refactor: 电商平台规格+市场语言改由 API 下发 (AGENTS.md 规则4完全合规)
This commit is contained in:
+38
-13
@@ -20,6 +20,7 @@ import { toast } from "./components/toast/toastStore";
|
||||
import { flushPendingGenerationRecords } from "./api/generationRecordClient";
|
||||
import { keyServerClient } from "./api/keyServerClient";
|
||||
import { preloadPublicConfig, getLogoUrl } from "./api/publicConfigClient";
|
||||
import { preloadPlatformRules } from "./api/platformRulesClient";
|
||||
import { setUserMaxConcurrency } from "./api/generationConcurrency";
|
||||
import {
|
||||
SERVER_SESSION_EXPIRED_EVENT,
|
||||
@@ -156,6 +157,9 @@ function App() {
|
||||
const [sessionNotice, setSessionNotice] = useState<string | null>(null);
|
||||
const [profileMenuOpen, setProfileMenuOpen] = useState(false);
|
||||
const [currentPage, setCurrentPage] = useState<"workspace" | "profile">("workspace");
|
||||
// 平台规则 gating:数据就绪(或兜底超时)后才渲染 EcommercePage,
|
||||
// 保证其模块求值时 platformRulesClient 缓存已填充,拿到 API 数据。
|
||||
const [platformRulesReady, setPlatformRulesReady] = useState(false);
|
||||
const [workspaceChrome, setWorkspaceChrome] = useState<WorkspaceChromeState>({
|
||||
isToolPage: false,
|
||||
});
|
||||
@@ -184,6 +188,20 @@ function App() {
|
||||
initNotificationPermission();
|
||||
}, []);
|
||||
|
||||
// 启动 gating:预加载平台规则。preload 自带超时+fallback 一定会 resolve;
|
||||
// 另加 3s 兜底,避免极端情况下首屏久等(兜底放行后用 fallback,数据=正确值)。
|
||||
useEffect(() => {
|
||||
let settled = false;
|
||||
const markReady = () => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
setPlatformRulesReady(true);
|
||||
};
|
||||
void preloadPlatformRules().then(markReady, markReady);
|
||||
const fallbackTimer = window.setTimeout(markReady, 3_000);
|
||||
return () => window.clearTimeout(fallbackTimer);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!session) return;
|
||||
void flushPendingGenerationRecords();
|
||||
@@ -381,19 +399,26 @@ function App() {
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<EcommercePage
|
||||
projects={[]}
|
||||
isAuthenticated={Boolean(session)}
|
||||
onWorkspaceChromeChange={setWorkspaceChrome}
|
||||
onStartCreate={() => undefined}
|
||||
onOpenProject={() => undefined}
|
||||
onDeleteProject={() => undefined}
|
||||
onImportWorkflow={() => undefined}
|
||||
onCreateTask={() => undefined}
|
||||
onRequireLogin={() => openAuth("login")}
|
||||
initialTemplate={null}
|
||||
onInitialTemplateConsumed={() => undefined}
|
||||
/>
|
||||
{platformRulesReady ? (
|
||||
<EcommercePage
|
||||
projects={[]}
|
||||
isAuthenticated={Boolean(session)}
|
||||
onWorkspaceChromeChange={setWorkspaceChrome}
|
||||
onStartCreate={() => undefined}
|
||||
onOpenProject={() => undefined}
|
||||
onDeleteProject={() => undefined}
|
||||
onImportWorkflow={() => undefined}
|
||||
onCreateTask={() => undefined}
|
||||
onRequireLogin={() => openAuth("login")}
|
||||
initialTemplate={null}
|
||||
onInitialTemplateConsumed={() => undefined}
|
||||
/>
|
||||
) : (
|
||||
<div className="page-loading-center">
|
||||
<div className="page-loading-spinner" />
|
||||
<span className="page-loading-center__text">加载中...</span>
|
||||
</div>
|
||||
)}
|
||||
</Suspense>
|
||||
</ErrorBoundary>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user