index.vue 7.7 KB

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