feat: 优化可两栏布局的页面都改成两栏

This commit is contained in:
2026-08-18 16:54:08 +08:00
parent 5d965e91e3
commit 15d0bdacb7
15 changed files with 1604 additions and 1497 deletions
@@ -1,19 +1,13 @@
<script setup lang="ts">
import type { CompanyVO } from '#/api/company/types';
import { computed, onMounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { computed, ref } from 'vue';
import {
Button,
Card,
Empty,
Flex,
Input,
message,
Select,
Space,
Spin,
Tag,
@@ -25,27 +19,13 @@ import {
getCompanyMenusApi,
getCompanyMenuIdsApi,
} from '#/api/company/menu/apis';
import { getCompanyPageApi } from '#/api/company';
import CompanyColPage from '#/views/company/components/CompanyColPage.vue';
defineOptions({
name: 'CompanyMenuManagePage',
});
const BuildingIcon = createIconifyIcon('lucide:building-2');
const companySearchForm = ref({
name: '',
status: undefined as number | undefined,
});
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
const companyLoading = ref(false);
const companyPagination = ref({
current: 1,
pageSize: 20,
total: 0,
});
const selectedCompanyId = ref<number | undefined>(undefined);
const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
const systemMenuList = ref<any[]>([]);
@@ -54,13 +34,6 @@ const selectedMenuIds = ref<number[]>([]);
const menuExpandedKeys = ref<(number | string)[]>([]);
const menuLoading = ref(false);
const selectedCompanyLabel = computed(() => {
if (!currentCompany.value) {
return '请先选择公司';
}
return currentCompany.value.name;
});
const menuTreeData = computed(() => {
const list = systemMenuList.value;
const map = new Map<number, any>();
@@ -89,29 +62,10 @@ const stats = computed(() => ({
changed: selectedMenuIds.value.length !== companyMenuIds.value.length,
}));
async function searchCompanies() {
companyLoading.value = true;
try {
const result = await getCompanyPageApi({
page: companyPagination.value.current,
pageSize: companyPagination.value.pageSize,
filters: {
name: companySearchForm.value.name || undefined,
status: companySearchForm.value.status,
},
});
companyList.value = result.records;
companyPagination.value.total = result.total;
} catch (error: any) {
message.error(error?.message || '获取公司列表失败');
} finally {
companyLoading.value = false;
}
}
async function selectCompany(company: CompanyVO.CompanyInfoVO) {
function onCompanySelect(company: CompanyVO.CompanyInfoVO) {
currentCompany.value = company;
await loadCompanyMenus();
selectedCompanyId.value = company.id;
void loadCompanyMenus();
}
async function loadCompanyMenus() {
@@ -208,249 +162,87 @@ async function handleSave() {
message.error(error?.message || '保存失败');
}
}
function resetCompanySearch() {
companySearchForm.value = { name: '', status: undefined };
companyPagination.value.current = 1;
searchCompanies();
}
function handleCompanyPageChange(page: number, pageSize: number) {
companyPagination.value.current = page;
companyPagination.value.pageSize = pageSize;
searchCompanies();
}
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(() => {
searchCompanies();
});
</script>
<template>
<Page title="公司菜单管理" :auto-content-height="true">
<template #description>
<div class="text-foreground/80 mt-2">
左侧选择公司,右侧勾选并保存该公司可访问的菜单。
</div>
</template>
<CompanyColPage
:selected-company-id="selectedCompanyId"
@select="onCompanySelect"
>
<Card
class="ml-1 flex h-full min-h-0 min-w-0 flex-1 flex-col sm:ml-2"
:body-style="{
height: '100%',
minHeight: 0,
padding: 0,
display: 'flex',
flexDirection: 'column',
}"
>
<template #title>
<span class="text-base font-semibold">菜单分配</span>
</template>
<template #extra>
<Space>
<Button :disabled="!currentCompany" @click="selectNone">取消全选</Button>
<Button type="primary" :disabled="!currentCompany" @click="selectAll">
一键全选
</Button>
<Button
type="primary"
:disabled="!currentCompany || !stats.changed"
@click="handleSave"
>
保存配置
</Button>
</Space>
</template>
<Flex gap="middle" class="h-full min-h-0 overflow-hidden">
<!-- 左:公司 -->
<Card
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',
}"
>
<template #title>
<span class="flex items-center gap-2 text-base font-semibold">
<BuildingIcon class="h-4 w-4" />
公司
</span>
</template>
<div class="flex min-w-0 shrink-0 flex-col gap-2">
<Input
v-model:value="companySearchForm.name"
placeholder="公司名称"
allow-clear
class="w-full min-w-0"
@press-enter="searchCompanies"
/>
<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 },
]"
/>
<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)"
>
<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>
<div
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
>
<Button
size="small"
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>
<!-- 右:菜单分配 -->
<Card
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
:body-style="{
height: '100%',
minHeight: 0,
padding: 0,
display: 'flex',
flexDirection: 'column',
}"
>
<template #title>
<span class="text-base font-semibold">菜单分配</span>
</template>
<div
class="shrink-0 border-t border-border px-4 py-2 text-xs text-muted-foreground"
>
当前:{{ selectedCompanyLabel }}
<template #extra>
<Space wrap size="small">
<template v-if="currentCompany">
<Tag
class="ml-2"
:color="currentCompany.status === 1 ? 'green' : 'red'"
>
<Tag :color="currentCompany.status === 1 ? 'green' : 'red'">
{{ currentCompany.status === 1 ? '启用' : '禁用' }}
</Tag>
<span class="ml-3">
<span class="text-xs text-muted-foreground">
系统菜单 {{ stats.total }} · 已配置
<strong class="text-green-600">{{ stats.company }}</strong> · 当前选择
<strong class="text-green-600">{{ stats.company }}</strong> · 当前
<strong class="text-blue-600">{{ stats.selected }}</strong>
<span v-if="stats.changed" class="text-orange-500">(有未保存更改)</span>
<span v-if="stats.changed" class="text-orange-500">(未保存)</span>
</span>
</template>
</div>
<Button :disabled="!currentCompany" @click="selectNone">取消全选</Button>
<Button type="primary" :disabled="!currentCompany" @click="selectAll">
一键全选
</Button>
<Button
type="primary"
:disabled="!currentCompany || !stats.changed"
@click="handleSave"
>
保存配置
</Button>
</Space>
</template>
<div
v-if="!currentCompany"
class="flex min-h-0 flex-1 items-center justify-center"
>
<Empty description="请从左侧选择公司以配置菜单" />
</div>
<div
v-if="!currentCompany"
class="flex min-h-0 flex-1 items-center justify-center"
>
<Empty description="请从左侧选择公司以配置菜单" />
</div>
<div v-else class="min-h-0 flex-1 overflow-y-auto px-4 py-3 sm:px-5">
<Spin :spinning="menuLoading">
<Tree
v-model:checked-keys="selectedMenuIds"
v-model:expanded-keys="menuExpandedKeys"
:tree-data="menuTreeData"
checkable
block-node
:selectable="false"
@check="handleTreeCheckChange"
>
<template #title="{ title, status }">
<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>
</div>
</Card>
</Flex>
</Page>
<div v-else class="min-h-0 flex-1 overflow-y-auto px-4 py-3 sm:px-5">
<Spin :spinning="menuLoading">
<Tree
v-model:checked-keys="selectedMenuIds"
v-model:expanded-keys="menuExpandedKeys"
:tree-data="menuTreeData"
checkable
block-node
:selectable="false"
@check="handleTreeCheckChange"
>
<template #title="{ title, status }">
<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>
</div>
</Card>
</CompanyColPage>
</template>