AdminShell.tsx
6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { useState } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import { RobotIcon, SettingIcon, UsergroupIcon } from 'tdesign-icons-react';
import {
BusinessAdminShell,
type BusinessAdminShellBreadcrumbItem,
type BusinessAdminShellMenuItem,
} from '@gl/business-components';
import { Dialog } from 'tdesign-react';
import { logout } from '../auth/localAuth';
const navigationItems: BusinessAdminShellMenuItem[] = [
{
key: 'agent-management',
label: 'Agent管理',
icon: <RobotIcon />,
children: [
{ key: 'agent-list', label: 'Agent列表' },
{ key: 'agent-tag-list', label: '岗位标签管理' },
{ key: 'skill-list', label: 'Skill目录' },
],
},
{
key: 'agent-group-management',
label: 'Agent群管理',
icon: <UsergroupIcon />,
children: [{ key: 'channel-code-list', label: '渠道活码' }],
},
{
key: 'official-site-management',
label: '官网配置',
icon: <SettingIcon />,
children: [
{ key: 'official-site-job-tabs', label: '岗位展示配置' },
{ key: 'official-site-methodology', label: '方法论展示配置' },
],
},
];
const routeByMenuKey: Record<string, string> = {
'agent-list': '/agents',
'agent-tag-list': '/agent-tags',
'skill-list': '/skills',
'channel-code-list': '/channel-codes',
'official-site-methodology': '/official-site/methodology',
'official-site-job-tabs': '/official-site/job-tabs',
};
export function AdminShell() {
const location = useLocation();
const navigate = useNavigate();
const [logoutConfirmOpen, setLogoutConfirmOpen] = useState(false);
const activeNavigationKey = location.pathname.startsWith('/skills')
? 'skill-list'
: location.pathname.startsWith('/agent-tags')
? 'agent-tag-list'
: location.pathname.startsWith('/official-site/methodology')
? 'official-site-methodology'
: location.pathname.startsWith('/official-site/job-tabs')
? 'official-site-job-tabs'
: location.pathname.startsWith('/agents')
? 'agent-list'
: location.pathname.startsWith('/channel-codes')
? 'channel-code-list'
: undefined;
const expandedMenuKeys = navigationItems
.filter((item) => item.children?.some((child) => child.key === activeNavigationKey))
.map((item) => item.key);
const makeMenuBreadcrumb = (
parentLabel: string,
childLabel: string,
childPath: string,
independentPageName?: string,
): BusinessAdminShellBreadcrumbItem[] => {
const items: BusinessAdminShellBreadcrumbItem[] = [
{ key: 'parent', label: parentLabel },
{
key: 'child',
label: childLabel,
onClick: independentPageName ? () => navigate(childPath) : undefined,
},
];
if (independentPageName) {
items.push({ key: 'independent-page', label: independentPageName });
}
return items;
};
const breadcrumbItems = location.pathname.startsWith('/skills')
? makeMenuBreadcrumb('Agent管理', 'Skill目录', '/skills')
: location.pathname.startsWith('/agent-tags/new')
? makeMenuBreadcrumb('Agent管理', '岗位标签管理', '/agent-tags', '新增岗位标签')
: location.pathname.startsWith('/agent-tags/') && location.pathname.endsWith('/edit')
? makeMenuBreadcrumb('Agent管理', '岗位标签管理', '/agent-tags', '编辑岗位标签')
: location.pathname.startsWith('/agent-tags')
? makeMenuBreadcrumb('Agent管理', '岗位标签管理', '/agent-tags')
: location.pathname.startsWith('/official-site/methodology')
? makeMenuBreadcrumb('官网配置', '方法论展示配置', '/official-site/methodology')
: location.pathname.startsWith('/official-site/job-tabs/new')
? makeMenuBreadcrumb('官网配置', '岗位展示配置', '/official-site/job-tabs', '新增岗位展示')
: location.pathname.startsWith('/official-site/job-tabs/') && location.pathname.endsWith('/edit')
? makeMenuBreadcrumb('官网配置', '岗位展示配置', '/official-site/job-tabs', '编辑岗位展示')
: location.pathname.startsWith('/official-site/job-tabs/') && location.pathname.endsWith('/agents')
? makeMenuBreadcrumb('官网配置', '岗位展示配置', '/official-site/job-tabs', '展示Agent配置')
: location.pathname.startsWith('/official-site/job-tabs')
? makeMenuBreadcrumb('官网配置', '岗位展示配置', '/official-site/job-tabs')
: location.pathname.startsWith('/channel-codes/new')
? makeMenuBreadcrumb('Agent群管理', '渠道活码', '/channel-codes', '新增渠道活码')
: location.pathname.startsWith('/channel-codes/') && location.pathname.endsWith('/edit')
? makeMenuBreadcrumb('Agent群管理', '渠道活码', '/channel-codes', '编辑渠道活码')
: location.pathname.startsWith('/channel-codes')
? makeMenuBreadcrumb('Agent群管理', '渠道活码', '/channel-codes')
: location.pathname.startsWith('/agents/new')
? makeMenuBreadcrumb('Agent管理', 'Agent列表', '/agents', '新增Agent')
: location.pathname.startsWith('/agents/') && location.pathname.endsWith('/edit')
? makeMenuBreadcrumb('Agent管理', 'Agent列表', '/agents', '编辑Agent')
: makeMenuBreadcrumb('Agent管理', 'Agent列表', '/agents');
return (
<BusinessAdminShell
systemName="岗位Agent管理后台"
menuItems={navigationItems}
activeMenuKey={activeNavigationKey}
expandedMenuKeys={expandedMenuKeys}
breadcrumbItems={breadcrumbItems}
user={{ name: '管理员' }}
onMenuChange={(key) => {
const nextRoute = routeByMenuKey[key];
if (nextRoute) navigate(nextRoute);
}}
onLogout={() => setLogoutConfirmOpen(true)}
>
<Outlet />
<Dialog
visible={logoutConfirmOpen}
header="确认退出登录?"
cancelBtn="取消"
confirmBtn="确定"
destroyOnClose
onClose={() => setLogoutConfirmOpen(false)}
onConfirm={() => {
setLogoutConfirmOpen(false);
logout();
navigate('/login', { replace: true, state: { from: location } });
}}
>
<p className="m-0 text-sm leading-[var(--gl-line-height-md)] text-[var(--gl-color-text-secondary)]">
退出后将返回登录页,当前后台操作上下文不会保留。
</p>
</Dialog>
</BusinessAdminShell>
);
}