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