67 lines
2.2 KiB
React
67 lines
2.2 KiB
React
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
import React, { Suspense, lazy, useContext } from 'react';
|
|
import { StatusContext } from '../../../context/Status';
|
|
|
|
/**
|
|
* 登录/注册页背景动画 —— 主题注册表
|
|
*
|
|
* 主题由后端 option「AuthBackgroundTheme」控制,经 /api/status 的
|
|
* auth_background_theme 字段下发。未配置 / 配置非法时兜底 ocean,
|
|
* 保证老部署行为不变。每个主题懒加载,未选中的不进首屏 bundle。
|
|
*/
|
|
const THEMES = {
|
|
ocean: lazy(() => import('../OceanBackground')),
|
|
'token-factory': lazy(() => import('./themes/TokenFactory')),
|
|
'token-factory-cinematic': lazy(
|
|
() => import('./themes/CinematicTokenFactory'),
|
|
),
|
|
};
|
|
|
|
// status 尚未拉取完成时,用 localStorage 缓存的上一次 status 兜底,
|
|
// 避免回头客先黑屏再闪入动画。
|
|
const readCachedTheme = () => {
|
|
try {
|
|
const s = JSON.parse(localStorage.getItem('status') || '{}');
|
|
return s?.auth_background_theme;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
};
|
|
|
|
const AuthBackground = () => {
|
|
const [statusState] = useContext(StatusContext);
|
|
const theme =
|
|
statusState?.status?.auth_background_theme ?? readCachedTheme() ?? 'ocean';
|
|
|
|
if (theme === 'none') return null;
|
|
// hasOwnProperty 守卫:防止 "constructor" 之类的原型链键名取出非组件值导致渲染崩溃
|
|
const ThemeComponent = Object.prototype.hasOwnProperty.call(THEMES, theme)
|
|
? THEMES[theme]
|
|
: THEMES.ocean;
|
|
|
|
return (
|
|
<Suspense fallback={null}>
|
|
<ThemeComponent />
|
|
</Suspense>
|
|
);
|
|
};
|
|
|
|
export default AuthBackground;
|