index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div class="page">
  3. <el-card shadow="nover">
  4. <el-form :model="tableData.param" ref="queryRef" inline label-width="68px">
  5. <el-form-item label="字典名称" prop="dictName">
  6. <el-input v-model="tableData.param.dictName" placeholder="请输入字典名称" clearable style="width: 240px" @keyup.enter.native="typeList" />
  7. </el-form-item>
  8. <el-form-item label="状态" prop="status" style="width: 200px">
  9. <el-select v-model="tableData.param.status" placeholder="字典状态" clearable style="width: 240px">
  10. <el-option label="启用" :value="1" />
  11. <el-option label="禁用" :value="0" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" class="ml10" @click="typeList">
  16. <el-icon>
  17. <ele-Search />
  18. </el-icon>
  19. 查询
  20. </el-button>
  21. <el-button @click="resetQuery(queryRef)">
  22. <el-icon>
  23. <ele-Refresh />
  24. </el-icon>
  25. 重置
  26. </el-button>
  27. <el-button type="primary" class="ml10" @click="onOpenAddDic" v-auth="'add'">
  28. <el-icon>
  29. <ele-FolderAdd />
  30. </el-icon>
  31. 新增字典
  32. </el-button>
  33. <el-button type="info" class="ml10" @click="onRowDel()" v-auth="'del'">
  34. <el-icon>
  35. <ele-Delete />
  36. </el-icon>
  37. 删除字典
  38. </el-button>
  39. </el-form-item>
  40. </el-form>
  41. <!-- 字典切换 -->
  42. <el-tabs v-model="tableData.param.moduleClassify" class="demo-tabs" @tab-change="typeList">
  43. <el-tab-pane v-for="dict in tabDataList" :label="dict.dictLabel" :name="dict.dictValue">
  44. </el-tab-pane>
  45. </el-tabs>
  46. <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
  47. <el-table-column type="selection" width="55" align="center" />
  48. <el-table-column label="字典ID" v-col="'dictId'" align="center" prop="dictId" width="80" />
  49. <el-table-column label="字典名称" v-col="'dictName'" prop="dictName" show-overflow-tooltip />
  50. <el-table-column label="字典类型" v-col="'dictType'" align="center" show-overflow-tooltip>
  51. <template #default="scope">
  52. <router-link :to="'/config/dict/' + scope.row.dictType" class="link-type">
  53. <span>{{ scope.row.dictType }}</span>
  54. </router-link>
  55. </template>
  56. </el-table-column>
  57. <el-table-column prop="status" label="字典状态" v-col="'status'" width="120" align="center">
  58. <template #default="scope">
  59. <el-tag type="success" size="small" v-if="scope.row.status">启用</el-tag>
  60. <el-tag type="info" size="small" v-else>禁用</el-tag>
  61. </template>
  62. </el-table-column>
  63. <el-table-column prop="remark" v-col="'remark'" label="字典描述" show-overflow-tooltip></el-table-column>
  64. <!-- <el-table-column prop="createdAt" label="创建时间" align="center" width="180"></el-table-column> -->
  65. <el-table-column label="操作" width="100" align="center" v-col="'handle'">
  66. <template #default="scope">
  67. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-auth="'edit'">修改</el-button>
  68. <el-button size="small" text type="info" @click="onRowDel(scope.row)" v-auth="'del'">删除</el-button>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="typeList" />
  73. </el-card>
  74. <EditDic ref="editDicRef" @typeList="typeList" />
  75. </div>
  76. </template>
  77. <script lang="ts">
  78. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  79. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  80. import EditDic from './component/editDic.vue';
  81. import api from '/@/api/system';
  82. // 定义接口来定义对象的类型
  83. interface TableDataRow {
  84. dictId: number;
  85. dictName: string;
  86. moduleClassify: string;
  87. dictType: string;
  88. status: number;
  89. remark: string;
  90. createdAt: string;
  91. }
  92. interface TableDataState {
  93. ids: number[];
  94. tableData: {
  95. data: Array<TableDataRow>;
  96. total: number;
  97. loading: boolean;
  98. param: {
  99. pageNum: number;
  100. pageSize: number;
  101. dictName: string;
  102. moduleClassify: string; // 字典类型
  103. dictType: string;
  104. status: string;
  105. dateRange: string[];
  106. };
  107. };
  108. }
  109. export default defineComponent({
  110. name: 'systemDic',
  111. components: { EditDic },
  112. setup() {
  113. const addDicRef = ref();
  114. const editDicRef = ref();
  115. const queryRef = ref();
  116. const tabDataList = ref([{ dictLabel: '全部', dictValue: '' }]);
  117. const state = reactive<TableDataState>({
  118. ids: [],
  119. tableData: {
  120. data: [],
  121. total: 0,
  122. loading: false,
  123. param: {
  124. pageNum: 1,
  125. pageSize: 10,
  126. dictName: '',
  127. moduleClassify: '',// 字典分类
  128. dictType: '',
  129. status: '',
  130. dateRange: [],
  131. },
  132. },
  133. });
  134. // 页面加载时
  135. onMounted(() => {
  136. initTableData();
  137. });
  138. // 初始化表格数据
  139. const initTableData = () => {
  140. dictList();
  141. };
  142. const typeList = () => {
  143. let params = state.tableData.param;
  144. state.tableData.loading = true;
  145. api.dict
  146. .getTypeList(params)
  147. .then((res: any) => {
  148. state.tableData.data = res.dictTypeList;
  149. state.tableData.total = res.total;
  150. })
  151. .finally(() => (state.tableData.loading = false));
  152. };
  153. // 打开新增字典弹窗
  154. const onOpenAddDic = () => {
  155. editDicRef.value.openDialog();
  156. };
  157. // 打开修改字典弹窗
  158. const onOpenEditDic = (row: TableDataRow) => {
  159. editDicRef.value.openDialog(row);
  160. };
  161. // 删除字典
  162. const onRowDel = (row?: TableDataRow) => {
  163. let msg = '你确定要删除所选数据?';
  164. let ids: number[] = [];
  165. if (row) {
  166. msg = `此操作将永久删除用户:“${row.dictName}”,是否继续?`;
  167. ids = [row.dictId];
  168. } else {
  169. ids = state.ids;
  170. }
  171. if (ids.length === 0) {
  172. ElMessage.error('请选择要删除的数据。');
  173. return;
  174. }
  175. ElMessageBox.confirm(msg, '提示', {
  176. confirmButtonText: '确认',
  177. cancelButtonText: '取消',
  178. type: 'warning',
  179. })
  180. .then(() => {
  181. api.dict.deleteType(ids).then(() => {
  182. ElMessage.success('删除成功');
  183. typeList();
  184. });
  185. })
  186. .catch(() => { });
  187. };
  188. /** 重置按钮操作 */
  189. const resetQuery = (formEl: FormInstance | undefined) => {
  190. if (!formEl) return;
  191. formEl.resetFields();
  192. typeList();
  193. };
  194. // 多选框选中数据
  195. const handleSelectionChange = (selection: TableDataRow[]) => {
  196. state.ids = selection.map((item) => item.dictId);
  197. };
  198. // 获取字典列表
  199. const dictList = () => {
  200. state.tableData.loading = true;
  201. api.dict.getDataList({ dictType: 'dict_class_type', status: 1, pageNum: 1, pageSize: 50, defaultValue: '' })
  202. .then((res: any) => {
  203. tabDataList.value = tabDataList.value.concat(res.list);
  204. typeList();
  205. }).finally(() => (state.tableData.loading = false));
  206. };
  207. return {
  208. addDicRef,
  209. editDicRef,
  210. queryRef,
  211. tabDataList,
  212. onOpenAddDic,
  213. onOpenEditDic,
  214. onRowDel,
  215. typeList,
  216. resetQuery,
  217. handleSelectionChange,
  218. ...toRefs(state),
  219. };
  220. },
  221. });
  222. </script>