完善:质量分析平台查询与分析功能
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
Dropdown,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Spin,
|
||||
Tooltip,
|
||||
@@ -15,19 +14,15 @@ import {
|
||||
AppstoreOutlined,
|
||||
ApartmentOutlined,
|
||||
BgColorsOutlined,
|
||||
CheckSquareOutlined,
|
||||
CheckOutlined,
|
||||
DatabaseOutlined,
|
||||
DownOutlined,
|
||||
DeploymentUnitOutlined,
|
||||
FileSearchOutlined,
|
||||
KeyOutlined,
|
||||
LineChartOutlined,
|
||||
LoadingOutlined,
|
||||
LogoutOutlined,
|
||||
RobotOutlined,
|
||||
SearchOutlined,
|
||||
QuestionCircleOutlined,
|
||||
SettingOutlined,
|
||||
TeamOutlined,
|
||||
ToolOutlined,
|
||||
@@ -50,8 +45,9 @@ const pageNames: Record<PageKey, string> = {
|
||||
|
||||
const pageFromLocation = (): PageKey => {
|
||||
const key = new URLSearchParams(window.location.search).get('page');
|
||||
if (key === 'headers' || key === 'releases') return 'sources';
|
||||
if (key === 'headers' || key === 'releases' || key === 'imports') return 'sources';
|
||||
if (key === 'scrap') return 'product';
|
||||
if (key === 'basis') return 'overall';
|
||||
return key && key in pageNames ? key as PageKey : 'overall';
|
||||
};
|
||||
|
||||
@@ -83,7 +79,6 @@ const navGroups = [
|
||||
label: '数据中心',
|
||||
items: [
|
||||
['sources', '数据接入', DatabaseOutlined],
|
||||
['imports', '导入与校验', CheckSquareOutlined],
|
||||
] as const,
|
||||
},
|
||||
{
|
||||
@@ -98,11 +93,6 @@ const navGroups = [
|
||||
},
|
||||
];
|
||||
|
||||
const searchablePages: { key: PageKey; label: string }[] = [
|
||||
...navGroups.flatMap(group => group.items.map(([key, label]) => ({ key, label }))),
|
||||
{ key: 'basis', label: pageNames.basis },
|
||||
];
|
||||
|
||||
function shownDepartment(value: string): string {
|
||||
return value === '质量管理部' ? '质量中心' : value;
|
||||
}
|
||||
@@ -122,28 +112,14 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
const [user, setUser] = useState<AuthUser | null>(null);
|
||||
const [sessionLoading, setSessionLoading] = useState(true);
|
||||
const [sessionError, setSessionError] = useState('');
|
||||
const [searchOpen, setSearchOpen] = useState(false);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
const onShortcut = (event: KeyboardEvent) => {
|
||||
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k') {
|
||||
event.preventDefault();
|
||||
setSearchTerm('');
|
||||
setSearchOpen(true);
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', onShortcut);
|
||||
return () => window.removeEventListener('keydown', onShortcut);
|
||||
}, [user]);
|
||||
|
||||
useEffect(() => {
|
||||
const syncFromLocation = () => {
|
||||
const url = new URL(window.location.href);
|
||||
const currentPage = url.searchParams.get('page') || '';
|
||||
if (['headers', 'releases', 'scrap'].includes(currentPage)) {
|
||||
url.searchParams.set('page', currentPage === 'scrap' ? 'product' : 'sources');
|
||||
if (['headers', 'releases', 'scrap', 'basis', 'imports'].includes(currentPage)) {
|
||||
if (currentPage === 'imports') url.searchParams.set('showImportHistory', '1');
|
||||
url.searchParams.set('page', currentPage === 'basis' ? 'overall' : currentPage === 'scrap' ? 'product' : 'sources');
|
||||
window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`);
|
||||
}
|
||||
setPage(pageFromLocation());
|
||||
@@ -175,6 +151,8 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
|
||||
const navigate = (next: PageKey, query?: QueryParams, resultRef?: TopResultRef) => {
|
||||
const url = new URL(window.location.href);
|
||||
if (next === 'imports') { next = 'sources'; url.searchParams.set('showImportHistory', '1'); }
|
||||
else url.searchParams.delete('showImportHistory');
|
||||
url.searchParams.set('page', next);
|
||||
if (next !== 'analysis' || query || resultRef) {
|
||||
url.searchParams.delete('sessionId');
|
||||
@@ -184,14 +162,8 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
else url.searchParams.delete('context');
|
||||
window.history.pushState({}, '', `${url.pathname}${url.search}${url.hash}`);
|
||||
setPage(next);
|
||||
setSearchOpen(false);
|
||||
};
|
||||
|
||||
const matchingPages = searchablePages.filter(({ key, label }) => {
|
||||
const normalized = searchTerm.trim().toLocaleLowerCase();
|
||||
return !normalized || `${label} ${key}`.toLocaleLowerCase().includes(normalized);
|
||||
});
|
||||
|
||||
const handleUnauthorized = useCallback((error: unknown) => {
|
||||
if (error instanceof ApiError && error.status === 401) {
|
||||
setUser(null);
|
||||
@@ -230,12 +202,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
<div className="nav-group nav-group-tail">
|
||||
<div className="nav-group-label">数据口径</div>
|
||||
<button className={`nav-item ${page === 'basis' ? 'active' : ''}`} aria-current={page === 'basis' ? 'page' : undefined} onClick={() => navigate('basis')}>
|
||||
<FileSearchOutlined aria-hidden="true" /><span>数据与计算依据</span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
<div className="user-block">
|
||||
<span className="avatar">{(user.displayName || user.username).slice(0, 1)}</span>
|
||||
@@ -251,9 +217,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
<header className="topbar">
|
||||
<div className="breadcrumb"><span>质量分析</span><span className="breadcrumb-slash">/</span><strong>{pageNames[page]}</strong></div>
|
||||
<div className="topbar-actions">
|
||||
<Button className="topbar-search" type="text" aria-label="搜索功能页面" onClick={() => { setSearchTerm(''); setSearchOpen(true); }}>
|
||||
<SearchOutlined /><span>搜索功能页面…</span><kbd>⌘ K</kbd>
|
||||
</Button>
|
||||
<Dropdown
|
||||
trigger={['click']}
|
||||
classNames={{ root: 'workspace-theme-dropdown' }}
|
||||
@@ -270,9 +233,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
<BgColorsOutlined /><span>{appearance.name}</span><DownOutlined />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
<Tooltip title="查看数据与计算依据">
|
||||
<Button className="topbar-help" type="text" icon={<QuestionCircleOutlined />} aria-label="查看数据与计算依据" onClick={() => navigate('basis')} />
|
||||
</Tooltip>
|
||||
<span className="top-organization"><TeamOutlined />质量中心</span>
|
||||
</div>
|
||||
</header>
|
||||
@@ -280,7 +240,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
<span className="brand-mark" aria-hidden="true"><i /><i /><i /></span><strong>质量中心</strong>
|
||||
<Select<PageKey> {...readableSelectPopup} aria-label="页面导航" value={page} onChange={value => navigate(value)} options={[
|
||||
...navGroups.map(group => ({ label: group.label, options: group.items.map(([value, label]) => ({ value, label })) })),
|
||||
{ label: '数据口径', options: [{ value: 'basis' as PageKey, label: '数据与计算依据' }] },
|
||||
]} />
|
||||
<Button type="text" icon={<LogoutOutlined />} aria-label="退出登录" onClick={async () => {
|
||||
try { await api.logout(); setUser(null); }
|
||||
@@ -297,33 +256,6 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
</Suspense>
|
||||
</div>
|
||||
</main>
|
||||
<Modal
|
||||
className="navigation-search-modal"
|
||||
title="搜索功能页面"
|
||||
open={searchOpen}
|
||||
footer={null}
|
||||
centered
|
||||
width={520}
|
||||
onCancel={() => setSearchOpen(false)}
|
||||
>
|
||||
<Input
|
||||
autoFocus
|
||||
allowClear
|
||||
prefix={<SearchOutlined />}
|
||||
placeholder="输入页面名称"
|
||||
value={searchTerm}
|
||||
onChange={event => setSearchTerm(event.target.value)}
|
||||
onPressEnter={() => matchingPages[0] && navigate(matchingPages[0].key)}
|
||||
/>
|
||||
<div className="navigation-search-results" role="listbox" aria-label="功能页面">
|
||||
{matchingPages.length ? matchingPages.map(item => (
|
||||
<button className="navigation-result" type="button" key={item.key} role="option" aria-selected={page === item.key} onClick={() => navigate(item.key)}>
|
||||
<span>{item.label}</span><kbd>Enter</kbd>
|
||||
</button>
|
||||
)) : <div className="navigation-search-empty">没有匹配的功能页面</div>}
|
||||
</div>
|
||||
<div className="navigation-search-footnote">按 Enter 打开首项,Esc 关闭</div>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user