index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 ref="crud"
  21. :page="page"
  22. :data="tableData"
  23. :permission="permissionList"
  24. :table-loading="tableLoading"
  25. :option="tableOption"
  26. @on-load="getList"
  27. @row-update="handleUpdate"
  28. @row-save="handleSave"
  29. @search-change="searchChange"
  30. @row-del="rowDel">
  31. <template slot-scope="scope"
  32. slot="menu">
  33. <el-button type="text"
  34. v-if="permissions.sys_dict_add"
  35. icon="el-icon-menu"
  36. size="mini"
  37. plain
  38. @click="handleItem(scope.row,scope.index)">字典项
  39. </el-button>
  40. </template>
  41. </avue-crud>
  42. </basic-container>
  43. <el-dialog title="字典项管理" :visible.sync="dialogFormVisible" width="90%"
  44. :table-loading="tableLoading"
  45. @close="dialogFormVisible=false">
  46. <avue-crud ref="crudItem"
  47. :data="tableDictItemData"
  48. :permission="permissionList"
  49. v-model="form"
  50. @row-update="handleItemUpdate"
  51. @row-save="handleItemSave"
  52. @row-del="rowItemDel"
  53. :before-open="handleBeforeOpen"
  54. :option="tableDictItemOption"
  55. :table-loading="tableLoading">
  56. </avue-crud>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script>
  61. import {addItemObj, addObj, delItemObj, delObj, fetchItemList, fetchList, putItemObj, putObj} from '@/api/admin/dict'
  62. import {tableDictItemOption, tableOption} from '@/const/crud/admin/dict'
  63. import {mapGetters} from 'vuex'
  64. export default {
  65. name: 'dict',
  66. data() {
  67. return {
  68. form: {},
  69. dictType: undefined,
  70. dictId: undefined,
  71. dialogFormVisible: false,
  72. tableData: [],
  73. tableDictItemData: [],
  74. page: {
  75. total: 0, // 总页数
  76. currentPage: 1, // 当前页数
  77. pageSize: 20 // 每页显示多少条
  78. },
  79. tableLoading: false,
  80. tableOption: tableOption,
  81. tableDictItemOption: tableDictItemOption
  82. }
  83. },
  84. created() {
  85. },
  86. mounted: function () {
  87. },
  88. computed: {
  89. ...mapGetters(['permissions']),
  90. permissionList() {
  91. return {
  92. addBtn: this.vaildData(this.permissions.sys_dict_add, false),
  93. delBtn: this.vaildData(this.permissions.sys_dict_del, false),
  94. editBtn: this.vaildData(this.permissions.sys_dict_edit, false)
  95. };
  96. }
  97. },
  98. methods: {
  99. getList(page, params) {
  100. this.tableLoading = true
  101. fetchList(Object.assign({
  102. current: page.currentPage,
  103. size: page.pageSize
  104. }, params)).then(response => {
  105. this.tableData = response.data.data.records
  106. this.page.total = response.data.data.total
  107. this.tableLoading = false
  108. })
  109. },
  110. getDictItemList(dictId, type) {
  111. this.dictType = type
  112. this.dictId = dictId
  113. this.dialogFormVisible = true
  114. this.tableLoading = true
  115. fetchItemList(Object.assign({
  116. current: this.page.currentPage,
  117. size: this.page.pageSize
  118. }, {dictId: dictId})).then(response => {
  119. this.tableDictItemData = response.data.data.records
  120. this.tableLoading = false
  121. })
  122. },
  123. handleBeforeOpen(done) {
  124. this.form.type = this.dictType
  125. this.form.dictId = this.dictId
  126. done()
  127. },
  128. rowDel: function (row) {
  129. var _this = this
  130. this.$confirm('是否确认删除数据类型为"' + row.type + '"的数据项?', '警告', {
  131. confirmButtonText: '确定',
  132. cancelButtonText: '取消',
  133. type: 'warning'
  134. }).then(function () {
  135. return delObj(row)
  136. }).then(() => {
  137. this.getList(this.page)
  138. _this.$message({
  139. showClose: true,
  140. message: '删除成功',
  141. type: 'success'
  142. })
  143. }).catch(function () {
  144. })
  145. },
  146. /**
  147. * @title 数据更新
  148. * @param row 为当前的数据
  149. * @param index 为当前更新数据的行数
  150. * @param done 为表单关闭函数
  151. *
  152. **/
  153. handleUpdate: function (row, index, done) {
  154. putObj(row).then(() => {
  155. this.tableData.splice(index, 1, Object.assign({}, row))
  156. this.$message({
  157. showClose: true,
  158. message: '修改成功',
  159. type: 'success'
  160. })
  161. this.getList(this.page)
  162. done()
  163. })
  164. },
  165. /**
  166. * @title 数据添加
  167. * @param row 为当前的数据
  168. * @param done 为表单关闭函数
  169. *
  170. **/
  171. handleSave: function (row, done) {
  172. addObj(row).then(() => {
  173. this.tableData.push(Object.assign({}, row))
  174. this.$message({
  175. showClose: true,
  176. message: '添加成功',
  177. type: 'success'
  178. })
  179. this.getList(this.page)
  180. done()
  181. })
  182. },
  183. handleItemSave: function (row, done) {
  184. addItemObj(row).then(() => {
  185. this.tableDictItemData.push(Object.assign({}, row))
  186. this.$message({
  187. showClose: true,
  188. message: '添加成功',
  189. type: 'success'
  190. })
  191. this.getList(this.page)
  192. done()
  193. })
  194. },
  195. handleItemUpdate: function (row, index, done) {
  196. putItemObj(row).then(() => {
  197. this.tableData.splice(index, 1, Object.assign({}, row))
  198. this.$message({
  199. showClose: true,
  200. message: '修改成功',
  201. type: 'success'
  202. })
  203. this.getDictItemList(row.dictId, row.type)
  204. done()
  205. })
  206. },
  207. searchChange(form) {
  208. this.getList(this.page, this.filterForm(form))
  209. },
  210. /**
  211. * 加载 字典项
  212. * @param row
  213. */
  214. handleItem: function (row) {
  215. this.getDictItemList(row.id, row.type)
  216. },
  217. rowItemDel: function (row) {
  218. var _this = this
  219. this.$confirm('是否确认删除数据为"' + row.label + '"的数据项?', '警告', {
  220. confirmButtonText: '确定',
  221. cancelButtonText: '取消',
  222. type: 'warning'
  223. }).then(function () {
  224. return delItemObj(row.id)
  225. }).then(() => {
  226. this.getDictItemList(row.dictId, row.type)
  227. _this.$message({
  228. showClose: true,
  229. message: '删除成功',
  230. type: 'success'
  231. })
  232. }).catch(function () {
  233. })
  234. },
  235. }
  236. }
  237. </script>
  238. <style lang="scss" scoped>
  239. </style>