index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div class="system-dic-container">
  3. <el-card shadow="hover">
  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="success" 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="danger" 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" @click="typeList">
  51. <el-tab-pane v-for="dict in dict_class_type" :label="dict.label" :name="dict.name">
  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="true" />
  56. <el-table-column label="字典分类" v-col="'moduleClassify'" align="center" prop="moduleClassify" />
  57. <el-table-column label="字典类型" v-col="'dictType'" align="center" :show-overflow-tooltip="true">
  58. <template #default="scope">
  59. <router-link :to="'/config/dict/' + scope.row.dictType" class="link-type">
  60. <span>{{ scope.row.dictType }}</span>
  61. </router-link>
  62. </template>
  63. </el-table-column>
  64. <el-table-column prop="status" label="字典状态" v-col="'status'" width="120" align="center">
  65. <template #default="scope">
  66. <el-tag type="success" size="small" v-if="scope.row.status">启用</el-tag>
  67. <el-tag type="info" size="small" v-else>禁用</el-tag>
  68. </template>
  69. </el-table-column>
  70. <el-table-column prop="remark" v-col="'remark'" label="字典描述" show-overflow-tooltip></el-table-column>
  71. <!-- <el-table-column prop="createdAt" label="创建时间" align="center" width="180"></el-table-column> -->
  72. <el-table-column label="操作" width="100" align="center" v-col="'handle'">
  73. <template #default="scope">
  74. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-auth="'edit'">修改</el-button>
  75. <el-button size="small" text type="danger" @click="onRowDel(scope.row)" v-auth="'del'">删除</el-button>
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="typeList" />
  80. </el-tab-pane>
  81. </el-tabs>
  82. </el-card>
  83. <EditDic ref="editDicRef" @typeList="typeList" />
  84. </div>
  85. </template>
  86. <script lang="ts">
  87. import { toRefs, reactive, onMounted, ref, defineComponent, getCurrentInstance} from 'vue';
  88. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  89. import EditDic from './component/editDic.vue';
  90. import api from '/@/api/system';
  91. // 定义接口来定义对象的类型
  92. interface TableDataRow {
  93. dictId: number;
  94. dictName: string;
  95. moduleClassify: string;
  96. dictType: string;
  97. status: number;
  98. remark: string;
  99. createdAt: string;
  100. }
  101. interface TableDataState {
  102. ids: number[];
  103. tableData: {
  104. data: Array<TableDataRow>;
  105. total: number;
  106. loading: boolean;
  107. param: {
  108. pageNum: number;
  109. pageSize: number;
  110. dictName: string;
  111. moduleClassify: string; // 字典类型
  112. dictType: string;
  113. status: string;
  114. dateRange: string[];
  115. };
  116. };
  117. }
  118. export default defineComponent({
  119. name: 'systemDic',
  120. components: { EditDic },
  121. setup() {
  122. const { proxy } = getCurrentInstance() as any;
  123. const { dict_class_type } = proxy.useDict('dict_class_type'); // 获取字典类型
  124. const addDicRef = ref();
  125. const editDicRef = ref();
  126. const queryRef = ref();
  127. const state = reactive<TableDataState>({
  128. ids: [],
  129. tableData: {
  130. data: [],
  131. total: 0,
  132. loading: false,
  133. param: {
  134. pageNum: 1,
  135. pageSize: 10,
  136. dictName: '',
  137. moduleClassify: '0',// 字典分类
  138. dictType: '',
  139. status: '',
  140. dateRange: [],
  141. },
  142. },
  143. });
  144. // 初始化表格数据
  145. const initTableData = () => {
  146. typeList();
  147. };
  148. const typeList = () => {
  149. let params = state.tableData.param;
  150. state.tableData.loading = true;
  151. api.dict
  152. .getTypeList(params)
  153. .then((res: any) => {
  154. state.tableData.data = res.dictTypeList;
  155. state.tableData.total = res.total;
  156. })
  157. .finally(() => (state.tableData.loading = false));
  158. };
  159. // 打开新增字典弹窗
  160. const onOpenAddDic = () => {
  161. editDicRef.value.openDialog();
  162. };
  163. // 打开修改字典弹窗
  164. const onOpenEditDic = (row: TableDataRow) => {
  165. editDicRef.value.openDialog(row);
  166. };
  167. // 删除字典
  168. const onRowDel = (row?: TableDataRow) => {
  169. let msg = '你确定要删除所选数据?';
  170. let ids: number[] = [];
  171. if (row) {
  172. msg = `此操作将永久删除用户:“${row.dictName}”,是否继续?`;
  173. ids = [row.dictId];
  174. } else {
  175. ids = state.ids;
  176. }
  177. if (ids.length === 0) {
  178. ElMessage.error('请选择要删除的数据。');
  179. return;
  180. }
  181. ElMessageBox.confirm(msg, '提示', {
  182. confirmButtonText: '确认',
  183. cancelButtonText: '取消',
  184. type: 'warning',
  185. })
  186. .then(() => {
  187. api.dict.deleteType(ids).then(() => {
  188. ElMessage.success('删除成功');
  189. typeList();
  190. });
  191. })
  192. .catch(() => { });
  193. };
  194. // 页面加载时
  195. onMounted(() => {
  196. initTableData();
  197. });
  198. /** 重置按钮操作 */
  199. const resetQuery = (formEl: FormInstance | undefined) => {
  200. if (!formEl) return;
  201. formEl.resetFields();
  202. typeList();
  203. };
  204. // 多选框选中数据
  205. const handleSelectionChange = (selection: TableDataRow[]) => {
  206. state.ids = selection.map((item) => item.dictId);
  207. };
  208. return {
  209. addDicRef,
  210. editDicRef,
  211. queryRef,
  212. onOpenAddDic,
  213. onOpenEditDic,
  214. onRowDel,
  215. typeList,
  216. resetQuery,
  217. handleSelectionChange,
  218. dict_class_type,
  219. ...toRefs(state),
  220. };
  221. },
  222. });
  223. </script>