轻应用主题参数:随当前主题色映射传值

- 主题参数改为按系统主题(red/dark-blue)映射取目标应用对应的值
- 应用管理弹窗用结构化映射编辑器(逐主题色配置目标值,默认同名)
- iframe 嵌套显式传入当前主题色,切主题时 src 重建
- 读取/保存时规范化映射串;解析支持 light/dark 等别名,取不到回退主题色名而非恒为 red

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
fengxiangdebaoziandClaude Opus 4.8 committed 2026-06-12 22:30:31 +08:00
1 parent a7596001c5
commit 74324f4585
4 files changed
+41 -12

No files matched your search

@@ -9,7 +9,7 @@ import { useParams } from "react-router-dom";
import { useTheme } from "@/contexts/ThemeContext";
import { useLightApp } from "@/strategy-components/api/light-apps";
import { buildLightAppUrl } from "@/strategy-components/lib/light-app";
import { buildLightAppUrl, type AppThemeColor } from "@/strategy-components/lib/light-app";
export default function LightAppIframeView() {
const { appId } = useParams<{ appId: string }>();
@@ -17,8 +17,14 @@ export default function LightAppIframeView() {
const isDark = theme === "dark";
const { data: app, isLoading, error } = useLightApp(appId);
// 依赖 theme:切换主题色时重建 src,把对应主题色重新传给被嵌套应用。
const src = useMemo(() => (app ? buildLightAppUrl(app) : ""), [app, theme]);
// 由 useTheme 的 theme 直接换算主题色并显式传入,切主题时 src 立即重建、
// 把新主题色传给被嵌套应用(不依赖 <html> 的 dark class,避免时序读旧值)。
// TODO: 后续接入 blue 主题后,这里区分 blue 与 dark-blue。
const themeColor: AppThemeColor = isDark ? "dark-blue" : "red";
const src = useMemo(
() => (app ? buildLightAppUrl(app, undefined, themeColor) : ""),
[app, themeColor],
);
const centerClass = `flex h-full w-full items-center justify-center text-sm ${
isDark ? "text-slate-400" : "text-slate-500"
@@ -707,8 +707,8 @@ function cleanParams(params: LightAppRouteParam[]): LightAppRouteParam[] {
base.customValue = (p.customValue ?? "").trim();
}
} else {
// theme:存映射串(或纯值),运行时按当前主题解析取值
base.themeValue = (p.themeValue ?? "").trim();
// theme:规范化为完整映射串(red=..;blue=..;dark-blue=..),运行时按当前主题取值
base.themeValue = stringifyThemeMap(parseThemeMap(p.themeValue));
}
return base;
});