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
@@ -0,0 +1,73 @@
<script setup lang="ts">
import type { CompanyVO } from '#/api/company/types';
import { ColPage } from '@vben/common-ui';
import CompanySidebarList from '#/views/company/components/CompanySidebarList.vue';
defineOptions({ name: 'CompanyColPage' });
withDefaults(
defineProps<{
selectedCompanyId?: number;
autoContentHeight?: boolean;
leftWidth?: number;
leftMinWidth?: number;
leftMaxWidth?: number;
leftCollapsedWidth?: number;
leftCollapsible?: boolean;
resizable?: boolean;
splitHandle?: boolean;
splitLine?: boolean;
}>(),
{
autoContentHeight: true,
leftWidth: 22,
leftMinWidth: 16,
leftMaxWidth: 36,
leftCollapsedWidth: 5,
leftCollapsible: true,
resizable: true,
splitHandle: false,
splitLine: false,
},
);
const emit = defineEmits<{
'update:selectedCompanyId': [id: number | undefined];
select: [company: CompanyVO.CompanyInfoVO];
}>();
</script>
<template>
<ColPage
:auto-content-height="autoContentHeight"
:left-width="leftWidth"
:left-min-width="leftMinWidth"
:left-max-width="leftMaxWidth"
:left-collapsed-width="leftCollapsedWidth"
:left-collapsible="leftCollapsible"
:right-width="100 - leftWidth"
:resizable="resizable"
:split-handle="splitHandle"
:split-line="splitLine"
content-class="!p-2 sm:!p-3"
>
<template #left="{ isCollapsed, expand, collapse }">
<div class="flex h-full min-h-0 min-w-0 flex-col overflow-hidden">
<CompanySidebarList
fluid
:collapsed="isCollapsed"
show-collapse-action
:selected-company-id="selectedCompanyId"
@collapse="collapse"
@expand="expand"
@update:selected-company-id="emit('update:selectedCompanyId', $event)"
@select="emit('select', $event)"
/>
</div>
</template>
<slot />
</ColPage>
</template>
@@ -0,0 +1,55 @@
<script setup lang="ts">
import { computed } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import { Avatar } from 'ant-design-vue';
defineOptions({ name: 'CompanyLogoAvatar' });
const props = withDefaults(
defineProps<{
logo?: string;
name?: string;
size?: number;
}>(),
{
logo: undefined,
name: undefined,
size: 36,
},
);
const BuildingIcon = createIconifyIcon('lucide:building-2');
const fallbackText = computed(() => {
const text = props.name?.trim();
return text ? text.charAt(0).toUpperCase() : '';
});
</script>
<template>
<Avatar
:size="size"
:src="logo"
:alt="name"
shape="square"
class="company-logo-avatar shrink-0 !rounded-md !bg-muted"
>
<span v-if="fallbackText" class="text-xs font-medium">{{ fallbackText }}</span>
<BuildingIcon v-else class="h-4 w-4 text-muted-foreground" />
</Avatar>
</template>
<style scoped>
.company-logo-avatar {
display: inline-flex !important;
align-items: center !important;
justify-content: center !important;
}
.company-logo-avatar span {
display: block;
line-height: 1;
}
</style>
@@ -0,0 +1,330 @@
<script setup lang="ts">
import type { CompanyVO } from '#/api/company/types';
import { computed, onMounted, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import {
Button,
Card,
Empty,
Input,
message,
Select,
Spin,
Tag,
Tooltip,
} from 'ant-design-vue';
import { getCompanyPageApi } from '#/api/company';
import CompanyLogoAvatar from '#/views/company/components/CompanyLogoAvatar.vue';
defineOptions({ name: 'CompanySidebarList' });
const props = withDefaults(
defineProps<{
selectedCompanyId?: number;
fluid?: boolean;
showCollapseAction?: boolean;
collapsed?: boolean;
}>(),
{
selectedCompanyId: undefined,
fluid: false,
showCollapseAction: false,
collapsed: false,
},
);
const emit = defineEmits<{
'update:selectedCompanyId': [id: number | undefined];
select: [company: CompanyVO.CompanyInfoVO];
collapse: [];
expand: [];
}>();
const BuildingIcon = createIconifyIcon('lucide:building-2');
const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
const PanelOpenIcon = createIconifyIcon('lucide:panel-left-open');
const ChevronUpIcon = createIconifyIcon('lucide:chevron-up');
const ChevronDownIcon = createIconifyIcon('lucide:chevron-down');
const companySearchForm = ref({
name: '',
status: undefined as number | undefined,
});
const companies = ref<CompanyVO.CompanyInfoVO[]>([]);
const companiesLoading = ref(false);
const companyPagination = ref({ current: 1, pageSize: 20, total: 0 });
const companyTotalPages = computed(() => {
const { total, pageSize } = companyPagination.value;
return Math.max(1, Math.ceil(total / pageSize) || 1);
});
async function searchCompanies(resetPage = false) {
if (resetPage) {
companyPagination.value.current = 1;
}
companiesLoading.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,
},
});
companies.value = result.records ?? [];
companyPagination.value.total = result.total ?? 0;
} catch (error: any) {
message.error(error?.message || '获取公司列表失败');
companies.value = [];
} finally {
companiesLoading.value = false;
}
}
function resetCompanySearch() {
companySearchForm.value = { name: '', status: undefined };
void searchCompanies(true);
}
function goCompanyPage(page: number) {
const next = Math.min(companyTotalPages.value, Math.max(1, page));
if (next === companyPagination.value.current) return;
companyPagination.value.current = next;
void searchCompanies();
}
function selectCompany(company: CompanyVO.CompanyInfoVO) {
emit('update:selectedCompanyId', company.id);
emit('select', company);
}
onMounted(() => {
void searchCompanies();
});
</script>
<template>
<div
v-if="collapsed"
class="flex h-full min-h-0 w-full flex-col items-center gap-1 pb-2 pt-3"
>
<Tooltip title="展开公司列表">
<Button type="text" size="small" class="!px-1" @click="emit('expand')">
<PanelOpenIcon class="h-4 w-4" />
</Button>
</Tooltip>
<div
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1 pb-1 pt-2"
>
<Spin
:spinning="companiesLoading"
size="small"
wrapper-class-name="company-sidebar-collapsed-spin"
>
<div class="flex w-full flex-col items-center gap-1.5">
<Tooltip v-for="company in companies" :key="company.id" :title="company.name">
<button
type="button"
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
:class="
selectedCompanyId === company.id
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
: undefined
"
@click="selectCompany(company)"
>
<CompanyLogoAvatar
:logo="company.logo"
:name="company.name"
:size="36"
/>
</button>
</Tooltip>
</div>
</Spin>
</div>
<div
v-if="companyTotalPages > 1"
class="flex shrink-0 flex-col items-center gap-0.5"
>
<Button
type="text"
size="small"
class="!h-6 !px-1"
:disabled="companyPagination.current <= 1 || companiesLoading"
@click="goCompanyPage(companyPagination.current - 1)"
>
<ChevronUpIcon class="h-3.5 w-3.5" />
</Button>
<span class="text-[10px] leading-none text-muted-foreground">
{{ companyPagination.current }}/{{ companyTotalPages }}
</span>
<Button
type="text"
size="small"
class="!h-6 !px-1"
:disabled="companyPagination.current >= companyTotalPages || companiesLoading"
@click="goCompanyPage(companyPagination.current + 1)"
>
<ChevronDownIcon class="h-3.5 w-3.5" />
</Button>
</div>
</div>
<Card
v-else
class="flex h-full flex-col overflow-hidden"
:class="fluid ? 'w-full min-w-0' : 'w-[320px] shrink-0'"
: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>
<template v-if="showCollapseAction" #extra>
<Tooltip title="收起公司列表">
<Button type="text" size="small" class="!px-1" @click="emit('collapse')">
<PanelCloseIcon class="h-4 w-4" />
</Button>
</Tooltip>
</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(true)"
/>
<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(true)">
搜索
</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="companiesLoading">
<Empty
v-if="!companiesLoading && companies.length === 0"
class="py-8"
description="暂无公司"
/>
<template v-else>
<Card
v-for="company in companies"
:key="company.id"
size="small"
:body-style="{ padding: '10px 12px' }"
class="mb-2 cursor-pointer !shadow-none last:mb-0 hover:border-primary"
:class="
selectedCompanyId === company.id
? 'border-primary bg-primary/5'
: undefined
"
@click="selectCompany(company)"
>
<div class="flex items-center gap-2">
<CompanyLogoAvatar
:logo="company.logo"
:name="company.name"
:size="36"
/>
<div class="flex min-w-0 flex-1 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>
</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 || companiesLoading"
@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 || companiesLoading
"
@click="goCompanyPage(companyPagination.current + 1)"
>
下一页
</Button>
</div>
</div>
</Card>
</template>
<style scoped>
:deep(.company-sidebar-collapsed-spin) {
display: flex;
width: 100%;
flex-direction: column;
align-items: center;
}
:deep(.company-sidebar-collapsed-spin .ant-spin-container) {
display: flex;
width: 100%;
flex-direction: column;
align-items: center;
}
</style>
@@ -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>
@@ -4,17 +4,11 @@ import type { PermissionVO } from '#/api/sys/permission/types';
import { computed, onMounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import {
Button,
Card,
Empty,
Flex,
Input,
message,
Select,
Space,
Spin,
Tag,
@@ -25,13 +19,11 @@ import {
batchUpdateCompanyPermissionsApi,
getCompanyPermissionIdsApi,
} from '#/api/company/permission/apis';
import { getCompanyPageApi } from '#/api/company';
import { getPermissionTreeApi } from '#/api/sys/permission';
import CompanyColPage from '#/views/company/components/CompanyColPage.vue';
defineOptions({ name: 'CompanyPermissionManagePage' });
const BuildingIcon = createIconifyIcon('lucide:building-2');
type PermissionTreeNode = {
key: number;
title: string;
@@ -40,15 +32,7 @@ type PermissionTreeNode = {
children?: PermissionTreeNode[];
};
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 permissionTree = ref<PermissionVO.PermissionInfoVO[]>([]);
@@ -57,13 +41,6 @@ const companyPermissionIds = ref<number[]>([]);
const selectedPermissionIds = ref<number[]>([]);
const expandedKeys = ref<number[]>([]);
const selectedCompanyLabel = computed(() => {
if (!currentCompany.value) {
return '请先选择公司';
}
return currentCompany.value.name;
});
const permissionTreeData = computed(() =>
mapPermissionToTreeData(permissionTree.value),
);
@@ -118,29 +95,10 @@ function collectExpandableKeys(nodes: PermissionVO.PermissionInfoVO[]): number[]
return keys;
}
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 loadCompanyPermissions();
selectedCompanyId.value = company.id;
void loadCompanyPermissions();
}
async function loadCompanyPermissions() {
@@ -191,31 +149,6 @@ async function handleSave() {
}
}
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);
}
function countLeafPermissions(nodes: PermissionVO.PermissionInfoVO[]): number {
let count = 0;
for (const node of nodes) {
@@ -246,237 +179,101 @@ function selectNone() {
}
onMounted(() => {
searchCompanies();
loadPermissionTree();
void loadPermissionTree();
});
</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">
全部叶子权限 {{ stats.total }} · 已配置
<strong class="text-green-600">{{ stats.company }}</strong> · 当前选择
<span class="text-xs text-muted-foreground">
叶子权限 {{ stats.total }} · 已配置
<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="permissionLoading">
<Tree
v-if="permissionTreeData.length > 0"
v-model:checked-keys="selectedPermissionIds"
v-model:expanded-keys="expandedKeys"
:tree-data="permissionTreeData"
checkable
block-node
:selectable="false"
@check="handleTreeCheckChange"
>
<template #title="{ title, code, type }">
<div class="flex min-w-0 items-center gap-2">
<span class="min-w-0 truncate font-medium">{{ title }}</span>
<span
v-if="code"
class="shrink-0 text-xs text-muted-foreground"
>
{{ code }}
</span>
<Tag
v-if="type === 'module'"
color="purple"
class="m-0 shrink-0"
>
模块
</Tag>
</div>
</template>
</Tree>
<Empty
v-else-if="!permissionLoading"
class="py-8"
description="暂无可分配的权限"
/>
</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="permissionLoading">
<Tree
v-if="permissionTreeData.length > 0"
v-model:checked-keys="selectedPermissionIds"
v-model:expanded-keys="expandedKeys"
:tree-data="permissionTreeData"
checkable
block-node
:selectable="false"
@check="handleTreeCheckChange"
>
<template #title="{ title, code, type }">
<div class="flex min-w-0 items-center gap-2">
<span class="min-w-0 truncate font-medium">{{ title }}</span>
<span
v-if="code"
class="shrink-0 text-xs text-muted-foreground"
>
{{ code }}
</span>
<Tag
v-if="type === 'module'"
color="purple"
class="m-0 shrink-0"
>
模块
</Tag>
</div>
</template>
</Tree>
<Empty
v-else-if="!permissionLoading"
class="py-8"
description="暂无可分配的权限"
/>
</Spin>
</div>
</Card>
</CompanyColPage>
</template>