dict-classic.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. :option="option"
  5. :table-loading="loading"
  6. :data="data"
  7. ref="crud"
  8. v-model="form"
  9. :permission="permissionList"
  10. :before-open="beforeOpen"
  11. :before-close="beforeClose"
  12. @row-del="rowDel"
  13. @row-update="rowUpdate"
  14. @row-save="rowSave"
  15. @search-change="searchChange"
  16. @search-reset="searchReset"
  17. @selection-change="selectionChange"
  18. @current-change="currentChange"
  19. @size-change="sizeChange"
  20. @refresh-change="refreshChange"
  21. @on-load="onLoad"
  22. >
  23. <template slot="menuLeft">
  24. <el-button
  25. type="danger"
  26. size="small"
  27. icon="el-icon-delete"
  28. v-if="permission.dict_delete"
  29. plain
  30. @click="handleDelete"
  31. >删 除
  32. </el-button>
  33. </template>
  34. <template slot-scope="{row}" slot="isSealed">
  35. <el-tag>{{row.isSealed===0?'否':'是'}}</el-tag>
  36. </template>
  37. <template slot-scope="scope" slot="menu">
  38. <el-button
  39. type="text"
  40. icon="el-icon-check"
  41. size="small"
  42. @click.stop="handleAdd(scope.row,scope.index)"
  43. >新增子项
  44. </el-button>
  45. </template>
  46. </avue-crud>
  47. </basic-container>
  48. </template>
  49. <script>
  50. import {
  51. getList,
  52. remove,
  53. update,
  54. add,
  55. getDict,
  56. getDictTree
  57. } from "@/api/system/dict";
  58. import {mapGetters} from "vuex";
  59. export default {
  60. data() {
  61. return {
  62. form: {},
  63. selectionList: [],
  64. query: {},
  65. loading: true,
  66. page: {
  67. pageSize: 10,
  68. currentPage: 1,
  69. total: 0
  70. },
  71. option: {
  72. tip: false,
  73. searchShow: true,
  74. searchMenuSpan: 6,
  75. tree: true,
  76. border: true,
  77. index: true,
  78. selection: true,
  79. viewBtn: true,
  80. menuWidth: 300,
  81. dialogWidth: 880,
  82. column: [
  83. {
  84. label: "字典编号",
  85. prop: "code",
  86. search: true,
  87. span: 24,
  88. rules: [
  89. {
  90. required: true,
  91. message: "请输入字典编号",
  92. trigger: "blur"
  93. }
  94. ]
  95. },
  96. {
  97. label: "字典名称",
  98. prop: "dictValue",
  99. search: true,
  100. align: "center",
  101. rules: [
  102. {
  103. required: true,
  104. message: "请输入字典名称",
  105. trigger: "blur"
  106. }
  107. ]
  108. },
  109. {
  110. label: "上级字典",
  111. prop: "parentId",
  112. type: "tree",
  113. dicData: [],
  114. hide: true,
  115. props: {
  116. label: "title"
  117. },
  118. rules: [
  119. {
  120. required: false,
  121. message: "请选择上级字典",
  122. trigger: "click"
  123. }
  124. ]
  125. },
  126. {
  127. label: "字典键值",
  128. prop: "dictKey",
  129. type: "number",
  130. rules: [
  131. {
  132. required: true,
  133. message: "请输入字典键值",
  134. trigger: "blur"
  135. }
  136. ]
  137. },
  138. {
  139. label: "字典排序",
  140. prop: "sort",
  141. type: "number",
  142. rules: [
  143. {
  144. required: true,
  145. message: "请输入字典排序",
  146. trigger: "blur"
  147. }
  148. ]
  149. },
  150. {
  151. label: "封存",
  152. prop: "isSealed",
  153. type: "select",
  154. dicData: [
  155. {
  156. label: "否",
  157. value: 0
  158. },
  159. {
  160. label: "是",
  161. value: 1
  162. }
  163. ],
  164. slot: true,
  165. rules: [
  166. {
  167. required: true,
  168. message: "请选择封存",
  169. trigger: "blur"
  170. }
  171. ]
  172. },
  173. {
  174. label: "字典备注",
  175. prop: "remark",
  176. search: true,
  177. hide: true
  178. }
  179. ]
  180. },
  181. data: []
  182. };
  183. },
  184. computed: {
  185. ...mapGetters(["permission"]),
  186. permissionList() {
  187. return {
  188. addBtn: this.vaildData(this.permission.dict_add, false),
  189. viewBtn: this.vaildData(this.permission.dict_view, false),
  190. delBtn: this.vaildData(this.permission.dict_delete, false),
  191. editBtn: this.vaildData(this.permission.dict_edit, false)
  192. };
  193. },
  194. ids() {
  195. let ids = [];
  196. this.selectionList.forEach(ele => {
  197. ids.push(ele.id);
  198. });
  199. return ids.join(",");
  200. }
  201. },
  202. mounted() {
  203. getDictTree().then(res => {
  204. const column = this.findObject(this.optionChild.column, "parentId");
  205. column.dicData = res.data.data;
  206. });
  207. },
  208. methods: {
  209. handleAdd(row) {
  210. this.$refs.crud.value.code = row.code;
  211. this.$refs.crud.value.parentId = row.id;
  212. this.$refs.crud.option.column.filter(item => {
  213. if (item.prop === "code") {
  214. item.value = row.code;
  215. item.addDisabled = true;
  216. }
  217. if (item.prop === "parentId") {
  218. item.value = row.id;
  219. item.addDisabled = true;
  220. }
  221. });
  222. this.$refs.crud.rowAdd();
  223. },
  224. rowSave(row, done, loading) {
  225. add(row).then(() => {
  226. this.onLoad(this.page);
  227. this.$message({
  228. type: "success",
  229. message: "操作成功!"
  230. });
  231. done();
  232. }, error => {
  233. window.console.log(error);
  234. loading();
  235. });
  236. },
  237. rowUpdate(row, index, done, loading) {
  238. update(row).then(() => {
  239. this.onLoad(this.page);
  240. this.$message({
  241. type: "success",
  242. message: "操作成功!"
  243. });
  244. done();
  245. }, error => {
  246. window.console.log(error);
  247. loading();
  248. });
  249. },
  250. rowDel(row) {
  251. this.$confirm("确定将选择数据删除?", {
  252. confirmButtonText: "确定",
  253. cancelButtonText: "取消",
  254. type: "warning"
  255. })
  256. .then(() => {
  257. return remove(row.id);
  258. })
  259. .then(() => {
  260. this.onLoad(this.page);
  261. this.$message({
  262. type: "success",
  263. message: "操作成功!"
  264. });
  265. });
  266. },
  267. searchReset() {
  268. this.query = {};
  269. this.onLoad(this.page);
  270. },
  271. searchChange(params, done) {
  272. this.query = params;
  273. this.page.currentPage = 1;
  274. this.onLoad(this.page, params);
  275. done();
  276. },
  277. selectionChange(list) {
  278. this.selectionList = list;
  279. },
  280. selectionClear() {
  281. this.selectionList = [];
  282. this.$refs.crud.toggleSelection();
  283. },
  284. handleDelete() {
  285. if (this.selectionList.length === 0) {
  286. this.$message.warning("请选择至少一条数据");
  287. return;
  288. }
  289. this.$confirm("确定将选择数据删除?", {
  290. confirmButtonText: "确定",
  291. cancelButtonText: "取消",
  292. type: "warning"
  293. })
  294. .then(() => {
  295. return remove(this.ids);
  296. })
  297. .then(() => {
  298. this.onLoad(this.page);
  299. this.$message({
  300. type: "success",
  301. message: "操作成功!"
  302. });
  303. this.$refs.crud.toggleSelection();
  304. });
  305. },
  306. beforeOpen(done, type) {
  307. if (["edit", "view"].includes(type)) {
  308. getDict(this.form.id).then(res => {
  309. this.form = res.data.data;
  310. });
  311. }
  312. done();
  313. },
  314. beforeClose(done) {
  315. this.$refs.crud.tableForm = {};
  316. this.$refs.crud.value.code = "";
  317. this.$refs.crud.value.parentId = "";
  318. this.$refs.crud.value.addDisabled = false;
  319. this.$refs.crud.option.column.filter(item => {
  320. if (item.prop === "code") {
  321. item.value = "";
  322. item.addDisabled = false;
  323. }
  324. if (item.prop === "parentId") {
  325. item.value = "";
  326. item.addDisabled = false;
  327. }
  328. });
  329. done();
  330. },
  331. currentChange(currentPage) {
  332. this.page.currentPage = currentPage;
  333. },
  334. sizeChange(pageSize) {
  335. this.page.pageSize = pageSize;
  336. },
  337. refreshChange() {
  338. this.onLoad(this.page, this.query);
  339. },
  340. onLoad(page, params = {}) {
  341. this.loading = true;
  342. getList(
  343. page.currentPage,
  344. page.pageSize,
  345. Object.assign(params, this.query)
  346. ).then(res => {
  347. this.data = res.data.data;
  348. this.loading = false;
  349. this.selectionClear();
  350. });
  351. }
  352. }
  353. };
  354. </script>
  355. <style>
  356. </style>