😎代码优化

This commit is contained in:
zuohuaijun 2024-07-10 13:32:10 +08:00
parent 1d12c06676
commit 3eb2fe86f3
4 changed files with 47 additions and 47 deletions

View File

@ -61,7 +61,7 @@ const state = reactive({
//
onMounted(async () => {
handleQuery();
await handleQuery();
});
//
@ -109,7 +109,7 @@ const delCache = () => {
})
.then(async () => {
await getAPI(SysCacheApi).apiSysCacheDeleteKeyPost(currentNode.value.id);
handleQuery();
await handleQuery();
state.cacheValue = undefined;
state.cacheKey = undefined;
ElMessage.success('删除成功');

View File

@ -5,7 +5,7 @@
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="配置名称" prop="name">
<el-input v-model="state.queryParams.name" placeholder="配置名称" clearable @keyup.enter.native="handleQuery()" />
<el-input v-model="state.queryParams.name" placeholder="配置名称" clearable @keyup.enter.native="handleQuery" />
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
@ -72,6 +72,7 @@ import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
import { Local } from '/@/utils/storage';
import EditConfig from '/@/views/system/config/component/editConfig.vue';
import ModifyRecord from '/@/components/table/modifyRecord.vue';
@ -79,7 +80,7 @@ import ModifyRecord from '/@/components/table/modifyRecord.vue';
import { getAPI } from '/@/utils/axios-utils';
import { SysConfigApi } from '/@/api-services/api';
import { SysConfig, PageConfigInput } from '/@/api-services/models';
import { Local } from '/@/utils/storage';
const xGrid = ref<VxeGridInstance>();
const editConfigRef = ref<InstanceType<typeof EditConfig>>();
const state = reactive({
@ -89,7 +90,7 @@ const state = reactive({
groupCode: undefined,
},
localPageParam: {
pageSize: 20 as number,
pageSize: 50 as number,
defaultSort: { field: 'orderNo', order: 'asc', descStr: 'desc' },
},
visible: false,
@ -135,7 +136,7 @@ const options = useVxeTable<SysConfig>(
//
onMounted(async () => {
state.localPageParam = Local.get(localPageParamKey) || state.localPageParam;
fetchGroupData();
await fetchGroupData();
});
// api
@ -149,10 +150,6 @@ const handleQuery = async () => {
// vxe-gridcommitProxy(query)
await xGrid.value?.commitProxy('query');
};
const fetchGroupData = async () => {
const res = await getAPI(SysConfigApi).apiSysConfigGroupListGet();
state.groupList = res.data.result ?? [];
};
//
const resetQuery = async () => {
@ -163,19 +160,6 @@ const resetQuery = async () => {
await xGrid.value?.commitProxy('reload');
};
//
const gridEvents: VxeGridListeners<SysConfig> = {
// pager-config
async pageChange({ pageSize }) {
state.localPageParam.pageSize = pageSize;
Local.set(localPageParamKey, state.localPageParam);
},
//
async sortChange({ field, order }) {
state.localPageParam.defaultSort = { field: field, order: order!, descStr: 'desc' };
Local.set(localPageParamKey, state.localPageParam);
},
};
//
const handleAdd = () => {
state.title = '添加配置';
@ -188,12 +172,6 @@ const handleEdit = (row: any) => {
editConfigRef.value?.openDialog(row);
};
//
const updateData = async () => {
await handleQuery();
fetchGroupData();
};
//
const handleDelete = (row: any) => {
ElMessageBox.confirm(`确定删除配置:【${row.name}】?`, '提示', {
@ -209,24 +187,46 @@ const handleDelete = (row: any) => {
.catch(() => {});
};
const handleSelectChange = () => {
state.selectList = xGrid.value?.getCheckboxRecords() ?? [];
//
const gridEvents: VxeGridListeners<SysConfig> = {
// pager-config
async pageChange({ pageSize }) {
state.localPageParam.pageSize = pageSize;
Local.set(localPageParamKey, state.localPageParam);
},
//
async sortChange({ field, order }) {
state.localPageParam.defaultSort = { field: field, order: order!, descStr: 'desc' };
Local.set(localPageParamKey, state.localPageParam);
},
};
//
const handleBacthDelete = () => {
if (state.selectList.length == 0) return false;
ElMessageBox.confirm(`确定批量删除【${state.selectList[0].name}】等${state.selectList.length}个配置?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
const ids = state.selectList.map((item: any) => item.id);
var res = await getAPI(SysConfigApi).apiSysConfigBatchDeletePost(ids);
handleQuery();
ElMessage.success('删除成功');
})
.catch(() => {});
//
const fetchGroupData = async () => {
const res = await getAPI(SysConfigApi).apiSysConfigGroupListGet();
state.groupList = res.data.result ?? [];
};
//
const updateData = async () => {
await handleQuery();
fetchGroupData();
};
// //
// const handleBacthDelete = () => {
// if (state.selectList.length == 0) return false;
// ElMessageBox.confirm(`${state.selectList[0].name}${state.selectList.length}?`, '', {
// confirmButtonText: '',
// cancelButtonText: '',
// type: 'warning',
// })
// .then(async () => {
// const ids = state.selectList.map((item: any) => item.id);
// var res = await getAPI(SysConfigApi).apiSysConfigBatchDeletePost(ids);
// handleQuery();
// ElMessage.success('');
// })
// .catch(() => {});
// };
</script>

View File

@ -142,7 +142,7 @@ import VueOfficePdf from '@vue-office/pdf';
import '@vue-office/docx/lib/index.css';
import '@vue-office/excel/lib/index.css';
import EditFile from '/@/views/system/file/component/editSysfile.vue';
import EditFile from '/@/views/system/file/component/editFile.vue';
import { getAPI } from '/@/utils/axios-utils';
import { SysFileApi } from '/@/api-services/api';