feat(iframe-bridge): implement iframe communication bridge and language sync
This commit is contained in:
@@ -24,6 +24,8 @@ import { SidebarProvider } from './components/ui/sidebar';
|
||||
import { TooltipProvider } from './components/ui/tooltip';
|
||||
import { ThemeEnum } from './constants/common';
|
||||
import storage from './utils/authorization-util';
|
||||
import Bridge from '@teres/iframe-bridge';
|
||||
import { LanguageAbbreviationMap, LanguageTranslationMap } from './constants/common';
|
||||
|
||||
dayjs.extend(customParseFormat);
|
||||
dayjs.extend(advancedFormat);
|
||||
@@ -99,6 +101,21 @@ const RootProvider = ({ children }: React.PropsWithChildren) => {
|
||||
if (lng) {
|
||||
i18n.changeLanguage(lng);
|
||||
}
|
||||
// 在嵌入模式下,向父应用暴露 changeLanguage 方法以支持跨项目语言同步
|
||||
if (Bridge.isEmbedded()) {
|
||||
Bridge.initChildBridge({
|
||||
methods: {
|
||||
changeLanguage: (nextLng: string) => {
|
||||
// 兼容传入缩写(en/zh/...)或显示名(English/Chinese/...)
|
||||
const isAbbr = !!LanguageAbbreviationMap[nextLng as keyof typeof LanguageAbbreviationMap];
|
||||
const resolved = isAbbr
|
||||
? nextLng
|
||||
: LanguageTranslationMap[nextLng as keyof typeof LanguageTranslationMap] || nextLng;
|
||||
i18n.changeLanguage(resolved);
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
@@ -21,7 +21,7 @@ const ThemeProviderContext = createContext<ThemeProviderState>(initialState);
|
||||
|
||||
export function ThemeProvider({
|
||||
children,
|
||||
defaultTheme = ThemeEnum.Dark,
|
||||
defaultTheme = ThemeEnum.Light,
|
||||
storageKey = 'vite-ui-theme',
|
||||
...props
|
||||
}: ThemeProviderProps) {
|
||||
|
||||
Reference in New Issue
Block a user