index.vue 4.8 KB

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