优化
This commit is contained in:
@@ -5,21 +5,30 @@ import {
|
||||
ClipboardList,
|
||||
KeyRound,
|
||||
LayoutGrid,
|
||||
Package,
|
||||
PlaneTakeoff,
|
||||
ReceiptText,
|
||||
Settings,
|
||||
Ship,
|
||||
ShieldCheck,
|
||||
Tags,
|
||||
Truck,
|
||||
Users,
|
||||
Warehouse,
|
||||
Zap,
|
||||
} from '@lucide/vue'
|
||||
|
||||
export interface ClientNavigationBaseNode {
|
||||
key: string
|
||||
title: string
|
||||
icon: Component
|
||||
dividerBefore?: boolean
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export interface ClientNavigationLeaf extends ClientNavigationBaseNode {
|
||||
path: string
|
||||
permission: string
|
||||
permission?: string
|
||||
children?: never
|
||||
}
|
||||
|
||||
@@ -33,19 +42,60 @@ export type ClientNavigationNode = ClientNavigationLeaf | ClientNavigationGroup
|
||||
|
||||
export const clientNavigation: ClientNavigationNode[] = [
|
||||
{ key: 'dashboard', title: '业务总览', icon: LayoutGrid, path: '/', permission: 'dashboard:view' },
|
||||
{ key: 'account-profile', title: '我的信息', icon: CircleUserRound, path: '/account/profile', permission: 'account:profile:view' },
|
||||
{
|
||||
key: 'first-leg',
|
||||
title: '头程业务',
|
||||
title: '头程物流',
|
||||
icon: Truck,
|
||||
children: [
|
||||
{ key: 'first-leg-orders', title: '头程订单', icon: ClipboardList, path: '/orders/first-leg', permission: 'order:first-leg:list' },
|
||||
{ key: 'first-leg-orders', title: '头程下单', icon: ClipboardList, path: '/orders/first-leg', permission: 'order:first-leg:list' },
|
||||
{ key: 'first-leg-import', title: '一键导入', icon: Package, path: '/first-leg/import' },
|
||||
{ key: 'first-leg-quick-order', title: '快速下单', icon: Zap, path: '/first-leg/quick-order' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'cross-border',
|
||||
title: '出海下单',
|
||||
icon: PlaneTakeoff,
|
||||
children: [
|
||||
{ key: 'cross-border-procurement', title: '海外采购', icon: Package, path: '/cross-border/procurement' },
|
||||
{ key: 'cross-border-domestic-trucking', title: '美国本土卡', icon: Truck, path: '/cross-border/domestic-trucking' },
|
||||
{ key: 'cross-border-pallet-shipping', title: '美本土散板', icon: Ship, path: '/cross-border/pallet-shipping' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'overseas-warehouse',
|
||||
title: '海外仓',
|
||||
icon: Warehouse,
|
||||
children: [
|
||||
{ key: 'overseas-labeling', title: '贴标申请', icon: Tags, path: '/overseas-warehouse/labeling' },
|
||||
{ key: 'overseas-return-inbound', title: '退货入库', icon: Package, path: '/overseas-warehouse/return-inbound' },
|
||||
{ key: 'overseas-return-relabel', title: '退货换标', icon: Tags, path: '/overseas-warehouse/return-relabel' },
|
||||
{ key: 'overseas-return-outbound', title: '退货出库', icon: Truck, path: '/overseas-warehouse/return-outbound' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'order-management',
|
||||
title: '订单管理',
|
||||
icon: ClipboardList,
|
||||
children: [
|
||||
{ key: 'orders-my', title: '我的订单', icon: ReceiptText, path: '/orders/my' },
|
||||
{ key: 'orders-inbound', title: '入库订单列表', icon: Package, path: '/orders/inbound' },
|
||||
{ key: 'orders-delivery', title: '派送订单列表', icon: Truck, path: '/orders/delivery' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'finance',
|
||||
title: '财务结算',
|
||||
icon: ReceiptText,
|
||||
children: [
|
||||
{ key: 'finance-payables', title: '应付账单', icon: ReceiptText, path: '/finance/payables' },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'company',
|
||||
title: '企业管理',
|
||||
icon: Settings,
|
||||
dividerBefore: true,
|
||||
children: [
|
||||
{ key: 'company-profile', title: '企业资料', icon: Building2, path: '/company/profile', permission: 'company:profile:view' },
|
||||
{ key: 'company-members', title: '企业成员', icon: Users, path: '/organization/members', permission: 'company:member:list' },
|
||||
@@ -53,6 +103,7 @@ export const clientNavigation: ClientNavigationNode[] = [
|
||||
{ key: 'company-permissions', title: '菜单权限', icon: KeyRound, path: '/organization/permissions', permission: 'company:permission:list' },
|
||||
],
|
||||
},
|
||||
{ key: 'account-profile', title: '我的信息', icon: CircleUserRound, path: '/account/profile', permission: 'account:profile:view' },
|
||||
]
|
||||
|
||||
function isNavigationGroup(node: ClientNavigationNode): node is ClientNavigationGroup {
|
||||
@@ -73,8 +124,9 @@ export function filterNavigationByPermissions(
|
||||
const allowed = new Set(permissions)
|
||||
const result: ClientNavigationNode[] = []
|
||||
for (const node of nodes) {
|
||||
if (node.hidden) continue
|
||||
if (!isNavigationGroup(node)) {
|
||||
if (allowed.has(node.permission)) result.push(node)
|
||||
if (!node.permission || allowed.has(node.permission)) result.push(node)
|
||||
continue
|
||||
}
|
||||
const children = filterNavigationByPermissions(node.children, permissions)
|
||||
@@ -84,7 +136,7 @@ export function filterNavigationByPermissions(
|
||||
}
|
||||
|
||||
export function getFirstAccessiblePath(permissions: readonly string[]) {
|
||||
return getNavigationLeaves(filterNavigationByPermissions(clientNavigation, permissions))[0]?.path ?? '/forbidden'
|
||||
return getNavigationLeaves(filterNavigationByPermissions(clientNavigation, permissions)).find((leaf) => leaf.permission)?.path ?? '/forbidden'
|
||||
}
|
||||
|
||||
function findNavigationParentKeys(
|
||||
|
||||
Reference in New Issue
Block a user