😎调整字典管理页面

This commit is contained in:
zuohuaijun 2024-07-11 02:51:21 +08:00
parent 2cac309356
commit 02c8d53f2b

View File

@ -1,18 +1,18 @@
<template>
<div class="sys-dict-container" v-loading="options.loading">
<div class="sys-dict-container" v-loading="optionsDictType.loading">
<el-row :gutter="8" style="width: 100%; height: 100%; flex: 1">
<el-col :span="12" :xs="24" class="full-height">
<el-card shadow="hover" :body-style="{ padding: '5px 5px 0 5px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
<el-form :model="state.queryParams" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
<el-form :model="state.queryParamsDictType" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
<el-form-item label="字典名称" prop="name">
<el-input v-model="state.queryParams.name" placeholder="字典名称" clearable @keyup.enter.native="handleQuery(true)" />
<el-input v-model="state.queryParamsDictType.name" placeholder="字典名称" clearable @keyup.enter.native="handleQuery" />
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
<el-form-item label="字典编码" prop="code">
<el-input v-model="state.queryParams.code" placeholder="字典编码" clearable @keyup.enter.native="handleQuery(true)" />
<el-input v-model="state.queryParamsDictType.code" placeholder="字典编码" clearable @keyup.enter.native="handleQuery" />
</el-form-item>
</el-col>
</el-row>
@ -21,15 +21,15 @@
<el-row>
<el-col>
<el-button-group>
<el-button type="primary" icon="ele-Search" @click="handleQuery(true)" v-auth="'sysDictType:page'" :loading="options.loading"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'sysDictType:page'" :loading="optionsDictType.loading"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetQuery" :loading="optionsDictType.loading"> 重置 </el-button>
</el-button-group>
</el-col>
</el-row>
</el-card>
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" @sort-change="sortChange" @cell-click="handleDictData">
<vxe-grid ref="xGridDictType" class="xGrid-style" v-bind="optionsDictType" v-on="gridEventsDictType" @cell-click="handleDictData">
<template #toolbar_buttons>
<el-icon size="16" style="margin-right: 3px; margin-top: 2px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>
<el-button type="primary" style="margin-left: 10px" icon="ele-Plus" @click="handleAdd" v-auth="'sysDictType:add'"> 新增 </el-button>
@ -50,34 +50,25 @@
<el-button icon="ele-Edit" text type="primary" v-auth="'sysDictType:update'" @click="handleEdit(row)"> </el-button>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button icon="ele-Delete" text type="danger" v-auth="'sysDictType:delete'" @click="handleDelete(row)"> </el-button>
<el-button icon="ele-Delete" text type="danger" v-auth="'sysDictType:delete'" @click="handleDeleteDictType(row)"> </el-button>
</el-tooltip>
</template>
<template #pager>
<vxe-pager
:loading="options.loading"
v-model:current-page="state.tableParams.page"
v-model:page-size="state.tableParams.pageSize"
:total="state.tableParams.total"
@page-change="pageChange"
/>
</template>
</vxe-grid>
</el-card>
</el-col>
<el-col :span="12" :xs="24" class="full-height">
<el-card shadow="hover" :body-style="{ padding: '5px 5px 0 5px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
<el-form :model="state.queryDictParams" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
<el-form :model="state.queryParamsDictData" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
<el-form-item label="字典值" prop="value">
<el-input v-model="state.queryDictParams.value" placeholder="字典值" clearable @keyup.enter.native="handleDictQuery(true)" />
<el-input v-model="state.queryParamsDictData.value" placeholder="字典值" clearable @keyup.enter.native="handleQueryDictData" />
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
<el-form-item label="编码" prop="code">
<el-input v-model="state.queryDictParams.code" placeholder="编码" clearable @keyup.enter.native="handleDictQuery(true)" />
<el-input v-model="state.queryParamsDictData.code" placeholder="编码" clearable @keyup.enter.native="handleQueryDictData" />
</el-form-item>
</el-col>
</el-row>
@ -86,18 +77,18 @@
<el-row>
<el-col>
<el-button-group>
<el-button type="primary" icon="ele-Search" @click="handleDictQuery(true)" v-auth="'sysDictType:page'" :loading="options.loading"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetDictQuery" :loading="options.loading"> 重置 </el-button>
<el-button type="primary" icon="ele-Search" @click="handleQueryDictData" v-auth="'sysDictType:page'" :loading="optionsDictData.loading"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetQueryDictData" :loading="optionsDictData.loading"> 重置 </el-button>
</el-button-group>
</el-col>
</el-row>
</el-card>
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
<vxe-grid ref="xDictGrid" class="xGrid-style" v-bind="dictOptions" @sort-change="dictSortChange">
<vxe-grid ref="xGridDictData" class="xGrid-style" v-bind="optionsDictData" v-on="gridEventsDictData">
<template #toolbar_buttons>
<el-icon size="16" style="margin-right: 3px; margin-top: 2px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>
<el-button type="primary" style="margin-left: 10px" icon="ele-Plus" @click="handleDictAdd" v-auth="'sysDictType:add'"> 新增 </el-button>
<el-button type="primary" style="margin-left: 10px" icon="ele-Plus" @click="handleAddDictData" v-auth="'sysDictType:add'"> 新增 </el-button>
</template>
<template #toolbar_tools> </template>
<template #empty>
@ -119,28 +110,19 @@
</template>
<template #row_buttons="{ row }">
<el-tooltip content="编辑" placement="top">
<el-button icon="ele-Edit" text type="primary" v-auth="'sysDictType:update'" @click="handleDictEdit(row)"> </el-button>
<el-button icon="ele-Edit" text type="primary" v-auth="'sysDictType:update'" @click="handleEditDictData(row)"> </el-button>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button icon="ele-Delete" text type="danger" v-auth="'sysDictType:delete'" @click="handleDictDelete(row)"> </el-button>
<el-button icon="ele-Delete" text type="danger" v-auth="'sysDictType:delete'" @click="handleDeleteDictData(row)"> </el-button>
</el-tooltip>
</template>
<template #pager>
<vxe-pager
:loading="dictOptions.loading"
v-model:current-page="state.tableDictParams.page"
v-model:page-size="state.tableDictParams.pageSize"
:total="state.tableDictParams.total"
@page-change="dictPageChange"
/>
</template>
</vxe-grid>
</el-card>
</el-col>
</el-row>
<EditDictType ref="editRef" :title="state.title" @handleQuery="handleQuery(false)" @handleUpdate="updateDictSession" />
<EditDcitData ref="editDictRef" :title="state.title" @handleQuery="handleDictQuery(false)" @handleUpdate="updateDictSession" />
<EditDictType ref="editRefDictType" :title="state.title" @handleQuery="handleQuery" @handleUpdate="updateDictSession" />
<EditDcitData ref="editRefDictData" :title="state.title" @handleQuery="handleQueryDictData" @handleUpdate="updateDictSession" />
</div>
</template>
@ -148,8 +130,9 @@
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { auth } from '/@/utils/authFunction';
import { VxeGridInstance, VxePagerEvents, VxePagerDefines } from 'vxe-table';
import { useVxeTable } from '/@/hooks/vxeTableOptionsHook';
import { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
import { Local } from '/@/utils/storage';
import { useUserInfo } from '/@/stores/userInfo';
import EditDictType from '/@/views/system/dict/component/editDictType.vue';
@ -158,45 +141,39 @@ import ModifyRecord from '/@/components/table/modifyRecord.vue';
import { getAPI } from '/@/utils/axios-utils';
import { SysDictTypeApi, SysDictDataApi } from '/@/api-services/api';
import { SysDictType, SysDictData } from '/@/api-services/models';
import { SysDictType, PageDictTypeInput, SysDictData, PageDictDataInput } from '/@/api-services/models';
const xGrid = ref<VxeGridInstance>();
const xDictGrid = ref<VxeGridInstance>();
const editRef = ref<InstanceType<typeof EditDictType>>();
const editDictRef = ref<InstanceType<typeof EditDcitData>>();
const xGridDictType = ref<VxeGridInstance>();
const xGridDictData = ref<VxeGridInstance>();
const editRefDictType = ref<InstanceType<typeof EditDictType>>();
const editRefDictData = ref<InstanceType<typeof EditDcitData>>();
const state = reactive({
queryParams: {
queryParamsDictType: {
name: undefined,
code: undefined,
},
queryDictParams: {
queryParamsDictData: {
dictTypeId: undefined,
value: undefined,
code: undefined,
},
tableParams: {
page: 1,
pageSize: 50,
field: 'orderNo', //
order: 'aes', //
descStr: 'desc', //
total: 0 as any,
localPageParamDictType: {
pageSize: 50 as number,
defaultSort: { field: 'orderNo', order: 'asc', descStr: 'desc' },
},
tableDictParams: {
page: 1,
pageSize: 50,
field: 'orderNo', //
order: 'aes', //
descStr: 'desc', //
total: 0 as any,
localPageParamDictData: {
pageSize: 50 as number,
defaultSort: { field: 'orderNo', order: 'asc', descStr: 'desc' },
},
title: '',
});
//
const localPageParamKey = 'localPageParam:sysDictType';
// -
const options = useVxeTable<SysDictType>(
const optionsDictType = useVxeTable<SysDictType>(
{
id: 'sysDict',
id: 'sysDictType',
name: '字典信息',
columns: [
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
@ -207,75 +184,67 @@ const options = useVxeTable<SysDictType>(
{ field: '', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
{ title: '操作', fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
],
enableExport: auth('sysDictType:export'),
searchCallback: () => handleQuery(),
queryAllCallback: () => fetchData({ pageSize: 99999 }),
},
{ rowConfig: { isCurrent: true, isHover: true }, checkboxConfig: { range: true, highlight: false } }
// vxeGrid()vxe-table
{
//
proxyConfig: { autoLoad: true, ajax: { query: ({ page, sort }) => handleQueryApi(page, sort) } },
//
sortConfig: { defaultSort: Local.get(localPageParamKey)?.defaultSort || state.localPageParamDictType.defaultSort },
//
pagerConfig: { pageSize: Local.get(localPageParamKey)?.pageSize || state.localPageParamDictType.pageSize },
//
toolbarConfig: { export: false },
//
rowConfig: { isCurrent: true, isHover: true },
checkboxConfig: { range: true, highlight: false },
}
);
//
onMounted(async () => {
state.localPageParamDictType = Local.get(localPageParamKey) || state.localPageParamDictType;
await handleQuery();
});
//
const handleQuery = async (reset = false) => {
options.loading = true;
if (reset) state.tableParams.page = 1;
var res = await fetchData(null);
await xGrid.value?.loadData(res.data.result?.items ?? []);
state.tableParams.total = res.data.result?.total;
options.loading = false;
// api
const handleQueryApi = async (page: VxeGridPropTypes.ProxyAjaxQueryPageParams, sort: VxeGridPropTypes.ProxyAjaxQuerySortCheckedParams) => {
const params = Object.assign(state.queryParamsDictType, { page: page.currentPage, pageSize: page.pageSize, field: sort.field, order: sort.order, descStr: 'desc' }) as PageDictTypeInput;
return getAPI(SysDictTypeApi).apiSysDictTypePagePost(params);
};
//
const fetchData = async (tableParams: any) => {
let params = Object.assign(state.queryParams, state.tableParams, tableParams);
return getAPI(SysDictTypeApi).apiSysDictTypePagePost(params);
//
const handleQuery = async () => {
await xGridDictType.value?.commitProxy('query');
};
//
const resetQuery = async () => {
state.queryParams.code = undefined;
state.queryParams.name = undefined;
await handleQuery(true);
};
//
const pageChange: VxePagerEvents.PageChange = async ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
state.tableParams.page = currentPage;
state.tableParams.pageSize = pageSize;
await handleQuery();
};
//
const sortChange = async (options: any) => {
state.tableParams.field = options.field;
state.tableParams.order = options.order;
await handleQuery();
state.queryParamsDictType.code = undefined;
state.queryParamsDictType.name = undefined;
await xGridDictType.value?.commitProxy('reload');
};
//
const handleAdd = () => {
state.title = '添加字典';
editRef.value?.openDialog({ status: 1, orderNo: 100 });
editRefDictType.value?.openDialog({ status: 1, orderNo: 100 });
};
//
const handleEdit = (row: any) => {
state.title = '编辑字典';
editRef.value?.openDialog(row);
editRefDictType.value?.openDialog(row);
};
//
//
const handleDictData = async (scope: any) => {
state.queryDictParams.dictTypeId = scope.row.id;
await handleDictQuery(true);
state.queryParamsDictData.dictTypeId = scope.row.id;
await handleQueryDictData();
};
//
const handleDelete = (row: any) => {
//
const handleDeleteDictType = (row: any) => {
ElMessageBox.confirm(`确定删除字典:【${row.name}】?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
@ -283,19 +252,32 @@ const handleDelete = (row: any) => {
})
.then(async () => {
await getAPI(SysDictTypeApi).apiSysDictTypeDeletePost({ id: row.id });
handleQuery();
updateDictSession();
xDictGrid.value?.loadData([]);
state.tableDictParams.total = 0;
await handleQuery();
await updateDictSession();
xGridDictData.value?.loadData([]);
ElMessage.success('删除成功');
})
.catch(() => {});
};
//
const gridEventsDictType: VxeGridListeners<SysDictType> = {
// pager-config
async pageChange({ pageSize }) {
state.localPageParamDictType.pageSize = pageSize;
// Local.set(localPageParamKey, state.localPageParam);
},
//
async sortChange({ field, order }) {
state.localPageParamDictType.defaultSort = { field: field, order: order!, descStr: 'desc' };
// Local.set(localPageParamKey, state.localPageParam);
},
};
// -
const dictOptions = useVxeTable<SysDictData>(
const optionsDictData = useVxeTable<SysDictData>(
{
id: 'dictInfo',
id: 'sysDictData',
name: '字典值信息',
columns: [
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
@ -308,53 +290,62 @@ const dictOptions = useVxeTable<SysDictData>(
{ field: '', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
{ title: '操作', fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
],
enableExport: auth('sysDictType:export'),
searchCallback: () => handleDictQuery(),
queryAllCallback: () => fetchDictData({ pageSize: 99999 }),
},
{ loading: false, rowConfig: { isCurrent: true, isHover: true }, checkboxConfig: { range: true, highlight: false } }
// vxeGrid()vxe-table
{
//
proxyConfig: { autoLoad: true, ajax: { query: ({ page, sort }) => handleQueryDictDataApi(page, sort) } },
// //
// sortConfig: { defaultSort: Local.get(localPageParamKey)?.defaultSort || state.localPageParam.defaultSort },
// //
// pagerConfig: { pageSize: Local.get(localPageParamKey)?.pageSize || state.localPageParam.pageSize },
//
toolbarConfig: { export: false },
//
loading: false,
//
rowConfig: { isCurrent: true, isHover: true },
//
checkboxConfig: { range: true, highlight: false },
}
);
//
const handleDictQuery = async (reset = false) => {
dictOptions.loading = true;
if (reset) state.tableDictParams.page = 1;
var res = await fetchDictData(null);
xDictGrid.value?.loadData(res.data.result?.items ?? []);
state.tableDictParams.total = res.data.result?.total;
dictOptions.loading = false;
};
//
const fetchDictData = async (tableParams: any) => {
let params = Object.assign(state.queryDictParams, state.tableDictParams, tableParams);
// api
const handleQueryDictDataApi = async (page: VxeGridPropTypes.ProxyAjaxQueryPageParams, sort: VxeGridPropTypes.ProxyAjaxQuerySortCheckedParams) => {
const params = Object.assign(state.queryParamsDictData, { page: page.currentPage, pageSize: page.pageSize, field: sort.field, order: sort.order, descStr: 'desc' }) as PageDictDataInput;
return getAPI(SysDictDataApi).apiSysDictDataPagePost(params);
};
//
const resetDictQuery = async () => {
state.queryDictParams.value = undefined;
state.queryDictParams.code = undefined;
await handleDictQuery(true);
//
const handleQueryDictData = async () => {
await xGridDictData.value?.commitProxy('query');
};
const handleDictAdd = () => {
if (!state.queryDictParams.dictTypeId) {
//
const resetQueryDictData = async () => {
state.queryParamsDictData.value = undefined;
state.queryParamsDictData.code = undefined;
await xGridDictData.value?.commitProxy('reload');
};
//
const handleAddDictData = () => {
if (!state.queryParamsDictData.dictTypeId) {
ElMessage.warning('请选择字典');
return;
}
state.title = '添加字典值';
editDictRef.value?.openDialog({ status: 1, orderNo: 100, dictTypeId: state.queryDictParams.dictTypeId });
editRefDictData.value?.openDialog({ status: 1, orderNo: 100, dictTypeId: state.queryParamsDictData.dictTypeId });
};
//
const handleDictEdit = (row: any) => {
const handleEditDictData = (row: any) => {
state.title = '编辑字典值';
editDictRef.value?.openDialog(row);
editRefDictData.value?.openDialog(row);
};
//
const handleDictDelete = (row: any) => {
//
const handleDeleteDictData = (row: any) => {
ElMessageBox.confirm(`确定删除字典值:【${row.value}】?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
@ -362,25 +353,25 @@ const handleDictDelete = (row: any) => {
})
.then(async () => {
await getAPI(SysDictDataApi).apiSysDictDataDeletePost({ id: row.id });
handleDictQuery();
updateDictSession();
await handleQueryDictData();
await updateDictSession();
ElMessage.success('删除成功');
})
.catch(() => {});
};
//
const dictPageChange: VxePagerEvents.PageChange = async ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
state.tableDictParams.page = currentPage;
state.tableDictParams.pageSize = pageSize;
await handleDictQuery();
};
//
const dictSortChange = async (options: any) => {
state.tableDictParams.field = options.field;
state.tableDictParams.order = options.order;
await handleDictQuery();
//
const gridEventsDictData: VxeGridListeners<SysDictData> = {
// pager-config
async pageChange({ pageSize }) {
state.localPageParamDictData.pageSize = pageSize;
// Local.set(localPageParamKey, state.localPageParam);
},
//
async sortChange({ field, order }) {
state.localPageParamDictData.defaultSort = { field: field, order: order!, descStr: 'desc' };
// Local.set(localPageParamKey, state.localPageParam);
},
};
//