dict-vertical.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <div>
  3. <basic-container>
  4. <el-row>
  5. <el-col :span="24">
  6. <avue-crud
  7. :option="option"
  8. :table-loading="loading"
  9. :data="dataParent"
  10. :page="pageParent"
  11. ref="crud"
  12. v-model="formParent"
  13. :permission="permissionList"
  14. :before-open="beforeOpen"
  15. @row-del="rowDel"
  16. @row-update="rowUpdate"
  17. @row-save="rowSave"
  18. @row-click="handleRowClick"
  19. @search-change="searchChange"
  20. @search-reset="searchReset"
  21. @selection-change="selectionChange"
  22. @current-change="currentChange"
  23. @size-change="sizeChange"
  24. @refresh-change="refreshChange"
  25. @on-load="onLoadParent"
  26. >
  27. <template slot="menuLeft">
  28. <el-button
  29. type="danger"
  30. size="small"
  31. icon="el-icon-delete"
  32. v-if="permission.dict_delete"
  33. plain
  34. @click="handleDelete"
  35. >删 除
  36. </el-button>
  37. </template>
  38. <template slot-scope="{row}" slot="isSealed">
  39. <el-tag>{{row.isSealed===0?'否':'是'}}</el-tag>
  40. </template>
  41. </avue-crud>
  42. </el-col>
  43. </el-row>
  44. </basic-container>
  45. <basic-container>
  46. <el-row>
  47. <el-col :span="24">
  48. <avue-crud
  49. :option="option"
  50. :table-loading="loading"
  51. :data="dataChild"
  52. :page="pageChild"
  53. ref="crudChild"
  54. v-model="formChild"
  55. :permission="permissionList"
  56. :before-open="beforeOpenChild"
  57. @row-del="rowDelChild"
  58. @row-update="rowUpdateChild"
  59. @row-save="rowSaveChild"
  60. @search-change="searchChangeChild"
  61. @search-reset="searchResetChild"
  62. @selection-change="selectionChangeChild"
  63. @current-change="currentChangeChild"
  64. @size-change="sizeChangeChild"
  65. @refresh-change="refreshChangeChild"
  66. @on-load="onLoadChild"
  67. >
  68. <template slot="menuLeft">
  69. <el-button
  70. type="danger"
  71. size="small"
  72. icon="el-icon-delete"
  73. v-if="permission.dict_delete"
  74. plain
  75. @click="handleDelete"
  76. >删 除
  77. </el-button>
  78. </template>
  79. <template slot-scope="{row}" slot="isSealed">
  80. <el-tag>{{row.isSealed===0?'否':'是'}}</el-tag>
  81. </template>
  82. </avue-crud>
  83. </el-col>
  84. </el-row>
  85. </basic-container>
  86. </div>
  87. </template>
  88. <script>
  89. import {
  90. getParentList,
  91. getChildList,
  92. remove,
  93. update,
  94. add,
  95. getDict,
  96. } from "@/api/system/dict";
  97. import {mapGetters} from "vuex";
  98. export default {
  99. data() {
  100. return {
  101. parentId: 0,
  102. formParent: {},
  103. formChild: {},
  104. selectionList: [],
  105. query: {},
  106. loading: true,
  107. pageParent: {
  108. pageSize: 5,
  109. pageSizes: [5, 10, 30, 50, 100, 200],
  110. currentPage: 1,
  111. total: 0
  112. },
  113. pageChild: {
  114. pageSize: 5,
  115. pageSizes: [5, 10, 30, 50, 100, 200],
  116. currentPage: 1,
  117. total: 0
  118. },
  119. dataParent: [],
  120. dataChild: [],
  121. option: {
  122. tip: false,
  123. searchShow: true,
  124. searchMenuSpan: 6,
  125. tree: true,
  126. border: true,
  127. index: true,
  128. selection: true,
  129. viewBtn: true,
  130. height: 300,
  131. menuWidth: 300,
  132. dialogWidth: 880,
  133. column: [
  134. {
  135. label: "字典编号",
  136. prop: "code",
  137. search: true,
  138. span: 24,
  139. rules: [
  140. {
  141. required: true,
  142. message: "请输入字典编号",
  143. trigger: "blur"
  144. }
  145. ]
  146. },
  147. {
  148. label: "字典键值",
  149. prop: "dictKey",
  150. type: "number",
  151. rules: [
  152. {
  153. required: true,
  154. message: "请输入字典键值",
  155. trigger: "blur"
  156. }
  157. ]
  158. },
  159. {
  160. label: "字典名称",
  161. prop: "dictValue",
  162. search: true,
  163. align: "center",
  164. rules: [
  165. {
  166. required: true,
  167. message: "请输入字典名称",
  168. trigger: "blur"
  169. }
  170. ]
  171. },
  172. {
  173. label: "字典排序",
  174. prop: "sort",
  175. type: "number",
  176. rules: [
  177. {
  178. required: true,
  179. message: "请输入字典排序",
  180. trigger: "blur"
  181. }
  182. ]
  183. },
  184. {
  185. label: "封存",
  186. prop: "isSealed",
  187. type: "select",
  188. dicData: [
  189. {
  190. label: "否",
  191. value: 0
  192. },
  193. {
  194. label: "是",
  195. value: 1
  196. }
  197. ],
  198. slot: true,
  199. rules: [
  200. {
  201. required: true,
  202. message: "请选择封存",
  203. trigger: "blur"
  204. }
  205. ]
  206. },
  207. {
  208. label: "字典备注",
  209. prop: "remark",
  210. search: true,
  211. hide: true
  212. }
  213. ]
  214. }
  215. };
  216. },
  217. computed: {
  218. ...mapGetters(["permission"]),
  219. permissionList() {
  220. return {
  221. addBtn: this.vaildData(this.permission.dict_add, false),
  222. viewBtn: this.vaildData(this.permission.dict_view, false),
  223. delBtn: this.vaildData(this.permission.dict_delete, false),
  224. editBtn: this.vaildData(this.permission.dict_edit, false)
  225. };
  226. },
  227. ids() {
  228. let ids = [];
  229. this.selectionList.forEach(ele => {
  230. ids.push(ele.id);
  231. });
  232. return ids.join(",");
  233. }
  234. },
  235. methods: {
  236. rowSave(row, done, loading) {
  237. add(row).then(() => {
  238. this.onLoadParent(this.pageParent);
  239. this.$message({
  240. type: "success",
  241. message: "操作成功!"
  242. });
  243. done();
  244. }, error => {
  245. window.console.log(error);
  246. loading();
  247. });
  248. },
  249. rowUpdate(row, index, done, loading) {
  250. update(row).then(() => {
  251. this.onLoadParent(this.pageParent);
  252. this.$message({
  253. type: "success",
  254. message: "操作成功!"
  255. });
  256. done();
  257. }, error => {
  258. window.console.log(error);
  259. loading();
  260. });
  261. },
  262. rowDel(row) {
  263. this.$confirm("确定将选择数据删除?", {
  264. confirmButtonText: "确定",
  265. cancelButtonText: "取消",
  266. type: "warning"
  267. })
  268. .then(() => {
  269. return remove(row.id);
  270. })
  271. .then(() => {
  272. this.onLoadParent(this.pageParent);
  273. this.$message({
  274. type: "success",
  275. message: "操作成功!"
  276. });
  277. });
  278. },
  279. handleRowClick(row) {
  280. this.parentId = row.id;
  281. this.onLoadChild(this.pageChild);
  282. },
  283. searchReset() {
  284. this.query = {};
  285. this.onLoadParent(this.pageParent);
  286. },
  287. searchChange(params, done) {
  288. this.query = params;
  289. this.pageParent.currentPage = 1;
  290. this.onLoadParent(this.pageParent, params);
  291. done();
  292. },
  293. selectionChange(list) {
  294. this.selectionList = list;
  295. },
  296. selectionClear() {
  297. this.selectionList = [];
  298. this.$refs.crud.toggleSelection();
  299. },
  300. handleDelete() {
  301. if (this.selectionList.length === 0) {
  302. this.$message.warning("请选择至少一条数据");
  303. return;
  304. }
  305. this.$confirm("确定将选择数据删除?", {
  306. confirmButtonText: "确定",
  307. cancelButtonText: "取消",
  308. type: "warning"
  309. })
  310. .then(() => {
  311. return remove(this.ids);
  312. })
  313. .then(() => {
  314. this.onLoadParent(this.pageParent);
  315. this.$message({
  316. type: "success",
  317. message: "操作成功!"
  318. });
  319. this.$refs.crud.toggleSelection();
  320. });
  321. },
  322. beforeOpen(done, type) {
  323. if (["edit", "view"].includes(type)) {
  324. getDict(this.formParent.id).then(res => {
  325. this.formParent = res.data.data;
  326. });
  327. }
  328. done();
  329. },
  330. currentChange(currentPage) {
  331. this.pageParent.currentPage = currentPage;
  332. },
  333. sizeChange(pageSize) {
  334. this.pageParent.pageSize = pageSize;
  335. },
  336. refreshChange() {
  337. this.onLoadParent(this.page, this.query);
  338. },
  339. rowSaveChild(row, done, loading) {
  340. add(row).then(() => {
  341. this.onLoadChild(this.pageChild);
  342. this.$message({
  343. type: "success",
  344. message: "操作成功!"
  345. });
  346. done();
  347. }, error => {
  348. window.console.log(error);
  349. loading();
  350. });
  351. },
  352. rowUpdateChild(row, index, done, loading) {
  353. update(row).then(() => {
  354. this.onLoadChild(this.pageChild);
  355. this.$message({
  356. type: "success",
  357. message: "操作成功!"
  358. });
  359. done();
  360. }, error => {
  361. window.console.log(error);
  362. loading();
  363. });
  364. },
  365. rowDelChild(row) {
  366. this.$confirm("确定将选择数据删除?", {
  367. confirmButtonText: "确定",
  368. cancelButtonText: "取消",
  369. type: "warning"
  370. })
  371. .then(() => {
  372. return remove(row.id);
  373. })
  374. .then(() => {
  375. this.onLoadChild(this.pageChild);
  376. this.$message({
  377. type: "success",
  378. message: "操作成功!"
  379. });
  380. });
  381. },
  382. searchResetChild() {
  383. this.query = {};
  384. this.onLoadChild(this.pageChild);
  385. },
  386. searchChangeChild(params, done) {
  387. this.query = params;
  388. this.pageChild.currentPage = 1;
  389. this.onLoadChild(this.pageChild, params);
  390. done();
  391. },
  392. selectionChangeChild(list) {
  393. this.selectionList = list;
  394. },
  395. selectionClearChild() {
  396. this.selectionList = [];
  397. this.$refs.crudChild.toggleSelection();
  398. },
  399. handleDeleteChild() {
  400. if (this.selectionList.length === 0) {
  401. this.$message.warning("请选择至少一条数据");
  402. return;
  403. }
  404. this.$confirm("确定将选择数据删除?", {
  405. confirmButtonText: "确定",
  406. cancelButtonText: "取消",
  407. type: "warning"
  408. })
  409. .then(() => {
  410. return remove(this.ids);
  411. })
  412. .then(() => {
  413. this.onLoadChild(this.pageChild);
  414. this.$message({
  415. type: "success",
  416. message: "操作成功!"
  417. });
  418. this.$refs.crudChild.toggleSelection();
  419. });
  420. },
  421. beforeOpenChild(done, type) {
  422. if (["edit", "view"].includes(type)) {
  423. getDict(this.formChild.id).then(res => {
  424. this.formChild = res.data.data;
  425. });
  426. }
  427. done();
  428. },
  429. currentChangeChild(currentPage) {
  430. this.pageChild.currentPage = currentPage;
  431. },
  432. sizeChangeChild(pageSize) {
  433. this.pageChild.pageSize = pageSize;
  434. },
  435. refreshChangeChild() {
  436. this.onLoadChild(this.pageChild, this.query);
  437. },
  438. onLoadParent(page, params = {}) {
  439. this.loading = true;
  440. getParentList(
  441. page.currentPage,
  442. page.pageSize,
  443. Object.assign(params, this.query)
  444. ).then(res => {
  445. const data = res.data.data;
  446. this.pageParent.total = data.total;
  447. this.dataParent = data.records;
  448. this.loading = false;
  449. this.selectionClear();
  450. });
  451. },
  452. onLoadChild(page, params = {}) {
  453. this.loading = true;
  454. getChildList(
  455. page.currentPage,
  456. page.pageSize,
  457. this.parentId,
  458. Object.assign(params, this.query)
  459. ).then(res => {
  460. const data = res.data.data;
  461. this.pageChild.total = data.total;
  462. this.dataChild = data.records;
  463. this.loading = false;
  464. this.selectionClear();
  465. });
  466. }
  467. }
  468. };
  469. </script>
  470. <style>
  471. </style>