dict-data.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div>
  3. <!-- 数据表格 -->
  4. <ele-pro-table
  5. ref="table"
  6. :columns="columns"
  7. :datasource="datasource"
  8. :need-page="true"
  9. :toolkit="[]"
  10. :selection.sync="selection"
  11. height="calc(100vh - 350px)"
  12. full-height="calc(100vh - 116px)"
  13. tool-class="ele-toolbar-form"
  14. cache-key="systemDictDataTable"
  15. :pageSize="this.$store.state.tablePageSize"
  16. @filter-change="selectType"
  17. >
  18. <!-- 表头工具栏 -->
  19. <!-- <template v-slot:toolbar>
  20. <dict-data-search @search="reload">
  21. <el-button
  22. size="small"
  23. type="primary"
  24. icon="el-icon-plus"
  25. class="ele-btn-icon"
  26. @click="openEdit()"
  27. >
  28. 添加
  29. </el-button>
  30. <el-button
  31. size="small"
  32. type="danger"
  33. icon="el-icon-delete"
  34. class="ele-btn-icon"
  35. @click="removeBatch"
  36. >
  37. 删除
  38. </el-button>
  39. </dict-data-search>
  40. </template> -->
  41. <!-- 操作列 -->
  42. <template v-slot:appType="{ row }">
  43. {{ types[row.appType] }}
  44. </template>
  45. <template v-slot:action="{ row }">
  46. <el-link
  47. type="primary"
  48. :underline="false"
  49. icon="el-icon-edit"
  50. @click="openEdit(row)"
  51. >
  52. 修改
  53. </el-link>
  54. <el-popconfirm
  55. class="ele-action"
  56. title="确定要删除此字典项吗?"
  57. @confirm="remove(row)"
  58. >
  59. <template v-slot:reference>
  60. <el-link type="danger" :underline="false" icon="el-icon-delete">
  61. 删除
  62. </el-link>
  63. </template>
  64. </el-popconfirm>
  65. </template>
  66. </ele-pro-table>
  67. <!-- 编辑弹窗 -->
  68. <dict-edit :visible.sync="showEdit" :id="id" @done="reload" />
  69. </div>
  70. </template>
  71. <script>
  72. import DictDataSearch from './dict-data-search.vue';
  73. import DictDataEdit from './dict-data-edit.vue';
  74. import {
  75. pageDictionaryData,
  76. removeDictionaryData,
  77. removeDictionaryDataBatch
  78. } from '@/api/system/dictionary-data';
  79. import { listDictionaries, removeDictionary } from '@/api/system/dictionary';
  80. import DictEdit from './dict-edit.vue';
  81. export default {
  82. components: { DictDataSearch, DictDataEdit, DictEdit },
  83. data() {
  84. return {
  85. // 表格列配置
  86. columns: [
  87. {
  88. columnKey: 'selection',
  89. type: 'selection',
  90. width: 45,
  91. align: 'center'
  92. },
  93. {
  94. columnKey: 'index',
  95. type: 'index',
  96. width: 45,
  97. align: 'center',
  98. showOverflowTooltip: true
  99. },
  100. {
  101. prop: 'code',
  102. label: '字典编码',
  103. align: 'center',
  104. showOverflowTooltip: true
  105. },
  106. {
  107. prop: 'name',
  108. label: '字典名称',
  109. align: 'center',
  110. showOverflowTooltip: true
  111. },
  112. // {
  113. // prop: 'appType',
  114. // label: '字典类型',
  115. // showOverflowTooltip: true,
  116. // minWidth: 110
  117. // },
  118. {//修改此prop名称时,请同步修改columnKey属性和下方selectType方法
  119. prop: 'appType',
  120. align: 'center',
  121. label: '应用类型',
  122. showOverflowTooltip: true,
  123. slot: 'appType',
  124. filters:[
  125. { value: 1, text:'业务字段' },
  126. { value: 2, text:'数据字典' },
  127. ],
  128. filterMultiple: false,
  129. columnKey: 'appType'
  130. },
  131. {
  132. prop: 'remark',
  133. label: '描述',
  134. align: 'center',
  135. showOverflowTooltip: true
  136. },
  137. {
  138. prop: 'updateTime',
  139. label: '上次更新时间',
  140. align: 'center',
  141. showOverflowTooltip: true,
  142. minWidth: 110,
  143. formatter: (_row, _column, cellValue) => {
  144. return this.$util.toDateString(cellValue);
  145. }
  146. },
  147. {
  148. columnKey: 'action',
  149. label: '操作',
  150. width: 130,
  151. align: 'center',
  152. resizable: false,
  153. slot: 'action',
  154. showOverflowTooltip: true
  155. }
  156. ],
  157. types: {
  158. 1: '业务字典',
  159. 2: '数据字典'
  160. },
  161. // 表格选中数据
  162. selection: [],
  163. // 当前编辑数据
  164. current: null,
  165. // 是否显示编辑弹窗
  166. showEdit: false,
  167. id: ''
  168. };
  169. },
  170. methods: {
  171. selectType(value) {
  172. let where = {}
  173. if (value.appType.length > 0) {
  174. where['appType'] = value.appType[0]
  175. }
  176. this.reload(where)
  177. },
  178. /* 表格数据源 */
  179. datasource({ page, limit, where, order }) {
  180. return listDictionaries({ pageNum: page, size: limit, ...where });
  181. },
  182. /* 刷新表格 */
  183. reload(where) {
  184. this.$refs.table.reload({ page: 1, where: where });
  185. },
  186. /* 显示编辑 */
  187. openEdit(row) {
  188. this.id = row.id;
  189. this.current = row;
  190. this.showEdit = true;
  191. },
  192. /* 删除 */
  193. remove(row) {
  194. const loading = this.$loading({ lock: true });
  195. removeDictionary(row.id)
  196. .then((msg) => {
  197. loading.close();
  198. this.$message.success('删除' + msg);
  199. this.reload();
  200. })
  201. .catch((e) => {
  202. loading.close();
  203. // this.$message.error(e.message);
  204. });
  205. },
  206. /* 批量删除 */
  207. removeBatch() {
  208. if (!this.selection.length) {
  209. this.$message.error('请至少选择一条数据');
  210. return;
  211. }
  212. this.$confirm('确定要删除选中的字典项吗?', '提示', {
  213. type: 'warning'
  214. })
  215. .then(() => {
  216. const loading = this.$loading({ lock: true });
  217. removeDictionaryDataBatch(this.selection.map((d) => d.dictDataId))
  218. .then((msg) => {
  219. loading.close();
  220. this.$message.success(msg);
  221. this.reload();
  222. })
  223. .catch((e) => {
  224. loading.close();
  225. // this.$message.error(e.message);
  226. });
  227. })
  228. .catch(() => {});
  229. }
  230. },
  231. watch: {
  232. // 监听字典id变化
  233. // dictId() {
  234. // this.reload();
  235. // }
  236. }
  237. };
  238. </script>