😎调整用户管理页面

This commit is contained in:
zuohuaijun 2024-07-11 00:04:43 +08:00
parent e2110487f3
commit 33368c910c

View File

@ -11,17 +11,17 @@
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="账号" prop="account">
<el-input v-model="state.queryParams.account" placeholder="账号" clearable @keyup.enter.native="handleQuery(true)" />
<el-input v-model="state.queryParams.account" 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">
<el-form-item label="姓名" prop="realName">
<el-input v-model="state.queryParams.realName" placeholder="姓名" clearable @keyup.enter.native="handleQuery(true)" />
<el-input v-model="state.queryParams.realName" 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">
<el-form-item label="手机号码" prop="phone">
<el-input v-model="state.queryParams.phone" placeholder="手机号码" clearable @keyup.enter.native="handleQuery(true)" />
<el-input v-model="state.queryParams.phone" placeholder="手机号码" clearable @keyup.enter.native="handleQuery" />
</el-form-item>
</el-col>
</el-row>
@ -32,7 +32,7 @@
<el-row>
<el-col>
<el-button-group>
<el-button type="primary" icon="ele-Search" @click="handleQuery(true)" v-auth="'sysUser:page'" :loading="options.loading"> 查询 </el-button>
<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'sysUser:page'" :loading="options.loading"> 查询 </el-button>
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
</el-button-group>
</el-col>
@ -40,7 +40,7 @@
</el-card>
<el-card class="full-table" shadow="hover" style="margin-top: 5px; flex: 1">
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" @sort-change="sortChange">
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" v-on="gridEvents">
<template #toolbar_buttons>
<el-button type="primary" icon="ele-Plus" @click="handleAdd" v-auth="'sysUser:add'"> 新增 </el-button>
</template>
@ -78,15 +78,6 @@
<el-button icon="ele-RefreshLeft" text type="danger" v-auth="'sysUser:resetPwd'" @click="resetQueryPwd(row)">重置密码</el-button>
<el-button icon="ele-Unlock" text type="primary" v-auth="'sysUser:unlockLogin'" @click="handleUnlock(row)">解除锁定</el-button>
</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>
@ -100,8 +91,9 @@
import { onMounted, reactive, ref, onActivated } 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 XEUtils from 'xe-utils';
import OrgTree from '/@/views/system/org/component/orgTree.vue';
@ -110,7 +102,7 @@ import ModifyRecord from '/@/components/table/modifyRecord.vue';
import { getAPI } from '/@/utils/axios-utils';
import { SysUserApi, SysOrgApi } from '/@/api-services/api';
import { SysUser, SysOrg } from '/@/api-services/models';
import { SysOrg, PageTenantInput, UserOutput } from '/@/api-services/models';
const xGrid = ref<VxeGridInstance>();
const treeRef = ref<InstanceType<typeof OrgTree>>();
@ -123,45 +115,53 @@ const state = reactive({
realName: undefined,
phone: undefined,
},
tableParams: {
page: 1,
pageSize: 50,
field: 'id', //
order: 'aes', //
descStr: 'desc', //
total: 0 as any,
localPageParam: {
pageSize: 50 as number,
defaultSort: { field: 'orderNo', order: 'asc', descStr: 'desc' },
},
visible: false,
title: '',
});
//
const localPageParamKey = 'localPageParam:sysUser';
//
const options = useVxeTable<SysUser>({
id: 'sysUser',
name: '账号',
columns: [
// { type: 'checkbox', width: 40, fixed: 'left' },
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
{ field: 'avatar', title: '头像', minWidth: 80, showOverflow: 'tooltip', slots: { default: 'row_avatar' } },
{ field: 'account', title: '账号', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'nickName', title: '昵称', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'realName', title: '姓名', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'phone', title: '手机号码', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'birthday', title: '出生日期', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }: any) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd') },
{ field: 'sex', title: '性别', minWidth: 70, showOverflow: 'tooltip', slots: { default: 'row_sex' } },
{ field: 'accountType', title: '账号类型', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_accountType' } },
{ field: 'roleName', title: '角色集合', minWidth: 130, showOverflow: 'tooltip' },
{ field: 'orgName', title: '所属机构', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'posName', title: '职位名称', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'status', title: '状态', width: 80, showOverflow: 'tooltip', slots: { default: 'row_status' } },
{ field: 'orderNo', title: '排序', width: 80, showOverflow: 'tooltip' },
{ field: '', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
{ title: '操作', fixed: 'right', width: 280, showOverflow: true, slots: { default: 'row_buttons' } },
],
enableExport: auth('sysUser:page'),
searchCallback: () => handleQuery(),
queryAllCallback: () => fetchData({ pageSize: 99999 }),
});
const options = useVxeTable<UserOutput>(
{
id: 'sysUser',
name: '账号',
columns: [
// { type: 'checkbox', width: 40, fixed: 'left' },
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
{ field: 'avatar', title: '头像', minWidth: 80, showOverflow: 'tooltip', slots: { default: 'row_avatar' } },
{ field: 'account', title: '账号', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'nickName', title: '昵称', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'realName', title: '姓名', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'phone', title: '手机号码', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'birthday', title: '出生日期', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }: any) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd') },
{ field: 'sex', title: '性别', minWidth: 70, showOverflow: 'tooltip', slots: { default: 'row_sex' } },
{ field: 'accountType', title: '账号类型', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_accountType' } },
{ field: 'roleName', title: '角色集合', minWidth: 130, showOverflow: 'tooltip' },
{ field: 'orgName', title: '所属机构', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'posName', title: '职位名称', minWidth: 120, showOverflow: 'tooltip' },
{ field: 'status', title: '状态', width: 80, showOverflow: 'tooltip', slots: { default: 'row_status' } },
{ field: 'orderNo', title: '排序', width: 80, showOverflow: 'tooltip' },
{ field: '', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
{ title: '操作', fixed: 'right', width: 280, showOverflow: true, slots: { default: 'row_buttons' } },
],
},
// vxeGrid()vxe-table
{
//
proxyConfig: { autoLoad: true, ajax: { query: ({ page, sort }) => handleQueryApi(page, sort) } },
//
sortConfig: { defaultSort: Local.get(localPageParamKey)?.defaultSort || state.localPageParam.defaultSort },
//
pagerConfig: { pageSize: Local.get(localPageParamKey)?.pageSize || state.localPageParam.pageSize },
//
toolbarConfig: { export: false },
}
);
//
onMounted(async () => {
@ -174,29 +174,24 @@ onActivated(async () => {
await fetchOrgData();
});
//
const handleQuery = async (reset = false) => {
options.loading = true;
if (reset) state.tableParams.page = 1;
var res = await fetchData(null);
xGrid.value?.loadData(res.data.result?.items ?? []);
state.tableParams.total = res.data.result?.total;
options.loading = false;
};
//
const fetchData = async (tableParams: any) => {
let params = Object.assign(state.queryParams, state.tableParams, tableParams);
// api
const handleQueryApi = async (page: VxeGridPropTypes.ProxyAjaxQueryPageParams, sort: VxeGridPropTypes.ProxyAjaxQuerySortCheckedParams) => {
const params = Object.assign(state.queryParams, { page: page.currentPage, pageSize: page.pageSize, field: sort.field, order: sort.order, descStr: 'desc' }) as PageTenantInput;
return getAPI(SysUserApi).apiSysUserPagePost(params);
};
//
const handleQuery = async () => {
await xGrid.value?.commitProxy('query');
};
//
const resetQuery = () => {
const resetQuery = async () => {
state.queryParams.orgId = -1;
state.queryParams.account = undefined;
state.queryParams.realName = undefined;
state.queryParams.phone = undefined;
handleQuery(true);
await xGrid.value?.commitProxy('reload');
};
//
@ -205,20 +200,6 @@ const fetchOrgData = async () => {
state.treeData = res.data.result ?? [];
};
//
const pageChange: VxePagerEvents.PageChange = ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
state.tableParams.page = currentPage;
state.tableParams.pageSize = pageSize;
handleQuery();
};
//
const sortChange = (options: any) => {
state.tableParams.field = options.field;
state.tableParams.order = options.order;
handleQuery();
};
//
const handleAdd = () => {
state.title = '添加账号';
@ -298,6 +279,20 @@ const handleNodeChange = async (node: any) => {
state.queryParams.account = undefined;
state.queryParams.realName = undefined;
state.queryParams.phone = undefined;
handleQuery(true);
await xGrid.value?.commitProxy('query');
};
//
const gridEvents: VxeGridListeners<UserOutput> = {
// 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);
},
};
</script>