index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div class="sys-config-container">
  3. <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
  4. <TableSearch :search="tb.tableData.search" @search="onSearch" />
  5. </el-card>
  6. <el-card class="full-table" shadow="hover" style="margin-top: 5px">
  7. <Table ref="tableRef" v-bind="tb.tableData" :getData="getData" :exportChangeData="exportChangeData" @sortHeader="onSortHeader" @selectionChange="tableSelection" border>
  8. <template #command>
  9. <el-button type="primary" icon="ele-Plus" @click="openAddConfig" v-auth="'sysConfig:add'"> 新增 </el-button>
  10. <el-button v-if="state.selectlist.length > 0" type="danger" icon="ele-Delete" @click="bacthDelete" v-auth="'sysConfig:batchDelete'"> 批量删除 </el-button>
  11. </template>
  12. <template #sysFlag="scope">
  13. <DictLabel :value="scope.row.sysFlag" code="YesNoEnum" />
  14. </template>
  15. <template #remark="scope">
  16. <ModifyRecord :data="scope.row" />
  17. </template>
  18. <template #action="scope">
  19. <el-button icon="ele-Edit" size="small" text type="primary" @click="openEditConfig(scope.row)" v-auth="'sysConfig:update'"> 编辑 </el-button>
  20. <el-button icon="ele-Delete" size="small" text type="danger" @click="delConfig(scope.row)" v-auth="'sysConfig:delete'" :disabled="scope.row.sysFlag === 1"> 删除 </el-button>
  21. </template>
  22. </Table>
  23. </el-card>
  24. <EditConfig ref="editConfigRef" :title="state.editConfigTitle" :groupList="state.groupList" @updateData="updateData" />
  25. </div>
  26. </template>
  27. <script lang="ts" setup name="sysConfig">
  28. import { onMounted, onUnmounted, reactive, ref, defineAsyncComponent, nextTick } from 'vue';
  29. import { ElMessageBox, ElMessage } from 'element-plus';
  30. import EditConfig from '/@/views/system/config/component/editConfig.vue';
  31. import ModifyRecord from '/@/components/table/modifyRecord.vue';
  32. import { getAPI } from '/@/utils/axios-utils';
  33. import { SysConfigApi } from '/@/api-services/api';
  34. import { auth } from '/@/utils/authFunction';
  35. import DictLabel from "/@/components/table/dictLabel.vue";
  36. // 引入组件
  37. const Table = defineAsyncComponent(() => import('/@/components/table/index.vue'));
  38. const TableSearch = defineAsyncComponent(() => import('/@/components/table/search.vue'));
  39. const editConfigRef = ref<InstanceType<typeof EditConfig>>();
  40. const tableRef = ref<RefType>();
  41. const state = reactive({
  42. editConfigTitle: '',
  43. selectlist: [] as EmptyObjectType[],
  44. groupList: [] as Array<String>,
  45. });
  46. const tb = reactive<TableDemoState>({
  47. tableData: {
  48. // 表头内容(必传,注意格式)
  49. columns: [
  50. { prop: 'name', minWidth: 150, label: '配置名称', headerAlign: 'center', sortable: 'custom', isCheck: true, hideCheck: true },
  51. { prop: 'code', minWidth: 150, label: '配置编码', headerAlign: 'center', toolTip: true, sortable: 'custom', isCheck: true },
  52. { prop: 'value', minWidth: 150, label: '属性值', headerAlign: 'center', isCheck: true },
  53. { prop: 'sysFlag', width: 100, label: '内置参数', align: 'center', isCheck: true },
  54. { prop: 'groupCode', width: 120, label: '分组编码', align: 'center', sortable: 'custom', isCheck: true },
  55. { prop: 'orderNo', width: 80, label: '排序', align: 'center', sortable: 'custom', isCheck: true },
  56. { prop: 'remark', width: 100, label: '修改记录', align: 'center', headerAlign: 'center', showOverflowTooltip: true, isCheck: true },
  57. { prop: 'action', width: 140, label: '操作', type: 'action', align: 'center', isCheck: true, fixed: 'right', hideCheck: true },
  58. ],
  59. // 配置项(必传)
  60. config: {
  61. isStripe: true, // 是否显示表格斑马纹
  62. isBorder: false, // 是否显示表格边框
  63. isSerialNo: true, // 是否显示表格序号
  64. isSelection: true, // 是否勾选表格多选
  65. showSelection: auth('sysConfig:batchDelete'), //是否显示表格多选
  66. pageSize: 50, // 每页条数
  67. hideExport: false, //是否隐藏导出按钮
  68. exportFileName: '系统参数', //导出报表的文件名,不填写取应用名称
  69. },
  70. // 搜索表单,动态生成(传空数组时,将不显示搜索,type有3种类型:input,date,select)
  71. search: [
  72. { label: '配置名称', prop: 'name', placeholder: '搜索配置名称', required: false, type: 'input' },
  73. { label: '配置编码', prop: 'code', placeholder: '搜索配置编码', required: false, type: 'input' },
  74. // { label: '创建时间', prop: 'time', placeholder: '请选择', required: false, type: 'date' },
  75. ],
  76. param: {},
  77. defaultSort: {
  78. prop: 'orderNo',
  79. order: 'ascending',
  80. },
  81. },
  82. });
  83. const getData = (param: any) => {
  84. return getAPI(SysConfigApi)
  85. .apiSysConfigPagePost(param)
  86. .then((res) => {
  87. return res.data;
  88. });
  89. };
  90. const exportChangeData = (data: Array<EmptyObjectType>) => {
  91. data.forEach((item) => {
  92. item.sysFlag = item.sysFlag == 1 ? '是' : '否';
  93. });
  94. return data;
  95. };
  96. // 拖动显示列排序回调
  97. const onSortHeader = (data: object[]) => {
  98. tb.tableData.columns = data;
  99. };
  100. // 搜索点击时表单回调
  101. const onSearch = (data: EmptyObjectType) => {
  102. tb.tableData.param = Object.assign({}, tb.tableData.param, { ...data });
  103. nextTick(() => {
  104. tableRef.value.pageReset();
  105. });
  106. };
  107. const getGroupList = async () => {
  108. const res = await getAPI(SysConfigApi).apiSysConfigGroupListGet();
  109. const groupSearch = {
  110. label: '分组编码',
  111. prop: 'groupCode',
  112. placeholder: '请选择',
  113. required: false,
  114. type: 'select',
  115. options: [],
  116. } as TableSearchType;
  117. state.groupList = res.data.result ?? [];
  118. res.data.result?.forEach((item) => {
  119. groupSearch.options?.push({ label: item, value: item });
  120. });
  121. let group = tb.tableData.search.filter((item) => {
  122. return item.prop == 'groupCode';
  123. });
  124. if (group.length == 0) {
  125. tb.tableData.search.push(groupSearch);
  126. } else {
  127. group[0] = groupSearch;
  128. }
  129. };
  130. //表格多选事件
  131. const tableSelection = (data: EmptyObjectType[]) => {
  132. state.selectlist = data;
  133. };
  134. onMounted(async () => {
  135. getGroupList();
  136. });
  137. // 更新数据
  138. const updateData = () => {
  139. tableRef.value.handleList();
  140. getGroupList();
  141. };
  142. // 打开新增页面
  143. const openAddConfig = () => {
  144. state.editConfigTitle = '添加配置';
  145. editConfigRef.value?.openDialog({ sysFlag: 2, orderNo: 100 });
  146. };
  147. // 打开编辑页面
  148. const openEditConfig = (row: any) => {
  149. state.editConfigTitle = '编辑配置';
  150. editConfigRef.value?.openDialog(row);
  151. };
  152. // 删除
  153. const delConfig = (row: any) => {
  154. ElMessageBox.confirm(`确定删除配置:【${row.name}】?`, '提示', {
  155. confirmButtonText: '确定',
  156. cancelButtonText: '取消',
  157. type: 'warning',
  158. })
  159. .then(async () => {
  160. await getAPI(SysConfigApi).apiSysConfigDeletePost({ id: row.id });
  161. tableRef.value.handleList();
  162. ElMessage.success('删除成功');
  163. })
  164. .catch(() => {});
  165. };
  166. //批量删除
  167. const bacthDelete = () => {
  168. if (state.selectlist.length == 0) return false;
  169. ElMessageBox.confirm(`确定批量删除【${state.selectlist[0].name}】等${state.selectlist.length}个配置?`, '提示', {
  170. confirmButtonText: '确定',
  171. cancelButtonText: '取消',
  172. type: 'warning',
  173. })
  174. .then(async () => {
  175. const ids = state.selectlist.map((item) => {
  176. return item.id;
  177. });
  178. var res = await getAPI(SysConfigApi).apiSysConfigBatchDeletePost(ids);
  179. tableRef.value.pageReset();
  180. ElMessage.success('删除成功');
  181. })
  182. .catch(() => {});
  183. };
  184. </script>