dictDataDialog.vue 5.9 KB

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