index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="ele-body">
  3. <DictDataSearch @search="reload" />
  4. <el-card shadow="never">
  5. <div style="margin: 5px 0; padding-left: 262px">
  6. <el-button
  7. size="small"
  8. type="primary"
  9. icon="el-icon-plus"
  10. class="ele-btn-icon"
  11. @click="openEdit()"
  12. >
  13. 添加
  14. </el-button>
  15. <!-- <el-button
  16. size="small"
  17. type="warning"
  18. icon="el-icon-edit"
  19. class="ele-btn-icon"
  20. :disabled="!current"
  21. @click="openEdit(current)"
  22. >
  23. 修改
  24. </el-button> -->
  25. <el-button
  26. size="small"
  27. type="danger"
  28. icon="el-icon-delete"
  29. class="ele-btn-icon"
  30. :disabled="!current"
  31. @click="remove"
  32. >
  33. 删除
  34. </el-button>
  35. </div>
  36. <ele-split-layout
  37. width="244px"
  38. allow-collapse
  39. :right-style="{ overflow: 'hidden' }"
  40. >
  41. <!-- 表格 -->
  42. <ele-pro-table
  43. ref="table"
  44. :columns="columns"
  45. :datasource="datasource"
  46. height="calc(100vh - 350px)"
  47. :need-page="false"
  48. :toolkit="[]"
  49. :current.sync="current"
  50. highlight-current-row
  51. class="dict-table"
  52. tool-class="ele-toolbar-actions"
  53. @done="done"
  54. >
  55. <!-- 表头工具栏 -->
  56. <template v-slot:toolbar> </template>
  57. </ele-pro-table>
  58. <template v-slot:content>
  59. <!-- 数据字典项列表 -->
  60. <dict-data ref="dictData" v-if="current" :dict-id="current.id" />
  61. </template>
  62. </ele-split-layout>
  63. </el-card>
  64. <!-- 编辑弹窗 -->
  65. <dict-edit :visible.sync="showEdit" @done="reload" />
  66. </div>
  67. </template>
  68. <script>
  69. import DictData from './components/dict-data.vue';
  70. import DictEdit from './components/dict-edit.vue';
  71. import DictDataSearch from './components/dict-data-search.vue';
  72. import { listDictionaries, removeDictionary } from '@/api/system/dictionary';
  73. export default {
  74. name: 'SystemDictionary',
  75. components: { DictData, DictEdit, DictDataSearch },
  76. data() {
  77. return {
  78. // 表格列配置
  79. columns: [
  80. {
  81. columnKey: 'index',
  82. type: 'index',
  83. width: 45,
  84. align: 'center',
  85. showOverflowTooltip: true
  86. },
  87. {
  88. prop: 'name',
  89. label: '字典名称',
  90. showOverflowTooltip: true
  91. }
  92. ],
  93. // 当前编辑数据
  94. current: null,
  95. // 是否显示编辑弹窗
  96. showEdit: false,
  97. // 编辑回显数据
  98. editData: null
  99. };
  100. },
  101. methods: {
  102. /* 表格数据源 */
  103. datasource() {
  104. // return;
  105. return listDictionaries();
  106. },
  107. /* 表格渲染完成回调 */
  108. done(res) {
  109. if (res.data?.length) {
  110. this.$refs.table.setCurrentRow(res.data[0]);
  111. }
  112. },
  113. /* 刷新表格 */
  114. reload(where) {
  115. this.$refs.table.reload();
  116. this.$refs.dictData.reload(where);
  117. },
  118. /* 显示编辑 */
  119. openEdit(row) {
  120. this.editData = row;
  121. this.showEdit = true;
  122. },
  123. /* 删除 */
  124. remove() {
  125. this.$confirm('确定要删除选中的字典吗?', '提示', {
  126. type: 'warning'
  127. })
  128. .then(() => {
  129. if (this.$refs.dictData.selection.length == 0) {
  130. this.$message({
  131. message: '当前未选择数据',
  132. type: 'error'
  133. });
  134. return;
  135. }
  136. let ids = this.$refs.dictData.selection.map((item) => item.id);
  137. const loading = this.$loading({ lock: true });
  138. removeDictionary(ids, true)
  139. .then((msg) => {
  140. loading.close();
  141. this.$message.success(msg);
  142. this.reload();
  143. })
  144. .catch((e) => {
  145. loading.close();
  146. this.$message.error(e.message);
  147. });
  148. })
  149. .catch(() => {});
  150. }
  151. }
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. .dict-table {
  156. :deep(.el-table__row) {
  157. cursor: pointer;
  158. }
  159. :deep(.el-table__row > td:last-child:after) {
  160. content: '\e6e0';
  161. font-family: element-icons !important;
  162. font-style: normal;
  163. font-variant: normal;
  164. text-transform: none;
  165. -webkit-font-smoothing: antialiased;
  166. -moz-osx-font-smoothing: grayscale;
  167. line-height: 1;
  168. position: absolute;
  169. right: 10px;
  170. top: 50%;
  171. margin-top: -7px;
  172. }
  173. :deep(.el-table__row > td:last-child .cell) {
  174. padding-right: 20px;
  175. }
  176. }
  177. </style>