topmenu.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page="page"
  7. :permission="permissionList"
  8. :before-open="beforeOpen"
  9. v-model="form"
  10. @row-update="rowUpdate"
  11. @row-save="rowSave"
  12. @row-del="rowDel"
  13. @search-change="searchChange"
  14. @search-reset="searchReset"
  15. @selection-change="selectionChange"
  16. @current-change="currentChange"
  17. @size-change="sizeChange"
  18. @on-load="onLoad">
  19. <template slot="menuLeft">
  20. <el-button type="danger"
  21. size="small"
  22. icon="el-icon-delete"
  23. plain
  24. v-if="permission.topmenu_delete"
  25. @click="handleDelete">删 除
  26. </el-button>
  27. <el-button size="small"
  28. icon="el-icon-delete"
  29. @click="handleMenuSetting"
  30. v-if="permission.topmenu_setting"
  31. plain>菜单配置
  32. </el-button>
  33. </template>
  34. <template slot-scope="{row}"
  35. slot="source">
  36. <div style="text-align:center">
  37. <i :class="row.source"></i>
  38. </div>
  39. </template>
  40. </avue-crud>
  41. <el-dialog title="下级菜单配置"
  42. :visible.sync="box"
  43. width="345px">
  44. <el-tree :data="menuGrantList"
  45. show-checkbox
  46. node-key="id"
  47. ref="treeMenu"
  48. :default-checked-keys="menuTreeObj"
  49. :props="props">
  50. </el-tree>
  51. <span slot="footer"
  52. class="dialog-footer">
  53. <el-button @click="box = false">取 消</el-button>
  54. <el-button type="primary"
  55. @click="submit">确 定</el-button>
  56. </span>
  57. </el-dialog>
  58. </basic-container>
  59. </template>
  60. <script>
  61. import {getList, getDetail, add, update, remove, grant, grantTree, getTopTree} from "@/api/system/topmenu";
  62. import {mapGetters} from "vuex";
  63. import iconList from "@/config/iconList";
  64. export default {
  65. data() {
  66. return {
  67. form: {},
  68. box: false,
  69. query: {},
  70. loading: true,
  71. props: {
  72. label: "title",
  73. value: "key"
  74. },
  75. page: {
  76. pageSize: 10,
  77. currentPage: 1,
  78. total: 0
  79. },
  80. selectionList: [],
  81. menuGrantList: [],
  82. menuTreeObj: [],
  83. option: {
  84. height:'auto',
  85. calcHeight:350,
  86. tip: false,
  87. border: true,
  88. index: true,
  89. viewBtn: true,
  90. selection: true,
  91. dialogWidth: 200,
  92. dialogHeight: 200,
  93. column: [
  94. {
  95. label: "菜单名",
  96. prop: "name",
  97. search: true,
  98. rules: [{
  99. required: true,
  100. message: "请输入菜单名",
  101. trigger: "blur"
  102. }]
  103. },
  104. {
  105. label: "菜单图标",
  106. prop: "source",
  107. type: "icon-select",
  108. slot: true,
  109. iconList: iconList,
  110. rules: [
  111. {
  112. required: true,
  113. message: "请输入菜单图标",
  114. trigger: "click"
  115. }
  116. ]
  117. },
  118. {
  119. label: "菜单编号",
  120. prop: "code",
  121. search: true,
  122. rules: [{
  123. required: true,
  124. message: "请输入菜单编号",
  125. trigger: "blur"
  126. }]
  127. },
  128. {
  129. label: "菜单排序",
  130. prop: "sort",
  131. type: "number",
  132. rules: [{
  133. required: true,
  134. message: "请输入菜单排序",
  135. trigger: "blur"
  136. }]
  137. },
  138. ]
  139. },
  140. data: []
  141. };
  142. },
  143. computed: {
  144. ...mapGetters(["permission"]),
  145. permissionList() {
  146. return {
  147. addBtn: this.vaildData(this.permission.topmenu_add, false),
  148. viewBtn: this.vaildData(this.permission.topmenu_view, false),
  149. delBtn: this.vaildData(this.permission.topmenu_delete, false),
  150. editBtn: this.vaildData(this.permission.topmenu_edit, false)
  151. };
  152. },
  153. ids() {
  154. let ids = [];
  155. this.selectionList.forEach(ele => {
  156. ids.push(ele.id);
  157. });
  158. return ids.join(",");
  159. }
  160. },
  161. methods: {
  162. submit() {
  163. const menuList = this.$refs.treeMenu.getCheckedKeys().join(",");
  164. grant(this.ids, menuList).then(() => {
  165. this.box = false;
  166. this.$message({
  167. type: "success",
  168. message: "操作成功!"
  169. });
  170. this.onLoad(this.page);
  171. });
  172. },
  173. rowSave(row, loading, done) {
  174. add(row).then(() => {
  175. loading();
  176. this.onLoad(this.page);
  177. this.$message({
  178. type: "success",
  179. message: "操作成功!"
  180. });
  181. }, error => {
  182. done();
  183. console.log(error);
  184. });
  185. },
  186. rowUpdate(row, index, loading, done) {
  187. update(row).then(() => {
  188. loading();
  189. this.onLoad(this.page);
  190. this.$message({
  191. type: "success",
  192. message: "操作成功!"
  193. });
  194. }, error => {
  195. done();
  196. console.log(error);
  197. });
  198. },
  199. rowDel(row) {
  200. this.$confirm("确定将选择数据删除?", {
  201. confirmButtonText: "确定",
  202. cancelButtonText: "取消",
  203. type: "warning"
  204. })
  205. .then(() => {
  206. return remove(row.id);
  207. })
  208. .then(() => {
  209. this.onLoad(this.page);
  210. this.$message({
  211. type: "success",
  212. message: "操作成功!"
  213. });
  214. });
  215. },
  216. handleDelete() {
  217. if (this.selectionList.length === 0) {
  218. this.$message.warning("请选择至少一条数据");
  219. return;
  220. }
  221. this.$confirm("确定将选择数据删除?", {
  222. confirmButtonText: "确定",
  223. cancelButtonText: "取消",
  224. type: "warning"
  225. })
  226. .then(() => {
  227. return remove(this.ids);
  228. })
  229. .then(() => {
  230. this.onLoad(this.page);
  231. this.$message({
  232. type: "success",
  233. message: "操作成功!"
  234. });
  235. this.$refs.crud.toggleSelection();
  236. });
  237. },
  238. handleMenuSetting() {
  239. if (this.selectionList.length !== 1) {
  240. this.$message.warning("只能选择一条数据");
  241. return;
  242. }
  243. this.menuTreeObj = [];
  244. grantTree()
  245. .then(res => {
  246. this.menuGrantList = res.data.data.menu;
  247. getTopTree(this.ids).then(res => {
  248. this.menuTreeObj = res.data.data.menu;
  249. this.box = true;
  250. });
  251. });
  252. },
  253. beforeOpen(done, type) {
  254. if (["edit", "view"].includes(type)) {
  255. getDetail(this.form.id).then(res => {
  256. this.form = res.data.data;
  257. });
  258. }
  259. done();
  260. },
  261. searchReset() {
  262. this.query = {};
  263. this.onLoad(this.page);
  264. },
  265. searchChange(params) {
  266. this.query = params;
  267. this.onLoad(this.page, params);
  268. },
  269. selectionChange(list) {
  270. this.selectionList = list;
  271. },
  272. currentChange(currentPage) {
  273. this.page.currentPage = currentPage;
  274. },
  275. sizeChange(pageSize) {
  276. this.page.pageSize = pageSize;
  277. },
  278. onLoad(page, params = {}) {
  279. this.loading = true;
  280. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  281. const data = res.data.data;
  282. this.page.total = data.total;
  283. this.data = data.records;
  284. this.loading = false;
  285. });
  286. }
  287. }
  288. };
  289. </script>
  290. <style>
  291. .none-border {
  292. border: 0;
  293. background-color: transparent !important;
  294. }
  295. </style>