优化:缓存查询与智能分析页面,修复组织下钻和草稿保留
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { lazy, Suspense, useCallback, useEffect, useState, type ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
Alert,
|
||||
App,
|
||||
@@ -34,8 +34,7 @@ import { workspaceThemes, type WorkspaceThemeId } from './ui-themes';
|
||||
import { readableSelectPopup } from './readableSelectPopup';
|
||||
import PersonalAccount, { type AccountTab } from './PersonalAccount';
|
||||
|
||||
const QueryPage = lazy(() => import('./QueryPage'));
|
||||
const ManagementPages = lazy(() => import('./ManagementPages'));
|
||||
import { CachedWorkspacePages, type WorkspaceNavigation } from './CachedWorkspacePages';
|
||||
|
||||
export type PageKey = 'overall' | 'department' | 'group' | 'product' | 'basis' | 'analysis' | 'sources' | 'imports' | 'rules' | 'mappings' | 'masterData' | 'tasks' | 'access';
|
||||
|
||||
@@ -99,10 +98,6 @@ function shownDepartment(value: string): string {
|
||||
return value === '质量管理部' ? '质量中心' : value;
|
||||
}
|
||||
|
||||
function PageReveal({ page, children }: { page: PageKey; children: ReactNode }) {
|
||||
return <div className="page-view" data-page={page}>{children}</div>;
|
||||
}
|
||||
|
||||
type QualityWorkspaceProps = {
|
||||
appearance: (typeof workspaceThemes)[number];
|
||||
onAppearanceChange: (themeId: WorkspaceThemeId) => void;
|
||||
@@ -115,6 +110,7 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
const [sessionLoading, setSessionLoading] = useState(true);
|
||||
const [sessionError, setSessionError] = useState('');
|
||||
const [accountTab, setAccountTab] = useState<AccountTab | null>(null);
|
||||
const workspaceNavigation = useRef<WorkspaceNavigation>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const syncFromLocation = () => {
|
||||
@@ -125,7 +121,7 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
url.searchParams.set('page', currentPage === 'basis' ? 'overall' : currentPage === 'scrap' ? 'product' : 'sources');
|
||||
window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`);
|
||||
}
|
||||
setPage(pageFromLocation());
|
||||
if (workspaceNavigation.current) workspaceNavigation.current.syncLocation(); else setPage(pageFromLocation());
|
||||
};
|
||||
syncFromLocation();
|
||||
window.addEventListener('popstate', syncFromLocation);
|
||||
@@ -153,6 +149,7 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
}, []);
|
||||
|
||||
const navigate = (next: PageKey, query?: QueryParams, resultRef?: TopResultRef) => {
|
||||
if (workspaceNavigation.current) { workspaceNavigation.current.navigate(next, query, resultRef); return; }
|
||||
const url = new URL(window.location.href);
|
||||
if (next === 'imports') { next = 'sources'; url.searchParams.set('showImportHistory', '1'); }
|
||||
else url.searchParams.delete('showImportHistory');
|
||||
@@ -259,13 +256,7 @@ export default function QualityWorkspace({ appearance, onAppearanceChange }: Qua
|
||||
<Button type="text" icon={<UserOutlined />} aria-label="打开个人账户" onClick={() => setAccountTab('profile')} />
|
||||
</div>
|
||||
<div className="page-content">
|
||||
<Suspense fallback={<div className="loading-panel"><Spin />正在打开页面…</div>}>
|
||||
<PageReveal page={page}>
|
||||
{['overall', 'department', 'group', 'product'].includes(page)
|
||||
? <QueryPage page={page} onUnauthorized={handleUnauthorized} onNavigate={navigate} />
|
||||
: <ManagementPages page={page} user={user} onUnauthorized={handleUnauthorized} onNavigate={navigate} />}
|
||||
</PageReveal>
|
||||
</Suspense>
|
||||
<CachedWorkspacePages ref={workspaceNavigation} page={page} user={user} onPageChange={setPage} onUserChange={setUser} onUnauthorized={handleUnauthorized} />
|
||||
</div>
|
||||
</main>
|
||||
<PersonalAccount user={user} tab={accountTab} onClose={() => setAccountTab(null)} onUserChange={setUser}
|
||||
|
||||
Reference in New Issue
Block a user