menu.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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. :uploadExceed="uploadExceed"
  23. :upload-preview="uploadPreview"
  24. >
  25. <template slot="menuLeft">
  26. <el-button type="danger"
  27. size="small"
  28. icon="el-icon-delete"
  29. v-if="permission.menu_delete"
  30. plain
  31. @click="handleDelete">删 除
  32. </el-button>
  33. </template>
  34. <template slot-scope="scope" slot="menu">
  35. <el-button
  36. type="text"
  37. icon="el-icon-circle-plus-outline"
  38. size="small"
  39. @click.stop="handleAdd(scope.row,scope.index)"
  40. v-if="userInfo.role_name.includes('admin') && scope.row.category === 1"
  41. >新增子项
  42. </el-button>
  43. <!-- <el-button
  44. type="text"
  45. icon="el-icon-circle-plus-outline"
  46. size="small"
  47. @click.stop="handleTYAdd(scope.row,scope.index)"
  48. >添加提示语
  49. </el-button>-->
  50. </template>
  51. <template slot-scope="{row}"
  52. slot="source">
  53. <div style="text-align:center">
  54. <i :class="row.source"/>
  55. </div>
  56. </template>
  57. <template slot="excelUrl" slot-scope="scope" >
  58. <el-link type="primary" :href="scope.row.excelUrl" target="_blank">
  59. <avue-text-ellipsis :text="scope.row.excelUrl" :height="100" >
  60. <small slot="more">...</small>
  61. </avue-text-ellipsis>
  62. </el-link>
  63. </template>
  64. </avue-crud>
  65. </basic-container>
  66. </template>
  67. <script>
  68. import {getLazyList, remove, update, add, getMenu} from "@/api/system/menu";
  69. import {mapGetters} from "vuex";
  70. import iconList from "@/config/iconList";
  71. import func from "@/util/func";
  72. import {getMenuTree} from "@/api/system/menu";
  73. export default {
  74. data() {
  75. return {
  76. form: {},
  77. query: {},
  78. loading: true,
  79. selectionList: [],
  80. parentId: 0,
  81. page: {
  82. pageSize: 10,
  83. currentPage: 1,
  84. total: 0,
  85. },
  86. option: {
  87. lazy: true,
  88. tip: false,
  89. simplePage: true,
  90. searchShow: true,
  91. searchMenuSpan: 6,
  92. dialogWidth: "60%",
  93. tree: true,
  94. border: true,
  95. index: true,
  96. selection: true,
  97. viewBtn: true,
  98. menuWidth: 400,
  99. dialogClickModal: false,
  100. column: [
  101. {
  102. label: "菜单名称",
  103. prop: "name",
  104. search: true,
  105. rules: [
  106. {
  107. required: true,
  108. message: "请输入菜单名称",
  109. trigger: "blur"
  110. }
  111. ]
  112. },
  113. {
  114. label: "所属系统",
  115. type: "select",
  116. dicUrl: "/api/blade-system/client/getClinetAll",
  117. props: {
  118. label: "clientId",
  119. value: "id"
  120. },
  121. slot: true,
  122. prop: "sysId",
  123. search: true,
  124. },
  125. {
  126. label: "路由地址",
  127. prop: "path",
  128. rules: [
  129. {
  130. required: true,
  131. message: "请输入路由地址",
  132. trigger: "blur"
  133. }
  134. ]
  135. },
  136. {
  137. label: "上级菜单",
  138. prop: "parentId",
  139. type: "tree",
  140. dicData: [],
  141. hide: true,
  142. addDisabled: false,
  143. props: {
  144. label: "title"
  145. },
  146. rules: [
  147. {
  148. required: false,
  149. message: "请选择上级菜单",
  150. trigger: "click"
  151. }
  152. ]
  153. },
  154. {
  155. label: "菜单图标",
  156. prop: "source",
  157. type: "icon",
  158. slot: true,
  159. iconList: iconList
  160. },
  161. {
  162. label: "菜单编号",
  163. prop: "code",
  164. rules: [
  165. {
  166. required: true,
  167. message: "请输入菜单编号",
  168. trigger: "blur"
  169. }
  170. ]
  171. },
  172. {
  173. label: "客户端图标",
  174. prop: "source"
  175. },
  176. {
  177. label: "菜单别名",
  178. prop: "alias",
  179. rules: [
  180. {
  181. required: true,
  182. message: "请输入菜单别名",
  183. trigger: "blur"
  184. }
  185. ]
  186. },
  187. {
  188. label: "菜单类型",
  189. prop: "category",
  190. type: "radio",
  191. dicData: [
  192. {
  193. label: "菜单",
  194. value: 1
  195. },
  196. {
  197. label: "按钮",
  198. value: 2
  199. }
  200. ],
  201. value: 1,
  202. rules: [
  203. {
  204. required: true,
  205. message: "请选择菜单类型",
  206. trigger: "blur"
  207. }
  208. ],
  209. },
  210. {
  211. label: "新窗口",
  212. prop: "isOpen",
  213. type: "radio",
  214. disabled: false,
  215. dicData: [
  216. {
  217. label: "否",
  218. value: 1
  219. },
  220. {
  221. label: "是",
  222. value: 2
  223. }
  224. ],
  225. value: 1,
  226. rules: [
  227. {
  228. required: true,
  229. message: "请选择新窗口打开",
  230. trigger: "blur"
  231. }
  232. ]
  233. },
  234. {
  235. label: "是否外层",
  236. prop: "isLayout",
  237. type: "radio",
  238. disabled: false,
  239. dicData: [
  240. {
  241. label: "否",
  242. value: 1
  243. },
  244. {
  245. label: "是",
  246. value: 2
  247. }
  248. ],
  249. value: 2,
  250. rules: [
  251. {
  252. required: true,
  253. message: "请选择新窗口打开",
  254. trigger: "blur"
  255. }
  256. ]
  257. },
  258. {
  259. label: "菜单排序",
  260. prop: "sort",
  261. type: "number",
  262. row: true,
  263. span: 24,
  264. value: 1,
  265. rules: [
  266. {
  267. required: true,
  268. message: "请输入菜单排序",
  269. trigger: "blur"
  270. }
  271. ]
  272. },
  273. {
  274. label: "菜单备注",
  275. prop: "remark",
  276. type: "textarea",
  277. span: 24,
  278. minRows: 2,
  279. hide: true
  280. },
  281. {
  282. label: "提示语",
  283. prop: "textInfo",
  284. type: "textarea",
  285. span: 24,
  286. minRows: 2,
  287. },
  288. {
  289. label: '菜单视频',
  290. prop: 'videoUrl',
  291. type: 'upload',
  292. listType: 'picture-img',
  293. span: 12,
  294. accept:"video/mp4",
  295. propsHttp: {
  296. url:'data'
  297. },
  298. limit:1,
  299. tip: '只能上传MP4格式,且不能用QQ录屏,推荐使用win10自带录屏录制,文件大小限制50兆',
  300. // tip: '只能上传jpg/png用户头像,且不超过500kb',
  301. action: "/api/blade-resource/oss/endpoint/put-file2"
  302. },
  303. {
  304. label: '文档信息',
  305. prop: 'excelUrl',
  306. type: 'upload',
  307. span: 12,
  308. multiple:false,
  309. dataType: "string",
  310. loadText: '模板上传中,请稍等',
  311. propsHttp: {
  312. url:'data',
  313. },
  314. limit:1,
  315. tip: '上传文档说明',
  316. action: "/api/blade-resource/oss/endpoint/upload-file2"
  317. },
  318. // {
  319. // label: "文档信息",
  320. // prop: "excelUrl",
  321. // type: "url",
  322. // span: 24,
  323. // minRows: 2,
  324. // propsHttp: {
  325. // url:'data'
  326. // }
  327. // },
  328. ]
  329. },
  330. data: []
  331. };
  332. },
  333. watch: {
  334. 'form.category'() {
  335. const category = func.toInt(this.form.category);
  336. this.$refs.crud.option.column.filter(item => {
  337. if (item.prop === "path") {
  338. item.rules[0].required = category === 1;
  339. }
  340. if (item.prop === 'isOpen') {
  341. item.disabled = category === 2;
  342. }
  343. if (item.prop === 'textInfo' ) {
  344. if(category===1){
  345. item.disabled = true;
  346. }
  347. if(category===2){
  348. item.disabled = false;
  349. }
  350. }
  351. if (item.prop === 'videoUrl') {
  352. if(category===1){
  353. item.disabled = false;
  354. }
  355. if(category===2){
  356. item.disabled = true;
  357. }
  358. }
  359. });
  360. },
  361. },
  362. computed: {
  363. ...mapGetters(["userInfo", "permission"]),
  364. permissionList() {
  365. return {
  366. addBtn: this.vaildData(this.permission.menu_add, false),
  367. viewBtn: this.vaildData(this.permission.menu_view, false),
  368. delBtn: this.vaildData(this.permission.menu_delete, false),
  369. editBtn: this.vaildData(this.permission.menu_edit, false)
  370. };
  371. },
  372. ids() {
  373. let ids = [];
  374. this.selectionList.forEach(ele => {
  375. ids.push(ele.id);
  376. });
  377. return ids.join(",");
  378. }
  379. },
  380. methods: {
  381. uploadExceed(limit, files, fileList, column){
  382. this.$message.warning('只允许上传1个文件,请先删除原文件再次点击上传')
  383. },
  384. //上传后进行点击预览
  385. uploadPreview(file, column, done) {
  386. //默认执行打开方法
  387. window.open(file.url, 'baidu').then(()=>{
  388. done();
  389. })
  390. },
  391. initData() {
  392. getMenuTree().then(res => {
  393. const column = this.findObject(this.option.column, "parentId");
  394. column.dicData = res.data.data;
  395. });
  396. },
  397. handleAdd(row) {
  398. this.parentId = row.id;
  399. const column = this.findObject(this.option.column, "parentId");
  400. column.value = row.id;
  401. column.addDisabled = true;
  402. this.$refs.crud.rowAdd();
  403. },
  404. // 提示语
  405. /* handleTYAdd(row) {
  406. this.parentId = row.id;
  407. const column = this.findObject(this.option.column, "parentId");
  408. column.value = row.id;
  409. column.addDisabled = true;
  410. this.$refs.crud.rowAdd();
  411. },*/
  412. rowSave(row, done, loading) {
  413. add(row).then((res) => {
  414. // 获取新增数据的相关字段
  415. const data = res.data.data;
  416. row.id = data.id;
  417. this.$message({
  418. type: "success",
  419. message: "操作成功!"
  420. });
  421. // 数据回调进行刷新
  422. done(row);
  423. }, error => {
  424. window.console.log(error);
  425. loading();
  426. });
  427. },
  428. rowUpdate(row, index, done, loading) {
  429. update(row).then(() => {
  430. this.$message({
  431. type: "success",
  432. message: "操作成功!"
  433. });
  434. // 数据回调进行刷新
  435. done(row);
  436. }, error => {
  437. window.console.log(error);
  438. loading();
  439. });
  440. },
  441. rowDel(row, index, done) {
  442. this.$confirm("确定将选择数据删除?", {
  443. confirmButtonText: "确定",
  444. cancelButtonText: "取消",
  445. type: "warning"
  446. })
  447. .then(() => {
  448. return remove(row.id);
  449. })
  450. .then(() => {
  451. this.$message({
  452. type: "success",
  453. message: "操作成功!"
  454. });
  455. // 数据回调进行刷新
  456. done(row);
  457. });
  458. },
  459. handleDelete() {
  460. if (this.selectionList.length === 0) {
  461. this.$message.warning("请选择至少一条数据");
  462. return;
  463. }
  464. this.$confirm("确定将选择数据删除?", {
  465. confirmButtonText: "确定",
  466. cancelButtonText: "取消",
  467. type: "warning"
  468. })
  469. .then(() => {
  470. return remove(this.ids);
  471. })
  472. .then(() => {
  473. // 刷新表格数据并重载
  474. this.data = [];
  475. this.parentId = 0;
  476. this.$refs.crud.refreshTable();
  477. this.$refs.crud.toggleSelection();
  478. // 表格数据重载
  479. this.onLoad(this.page);
  480. this.$message({
  481. type: "success",
  482. message: "操作成功!"
  483. });
  484. });
  485. },
  486. searchReset() {
  487. this.query = {};
  488. this.parentId = 0;
  489. this.onLoad(this.page);
  490. },
  491. searchChange(params, done) {
  492. this.query = params;
  493. this.parentId = '';
  494. this.page.currentPage = 1;
  495. this.onLoad(this.page, params);
  496. done();
  497. },
  498. selectionChange(list) {
  499. this.selectionList = list;
  500. },
  501. selectionClear() {
  502. this.selectionList = [];
  503. this.$refs.crud.toggleSelection();
  504. },
  505. beforeOpen(done, type) {
  506. if (["add", "edit"].includes(type)) {
  507. this.initData();
  508. }
  509. if (["edit", "view"].includes(type)) {
  510. getMenu(this.form.id).then(res => {
  511. this.form = res.data.data;
  512. });
  513. }
  514. done();
  515. },
  516. beforeClose(done) {
  517. this.parentId = "";
  518. const column = this.findObject(this.option.column, "parentId");
  519. column.value = "";
  520. column.addDisabled = false;
  521. done();
  522. },
  523. currentChange(currentPage) {
  524. this.page.currentPage = currentPage;
  525. },
  526. sizeChange(pageSize) {
  527. this.page.pageSize = pageSize;
  528. },
  529. refreshChange() {
  530. this.onLoad(this.page, this.query);
  531. },
  532. onLoad(page, params = {}) {
  533. this.loading = true;
  534. getLazyList(this.parentId, Object.assign(params, this.query)).then(res => {
  535. this.data = res.data.data;
  536. this.loading = false;
  537. this.selectionClear();
  538. });
  539. },
  540. treeLoad(tree, treeNode, resolve) {
  541. const parentId = tree.id;
  542. getLazyList(parentId).then(res => {
  543. resolve(res.data.data);
  544. });
  545. }
  546. }
  547. };
  548. </script>
  549. <style>
  550. </style>