index.vue 8.6 KB

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