feat: 优化前端系统菜单和系统权限页UI和交互

This commit is contained in:
2026-08-15 14:42:43 +08:00
parent 5f6b96e662
commit 64c38a4928
3 changed files with 312 additions and 358 deletions
@@ -13,7 +13,6 @@ import {
Flex,
Input,
message,
Pagination,
Select,
Space,
Spin,
@@ -27,10 +26,6 @@ import {
getCompanyMenuIdsApi,
} from '#/api/company/menu/apis';
import { getCompanyPageApi } from '#/api/company';
import {
SIDEBAR_LIST_SHELL_CLASS,
sidebarListRowClass,
} from '#/utils/sidebar-list-styles';
defineOptions({
name: 'CompanyMenuManagePage',
@@ -56,6 +51,7 @@ const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
const systemMenuList = ref<any[]>([]);
const companyMenuIds = ref<number[]>([]);
const selectedMenuIds = ref<number[]>([]);
const menuExpandedKeys = ref<(number | string)[]>([]);
const menuLoading = ref(false);
const selectedCompanyLabel = computed(() => {
@@ -129,6 +125,7 @@ async function loadCompanyMenus() {
systemMenuList.value = allMenus || [];
companyMenuIds.value = menuIds || [];
selectedMenuIds.value = [...companyMenuIds.value];
menuExpandedKeys.value = (allMenus || []).map((m: { id: number }) => m.id);
} catch (error: any) {
message.error(error?.message || '加载菜单失败');
} finally {
@@ -224,9 +221,17 @@ function handleCompanyPageChange(page: number, pageSize: number) {
searchCompanies();
}
function companyRowClass(companyId: number) {
const active = currentCompany.value?.id === companyId;
return sidebarListRowClass(active, 'w-full cursor-pointer text-left');
const companyTotalPages = computed(() => {
const { total, pageSize } = companyPagination.value;
return Math.max(1, Math.ceil(total / pageSize) || 1);
});
function goCompanyPage(page: number) {
const next = Math.min(companyTotalPages.value, Math.max(1, page));
if (next === companyPagination.value.current) {
return;
}
handleCompanyPageChange(next, companyPagination.value.pageSize);
}
onMounted(() => {
@@ -258,16 +263,18 @@ onMounted(() => {
</Space>
</template>
<Flex gap="middle" class="h-full min-h-0">
<Flex gap="middle" class="h-full min-h-0 overflow-hidden">
<!-- 左:公司 -->
<Card
class="flex h-full w-[420px] shrink-0 flex-col"
class="flex h-full w-[320px] shrink-0 flex-col overflow-hidden"
:body-style="{
height: '100%',
display: 'flex',
flexDirection: 'column',
gap: '8px',
minHeight: 0,
minWidth: 0,
overflow: 'hidden',
padding: '12px',
}"
>
@@ -278,67 +285,101 @@ onMounted(() => {
</span>
</template>
<Flex wrap="wrap" align="center" class="shrink-0 gap-2">
<div class="flex min-w-0 shrink-0 flex-col gap-2">
<Input
v-model:value="companySearchForm.name"
placeholder="公司名称"
allow-clear
class="min-w-[140px] flex-1"
class="w-full min-w-0"
@press-enter="searchCompanies"
/>
<Select
v-model:value="companySearchForm.status"
placeholder="状态"
allow-clear
class="w-[88px]"
:options="[
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
]"
/>
<Button type="primary" size="small" @click="searchCompanies">
搜索
</Button>
<Button size="small" @click="resetCompanySearch">重置</Button>
</Flex>
<Spin :spinning="companyLoading" class="flex min-h-0 flex-1 flex-col">
<div :class="SIDEBAR_LIST_SHELL_CLASS">
<Empty
v-if="!companyLoading && companyList.length === 0"
class="py-8"
description="暂无公司"
<div class="flex min-w-0 items-center gap-2">
<Select
v-model:value="companySearchForm.status"
placeholder="状态"
allow-clear
class="min-w-0 flex-1"
:options="[
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
]"
/>
<div v-else class="space-y-1">
<button
v-for="company in companyList"
:key="company.id"
type="button"
:class="companyRowClass(company.id)"
@click="selectCompany(company)"
>
<span class="block truncate">{{ company.name }}</span>
<span
class="mt-0.5 block truncate text-xs font-normal text-muted-foreground"
<Button type="primary" class="shrink-0" @click="searchCompanies">
搜索
</Button>
<Button class="shrink-0" @click="resetCompanySearch">重置</Button>
</div>
</div>
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
<div class="min-h-0 flex-1 overflow-y-auto">
<Spin :spinning="companyLoading">
<Empty
v-if="!companyLoading && companyList.length === 0"
class="py-8"
description="暂无公司"
/>
<template v-else>
<Card
v-for="company in companyList"
:key="company.id"
size="small"
:body-style="{ padding: '10px 12px' }"
class="mb-2 cursor-pointer !shadow-none last:mb-0 hover:border-primary"
:class="
currentCompany?.id === company.id
? 'border-primary bg-primary/5'
: undefined
"
@click="selectCompany(company)"
>
{{ company.status === 1 ? '启用' : '禁用' }}
</span>
</button>
</div>
<div class="flex items-center justify-between gap-2">
<span class="min-w-0 truncate text-sm font-medium">
{{ company.name }}
</span>
<Tag
class="m-0 shrink-0"
:color="company.status === 1 ? 'green' : 'red'"
>
{{ company.status === 1 ? '启用' : '禁用' }}
</Tag>
</div>
</Card>
</template>
</Spin>
</div>
<Flex justify="center" class="mt-2 shrink-0 pt-1">
<Pagination
v-model:current="companyPagination.current"
v-model:page-size="companyPagination.pageSize"
:total="companyPagination.total"
<div
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
>
<Button
size="small"
:show-size-changer="true"
:show-quick-jumper="true"
@change="handleCompanyPageChange"
/>
</Flex>
</Spin>
class="shrink-0"
:disabled="companyPagination.current <= 1 || companyLoading"
@click="goCompanyPage(companyPagination.current - 1)"
>
上一页
</Button>
<span
class="min-w-0 flex-1 truncate text-center text-xs text-muted-foreground"
>
{{ companyPagination.current }} / {{ companyTotalPages }}
<span class="ml-1 opacity-70"
>({{ companyPagination.total }})</span
>
</span>
<Button
size="small"
class="shrink-0"
:disabled="
companyPagination.current >= companyTotalPages || companyLoading
"
@click="goCompanyPage(companyPagination.current + 1)"
>
下一页
</Button>
</div>
</div>
</Card>
<!-- 右:菜单分配 -->
@@ -387,19 +428,24 @@ onMounted(() => {
<Spin :spinning="menuLoading">
<Tree
v-model:checked-keys="selectedMenuIds"
v-model:expanded-keys="menuExpandedKeys"
:tree-data="menuTreeData"
checkable
:default-expand-all="true"
class="company-menu-tree"
block-node
:selectable="false"
@check="handleTreeCheckChange"
>
<template #title="{ title, status }">
<span>
{{ title }}
<span v-if="status === 0" class="ml-2 text-xs text-gray-400">
(已禁用)
</span>
</span>
<div class="flex min-w-0 items-center gap-2">
<span class="min-w-0 truncate font-medium">{{ title }}</span>
<Tag
v-if="status === 0"
color="default"
class="m-0 shrink-0"
>
已禁用
</Tag>
</div>
</template>
</Tree>
</Spin>