index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!--
  2. - Copyright (c) 2018-2025, lengleng All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions are met:
  6. -
  7. - Redistributions of source code must retain the above copyright notice,
  8. - this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. - notice, this list of conditions and the following disclaimer in the
  11. - documentation and/or other materials provided with the distribution.
  12. - Neither the name of the pig4cloud.com developer nor the names of its
  13. - contributors may be used to endorse or promote products derived from
  14. - this software without specific prior written permission.
  15. - Author: lengleng (wangiegie@gmail.com)
  16. -->
  17. <template>
  18. <div class="execution">
  19. <basic-container>
  20. <avue-crud
  21. ref="crud"
  22. :page="page"
  23. :data="tableData"
  24. :permission="permissionList"
  25. :table-loading="tableLoading"
  26. :option="tableOption"
  27. @on-load="getList"
  28. @row-update="handleUpdate"
  29. @row-save="handleSave"
  30. @search-change="searchChange"
  31. @size-change="sizeChange"
  32. @current-change="currentChange"
  33. @row-del="rowDel">
  34. <template
  35. slot-scope="scope"
  36. slot="menu">
  37. <el-button
  38. v-if="permissions.sys_dict_add"
  39. type="text"
  40. size="mini"
  41. icon="el-icon-menu"
  42. @click="handleItem(scope.row,scope.index)">字典项
  43. </el-button>
  44. </template>
  45. </avue-crud>
  46. </basic-container>
  47. <el-dialog
  48. :visible.sync="dialogFormVisible"
  49. :table-loading="tableLoading"
  50. title="字典项管理"
  51. width="90%"
  52. @close="dialogFormVisible=false">
  53. <avue-crud
  54. ref="crudItem"
  55. :data="tableDictItemData"
  56. :permission="permissionList"
  57. v-model="form"
  58. :before-open="handleBeforeOpen"
  59. :option="tableDictItemOption"
  60. :table-loading="tableLoading"
  61. @row-update="handleItemUpdate"
  62. @row-save="handleItemSave"
  63. @row-del="rowItemDel"/>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script>
  68. import {addItemObj, addObj, delItemObj, delObj, fetchItemList, fetchList, putItemObj, putObj} from '@/api/admin/dict'
  69. import {tableDictItemOption, tableOption} from '@/const/crud/admin/dict'
  70. import {mapGetters} from 'vuex'
  71. export default {
  72. name: 'Dict',
  73. data() {
  74. return {
  75. searchForm: {},
  76. form: {
  77. type: undefined,
  78. dictId: undefined
  79. },
  80. dictType: undefined,
  81. dictId: undefined,
  82. dialogFormVisible: false,
  83. tableData: [],
  84. tableDictItemData: [],
  85. page: {
  86. total: 0, // 总页数
  87. currentPage: 1, // 当前页数
  88. pageSize: 20 // 每页显示多少条
  89. },
  90. tableLoading: false,
  91. tableOption: tableOption,
  92. tableDictItemOption: tableDictItemOption
  93. }
  94. },
  95. created() {
  96. },
  97. mounted: function () {
  98. },
  99. computed: {
  100. ...mapGetters(['permissions']),
  101. permissionList() {
  102. return {
  103. addBtn: this.vaildData(this.permissions.sys_dict_add, false),
  104. delBtn: this.vaildData(this.permissions.sys_dict_del, false),
  105. editBtn: this.vaildData(this.permissions.sys_dict_edit, false)
  106. }
  107. }
  108. },
  109. methods: {
  110. getList(page, params) {
  111. this.tableLoading = true
  112. fetchList(Object.assign({
  113. current: page.currentPage,
  114. size: page.pageSize
  115. }, params, this.searchForm)).then(response => {
  116. this.tableData = response.data.data.records
  117. this.page.total = response.data.data.total
  118. this.tableLoading = false
  119. })
  120. },
  121. getDictItemList(dictId, type) {
  122. this.dictType = type
  123. this.dictId = dictId
  124. this.dialogFormVisible = true
  125. this.tableLoading = true
  126. fetchItemList(Object.assign({
  127. current: this.page.currentPage,
  128. size: this.page.pageSize
  129. }, {dictId: dictId})).then(response => {
  130. this.tableDictItemData = response.data.data.records
  131. this.tableLoading = false
  132. })
  133. },
  134. handleBeforeOpen(done) {
  135. this.form.type = this.dictType
  136. this.form.dictId = this.dictId
  137. done()
  138. },
  139. rowDel: function (row) {
  140. var _this = this
  141. this.$confirm('是否确认删除数据类型为"' + row.type + '"的数据项?', '警告', {
  142. confirmButtonText: '确定',
  143. cancelButtonText: '取消',
  144. type: 'warning'
  145. }).then(function () {
  146. return delObj(row)
  147. }).then(() => {
  148. this.getList(this.page)
  149. _this.$message.success('删除成功')
  150. }).catch(function () {
  151. })
  152. },
  153. handleUpdate: function (row, index, done) {
  154. putObj(row).then(() => {
  155. this.$message.success('修改成功')
  156. this.getList(this.page)
  157. done()
  158. })
  159. },
  160. handleSave: function (row, done) {
  161. addObj(row).then(() => {
  162. this.$message.success('添加成功')
  163. this.getList(this.page)
  164. done()
  165. })
  166. },
  167. handleItemSave: function (row, done) {
  168. addItemObj(row).then(() => {
  169. this.$message.success('添加成功')
  170. this.getDictItemList(row.dictId, row.type)
  171. done()
  172. })
  173. },
  174. handleItemUpdate: function (row, index, done) {
  175. putItemObj(row).then(() => {
  176. this.$message.success('修改成功')
  177. this.getDictItemList(row.dictId, row.type)
  178. done()
  179. })
  180. },
  181. searchChange(form, done) {
  182. this.searchForm = form
  183. this.getList(this.page, form)
  184. done()
  185. },
  186. sizeChange(pageSize) {
  187. this.page.pageSize = pageSize
  188. },
  189. currentChange(current) {
  190. this.page.currentPage = current
  191. },
  192. handleItem: function (row) {
  193. this.getDictItemList(row.id, row.type)
  194. },
  195. rowItemDel: function (row) {
  196. var _this = this
  197. this.$confirm('是否确认删除数据为"' + row.label + '"的数据项?', '警告', {
  198. confirmButtonText: '确定',
  199. cancelButtonText: '取消',
  200. type: 'warning'
  201. }).then(function () {
  202. return delItemObj(row.id)
  203. }).then(() => {
  204. this.getDictItemList(row.dictId, row.type)
  205. _this.$message.success('删除成功')
  206. }).catch(function () {
  207. })
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. </style>