menu.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. ref="crud"
  7. v-model="form"
  8. :permission="permissionList"
  9. :before-open="beforeOpen"
  10. :before-close="beforeClose"
  11. @row-del="rowDel"
  12. @row-update="rowUpdate"
  13. @row-save="rowSave"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad"
  21. @tree-load="treeLoad">
  22. <template slot="menuLeft">
  23. <el-button type="danger"
  24. size="small"
  25. icon="el-icon-delete"
  26. v-if="permission.menu_delete"
  27. plain
  28. @click="handleDelete">删 除
  29. </el-button>
  30. </template>
  31. <template slot-scope="scope" slot="menu">
  32. <el-button
  33. type="text"
  34. icon="el-icon-circle-plus-outline"
  35. size="small"
  36. @click.stop="handleAdd(scope.row,scope.index)"
  37. v-if="userInfo.role_name.includes('admin') && scope.row.category === 1"
  38. >新增子项
  39. </el-button>
  40. </template>
  41. <template slot-scope="{row}"
  42. slot="source">
  43. <div style="text-align:center">
  44. <i :class="row.source"/>
  45. </div>
  46. </template>
  47. </avue-crud>
  48. </basic-container>
  49. </template>
  50. <script>
  51. import {getLazyList, remove, update, add, getMenu} from "@/api/system/menu";
  52. import {mapGetters} from "vuex";
  53. import iconList from "@/config/iconList";
  54. import func from "@/util/func";
  55. import {getMenuTree} from "@/api/system/menu";
  56. export default {
  57. data() {
  58. return {
  59. form: {},
  60. query: {},
  61. loading: true,
  62. selectionList: [],
  63. parentId: 0,
  64. page: {
  65. pageSize: 10,
  66. currentPage: 1,
  67. total: 0,
  68. },
  69. option: {
  70. lazy: true,
  71. tip: false,
  72. simplePage: true,
  73. searchShow: true,
  74. searchMenuSpan: 6,
  75. dialogWidth: "60%",
  76. tree: true,
  77. border: true,
  78. index: true,
  79. selection: true,
  80. viewBtn: true,
  81. menuWidth: 300,
  82. dialogClickModal: false,
  83. column: [
  84. {
  85. label: "菜单名称",
  86. prop: "name",
  87. search: true,
  88. rules: [
  89. {
  90. required: true,
  91. message: "请输入菜单名称",
  92. trigger: "blur"
  93. }
  94. ]
  95. },
  96. {
  97. label: "所属系统",
  98. type: "select",
  99. dicUrl: "/api/blade-system/client/getClinetAll",
  100. props: {
  101. label: "clientId",
  102. value: "id"
  103. },
  104. slot: true,
  105. prop: "sysId",
  106. search: true,
  107. },
  108. {
  109. label: "路由地址",
  110. prop: "path",
  111. rules: [
  112. {
  113. required: true,
  114. message: "请输入路由地址",
  115. trigger: "blur"
  116. }
  117. ]
  118. },
  119. {
  120. label: "上级菜单",
  121. prop: "parentId",
  122. type: "tree",
  123. dicData: [],
  124. hide: true,
  125. addDisabled: false,
  126. props: {
  127. label: "title"
  128. },
  129. rules: [
  130. {
  131. required: false,
  132. message: "请选择上级菜单",
  133. trigger: "click"
  134. }
  135. ]
  136. },
  137. {
  138. label: "菜单图标",
  139. prop: "source",
  140. type: "icon",
  141. slot: true,
  142. iconList: iconList
  143. },
  144. {
  145. label: "菜单编号",
  146. prop: "code",
  147. rules: [
  148. {
  149. required: true,
  150. message: "请输入菜单编号",
  151. trigger: "blur"
  152. }
  153. ]
  154. },
  155. {
  156. label: "菜单类型",
  157. prop: "category",
  158. type: "radio",
  159. dicData: [
  160. {
  161. label: "菜单",
  162. value: 1
  163. },
  164. {
  165. label: "按钮",
  166. value: 2
  167. }
  168. ],
  169. value: 1,
  170. rules: [
  171. {
  172. required: true,
  173. message: "请选择菜单类型",
  174. trigger: "blur"
  175. }
  176. ]
  177. },
  178. {
  179. label: "菜单别名",
  180. prop: "alias",
  181. rules: [
  182. {
  183. required: true,
  184. message: "请输入菜单别名",
  185. trigger: "blur"
  186. }
  187. ]
  188. },
  189. {
  190. label: "新窗口",
  191. prop: "isOpen",
  192. type: "radio",
  193. disabled: false,
  194. dicData: [
  195. {
  196. label: "否",
  197. value: 1
  198. },
  199. {
  200. label: "是",
  201. value: 2
  202. }
  203. ],
  204. value: 1,
  205. rules: [
  206. {
  207. required: true,
  208. message: "请选择新窗口打开",
  209. trigger: "blur"
  210. }
  211. ]
  212. },
  213. {
  214. label: "是否外层",
  215. prop: "isLayout",
  216. type: "radio",
  217. disabled: false,
  218. dicData: [
  219. {
  220. label: "否",
  221. value: 1
  222. },
  223. {
  224. label: "是",
  225. value: 2
  226. }
  227. ],
  228. value: 2,
  229. rules: [
  230. {
  231. required: true,
  232. message: "请选择新窗口打开",
  233. trigger: "blur"
  234. }
  235. ]
  236. },
  237. {
  238. label: "菜单排序",
  239. prop: "sort",
  240. type: "number",
  241. row: true,
  242. span: 24,
  243. value: 1,
  244. rules: [
  245. {
  246. required: true,
  247. message: "请输入菜单排序",
  248. trigger: "blur"
  249. }
  250. ]
  251. },
  252. {
  253. label: "菜单备注",
  254. prop: "remark",
  255. type: "textarea",
  256. span: 24,
  257. minRows: 2,
  258. hide: true
  259. },
  260. {
  261. label: "提示语",
  262. prop: "textInfo",
  263. type: "textarea",
  264. span: 24,
  265. minRows: 2
  266. }
  267. ]
  268. },
  269. data: []
  270. };
  271. },
  272. watch: {
  273. 'form.category'() {
  274. const category = func.toInt(this.form.category);
  275. this.$refs.crud.option.column.filter(item => {
  276. if (item.prop === "path") {
  277. item.rules[0].required = category === 1;
  278. }
  279. if (item.prop === 'isOpen') {
  280. item.disabled = category === 2;
  281. }
  282. });
  283. },
  284. },
  285. computed: {
  286. ...mapGetters(["userInfo", "permission"]),
  287. permissionList() {
  288. return {
  289. addBtn: this.vaildData(this.permission.menu_add, false),
  290. viewBtn: this.vaildData(this.permission.menu_view, false),
  291. delBtn: this.vaildData(this.permission.menu_delete, false),
  292. editBtn: this.vaildData(this.permission.menu_edit, false)
  293. };
  294. },
  295. ids() {
  296. let ids = [];
  297. this.selectionList.forEach(ele => {
  298. ids.push(ele.id);
  299. });
  300. return ids.join(",");
  301. }
  302. },
  303. methods: {
  304. initData() {
  305. getMenuTree().then(res => {
  306. const column = this.findObject(this.option.column, "parentId");
  307. column.dicData = res.data.data;
  308. });
  309. },
  310. handleAdd(row) {
  311. this.parentId = row.id;
  312. const column = this.findObject(this.option.column, "parentId");
  313. column.value = row.id;
  314. column.addDisabled = true;
  315. this.$refs.crud.rowAdd();
  316. },
  317. rowSave(row, done, loading) {
  318. add(row).then((res) => {
  319. // 获取新增数据的相关字段
  320. const data = res.data.data;
  321. row.id = data.id;
  322. this.$message({
  323. type: "success",
  324. message: "操作成功!"
  325. });
  326. // 数据回调进行刷新
  327. done(row);
  328. }, error => {
  329. window.console.log(error);
  330. loading();
  331. });
  332. },
  333. rowUpdate(row, index, done, loading) {
  334. update(row).then(() => {
  335. this.$message({
  336. type: "success",
  337. message: "操作成功!"
  338. });
  339. // 数据回调进行刷新
  340. done(row);
  341. }, error => {
  342. window.console.log(error);
  343. loading();
  344. });
  345. },
  346. rowDel(row, index, done) {
  347. this.$confirm("确定将选择数据删除?", {
  348. confirmButtonText: "确定",
  349. cancelButtonText: "取消",
  350. type: "warning"
  351. })
  352. .then(() => {
  353. return remove(row.id);
  354. })
  355. .then(() => {
  356. this.$message({
  357. type: "success",
  358. message: "操作成功!"
  359. });
  360. // 数据回调进行刷新
  361. done(row);
  362. });
  363. },
  364. handleDelete() {
  365. if (this.selectionList.length === 0) {
  366. this.$message.warning("请选择至少一条数据");
  367. return;
  368. }
  369. this.$confirm("确定将选择数据删除?", {
  370. confirmButtonText: "确定",
  371. cancelButtonText: "取消",
  372. type: "warning"
  373. })
  374. .then(() => {
  375. return remove(this.ids);
  376. })
  377. .then(() => {
  378. // 刷新表格数据并重载
  379. this.data = [];
  380. this.parentId = 0;
  381. this.$refs.crud.refreshTable();
  382. this.$refs.crud.toggleSelection();
  383. // 表格数据重载
  384. this.onLoad(this.page);
  385. this.$message({
  386. type: "success",
  387. message: "操作成功!"
  388. });
  389. });
  390. },
  391. searchReset() {
  392. this.query = {};
  393. this.parentId = 0;
  394. this.onLoad(this.page);
  395. },
  396. searchChange(params, done) {
  397. this.query = params;
  398. this.parentId = '';
  399. this.page.currentPage = 1;
  400. this.onLoad(this.page, params);
  401. done();
  402. },
  403. selectionChange(list) {
  404. this.selectionList = list;
  405. },
  406. selectionClear() {
  407. this.selectionList = [];
  408. this.$refs.crud.toggleSelection();
  409. },
  410. beforeOpen(done, type) {
  411. if (["add", "edit"].includes(type)) {
  412. this.initData();
  413. }
  414. if (["edit", "view"].includes(type)) {
  415. getMenu(this.form.id).then(res => {
  416. this.form = res.data.data;
  417. });
  418. }
  419. done();
  420. },
  421. beforeClose(done) {
  422. this.parentId = "";
  423. const column = this.findObject(this.option.column, "parentId");
  424. column.value = "";
  425. column.addDisabled = false;
  426. done();
  427. },
  428. currentChange(currentPage) {
  429. this.page.currentPage = currentPage;
  430. },
  431. sizeChange(pageSize) {
  432. this.page.pageSize = pageSize;
  433. },
  434. refreshChange() {
  435. this.onLoad(this.page, this.query);
  436. },
  437. onLoad(page, params = {}) {
  438. this.loading = true;
  439. getLazyList(this.parentId, Object.assign(params, this.query)).then(res => {
  440. this.data = res.data.data;
  441. this.loading = false;
  442. this.selectionClear();
  443. });
  444. },
  445. treeLoad(tree, treeNode, resolve) {
  446. const parentId = tree.id;
  447. getLazyList(parentId).then(res => {
  448. resolve(res.data.data);
  449. });
  450. }
  451. }
  452. };
  453. </script>
  454. <style>
  455. </style>