dictDataDialog.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div class="sys-dictData-container">
  3. <el-dialog v-model="state.isShowDialog" draggable width="860px">
  4. <template #header>
  5. <div style="color: #fff">
  6. <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>
  7. <span> 字典值列表 </span>
  8. </div>
  9. </template>
  10. <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
  11. <el-form :model="state.queryParams" ref="queryForm" :inline="true">
  12. <el-form-item label="字典值" prop="value">
  13. <el-input placeholder="字典值" clearable @keyup.enter="handleQuery" v-model="state.queryParams.value" />
  14. </el-form-item>
  15. <el-form-item label="编码" prop="code">
  16. <el-input placeholder="编码" clearable @keyup.enter="handleQuery" v-model="state.queryParams.code" />
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button-group>
  20. <el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询 </el-button>
  21. <el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
  22. </el-button-group>
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" icon="ele-Plus" @click="openAddDictData"> 新增 </el-button>
  26. </el-form-item>
  27. </el-form>
  28. </el-card>
  29. <el-card shadow="hover" style="margin-top: 8px">
  30. <el-table :data="state.dictDataData" style="width: 100%" v-loading="state.loading" border>
  31. <el-table-column type="index" label="序号" width="55" align="center" />
  32. <el-table-column prop="value" label="字典值" show-overflow-tooltip />
  33. <el-table-column prop="code" label="编码" show-overflow-tooltip />
  34. <el-table-column prop="status" label="状态" width="70" align="center" show-overflow-tooltip>
  35. <template #default="scope">
  36. <el-tag type="success" v-if="scope.row.status === 1">启用</el-tag>
  37. <el-tag type="danger" v-else>禁用</el-tag>
  38. </template>
  39. </el-table-column>
  40. <el-table-column prop="orderNo" label="排序" width="70" align="center" show-overflow-tooltip />
  41. <el-table-column prop="createTime" label="修改时间" align="center" show-overflow-tooltip />
  42. <el-table-column prop="remark" label="备注" show-overflow-tooltip />
  43. <el-table-column label="操作" width="140" fixed="right" align="center" show-overflow-tooltip>
  44. <template #default="scope">
  45. <el-button icon="ele-Edit" size="small" text type="primary" @click="openEditDictData(scope.row)"> 编辑 </el-button>
  46. <el-button icon="ele-Delete" size="small" text type="danger" @click="delDictData(scope.row)"> 删除 </el-button>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. <el-pagination
  51. v-model:currentPage="state.tableParams.page"
  52. v-model:page-size="state.tableParams.pageSize"
  53. :total="state.tableParams.total"
  54. :page-sizes="[10, 20, 50, 100]"
  55. small
  56. background
  57. @size-change="handleSizeChange"
  58. @current-change="handleCurrentChange"
  59. layout="total, sizes, prev, pager, next, jumper"
  60. />
  61. </el-card>
  62. </el-dialog>
  63. <EditDictData ref="editDictDataRef" :title="state.editDictDataTitle" :dictTypeId="state.queryParams.dictTypeId" />
  64. </div>
  65. </template>
  66. <script lang="ts" setup name="sysDictData">
  67. import { onMounted, onUnmounted, reactive, ref } from 'vue';
  68. import { ElMessageBox, ElMessage } from 'element-plus';
  69. import mittBus from '/@/utils/mitt';
  70. import EditDictData from '/@/views/system/dict/component/editDictData.vue';
  71. import { getAPI } from '/@/utils/axios-utils';
  72. import { SysDictDataApi } from '/@/api-services/api';
  73. import { SysDictData } from '/@/api-services/models';
  74. const editDictDataRef = ref();
  75. const state = reactive({
  76. isShowDialog: false,
  77. loading: false,
  78. dictDataData: [] as Array<SysDictData>,
  79. queryParams: {
  80. value: undefined,
  81. code: undefined,
  82. dictTypeId: 0, // 字典类型Id
  83. },
  84. tableParams: {
  85. page: 1,
  86. pageSize: 10,
  87. total: 0 as any,
  88. },
  89. editDictDataTitle: '',
  90. });
  91. onMounted(async () => {
  92. mittBus.on('submitRefreshDictData', () => {
  93. handleQuery();
  94. });
  95. });
  96. onUnmounted(() => {
  97. mittBus.off('submitRefreshDictData');
  98. });
  99. // 打开弹窗
  100. const openDialog = async (row: any) => {
  101. state.queryParams.dictTypeId = row.id;
  102. handleQuery();
  103. state.isShowDialog = true;
  104. };
  105. // 查询操作
  106. const handleQuery = async () => {
  107. state.loading = true;
  108. let params = Object.assign(state.queryParams, state.tableParams);
  109. var res = await getAPI(SysDictDataApi).apiSysDictDataPagePost(params);
  110. state.dictDataData = res.data.result?.items ?? [];
  111. state.tableParams.total = res.data.result?.total;
  112. state.loading = false;
  113. };
  114. // 重置操作
  115. const resetQuery = () => {
  116. state.queryParams.value = undefined;
  117. state.queryParams.code = undefined;
  118. handleQuery();
  119. };
  120. // 打开新增页面
  121. const openAddDictData = () => {
  122. state.editDictDataTitle = '添加字典值';
  123. editDictDataRef.value.openDialog({});
  124. };
  125. // 打开编辑页面
  126. const openEditDictData = (row: any) => {
  127. state.editDictDataTitle = '编辑字典值';
  128. editDictDataRef.value.openDialog(row);
  129. };
  130. // 删除
  131. const delDictData = (row: any) => {
  132. ElMessageBox.confirm(`确定删除字典值:【${row.value}】?`, '提示', {
  133. confirmButtonText: '确定',
  134. cancelButtonText: '取消',
  135. type: 'warning',
  136. })
  137. .then(async () => {
  138. await getAPI(SysDictDataApi).apiSysDictDataDeletePost({ id: row.id });
  139. handleQuery();
  140. ElMessage.success('删除成功');
  141. })
  142. .catch(() => {});
  143. };
  144. // 改变页面容量
  145. const handleSizeChange = (val: number) => {
  146. state.tableParams.pageSize = val;
  147. handleQuery();
  148. };
  149. // 改变页码序号
  150. const handleCurrentChange = (val: number) => {
  151. state.tableParams.page = val;
  152. handleQuery();
  153. };
  154. // 导出对象
  155. defineExpose({ openDialog });
  156. </script>