5463a0c772
- 冲突以 weiyuan 功能(小程序登录、i18n 文案)为准,并保留远端 lint 重构与依赖收敛 - 删除 weiyuan 已移除、远端仅做 lint 修正的 3 个图片相关文件 - 适配远端零警告 ESLint:Monitoring/Subscription 改用 useEffectEvent,EditChannelModal 注明 t 依赖 - effect-events 单测补充 react-i18next mock - 对合并后仍不符合 Prettier 的文件做纯格式化
227 lines
7.4 KiB
React
227 lines
7.4 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, { useEffect, useMemo, useState } from 'react';
|
||
import i18next from 'i18next';
|
||
|
||
// 读品牌值:localStorage → window.__WL_BRAND__(index.html 内联脚本写入)→ 空。
|
||
// 不用 getSystemName/getLogo —— 它们的终极兜底是 'Weelinking' / '/logo.svg'(老品牌),
|
||
// 这里要严格白牌,宁可让旋转环单独转,也不能露出老标识。
|
||
// 接 window 一层是为了和首屏 splash 对齐:冷启动 + 用户立刻进了懒路由的窗口期,
|
||
// localStorage 还没被 /api/status 灌满,但 window 已有后端启动注入的品牌。
|
||
const readBrand = (key, windowKey) => {
|
||
try {
|
||
const v = localStorage.getItem(key);
|
||
if (v && v !== 'undefined' && v !== 'null') return v;
|
||
} catch {
|
||
/* 隐私模式:fall through */
|
||
}
|
||
if (typeof window !== 'undefined' && window.__WL_BRAND__) {
|
||
return window.__WL_BRAND__[windowKey] || '';
|
||
}
|
||
return '';
|
||
};
|
||
|
||
// 加载文案根据浏览器语言决定,避免 i18n 还没初始化时硬编码中文。
|
||
const getLoadingText = () => {
|
||
if (i18next.isInitialized) return i18next.t('加载中...');
|
||
const lang = (
|
||
(typeof navigator !== 'undefined' && navigator.language) ||
|
||
'zh'
|
||
).toLowerCase();
|
||
return lang.startsWith('zh') ? '加载中...' : 'Loading...';
|
||
};
|
||
|
||
const Loading = () => {
|
||
const systemName = readBrand('system_name', 'name');
|
||
const logo = readBrand('logo', 'logo');
|
||
const [logoFailed, setLogoFailed] = useState(false);
|
||
// 防御性:同实例内 logo URL 变化(罕见,但 /api/status 在同一 Loading 生命周期内回来时可能发生),
|
||
// 重置失败标志,避免新 URL 也被错判成"已坏"
|
||
useEffect(() => {
|
||
setLogoFailed(false);
|
||
}, [logo]);
|
||
|
||
const loadingText = useMemo(getLoadingText, []);
|
||
const monogram = useMemo(() => {
|
||
const s = systemName.trim();
|
||
return s ? Array.from(s)[0].toUpperCase() : '';
|
||
}, [systemName]);
|
||
|
||
const showImg = logo && !logoFailed;
|
||
// 没 logo 也没名字:旋转环里留空,避免出现"空着的渐变色方块"
|
||
const showMono = !showImg && monogram;
|
||
|
||
return (
|
||
<div className='wl-page-loading'>
|
||
<div className='wl-page-box'>
|
||
<div className='wl-page-logo-ring'>
|
||
<span className='wl-page-logo-slot'>
|
||
{showImg && (
|
||
<img
|
||
className='wl-page-logo'
|
||
src={logo}
|
||
alt={systemName || 'logo'}
|
||
onError={() => setLogoFailed(true)}
|
||
/>
|
||
)}
|
||
{showMono && <span className='wl-page-mono'>{monogram}</span>}
|
||
</span>
|
||
</div>
|
||
{systemName && <div className='wl-page-brand'>{systemName}</div>}
|
||
<div className='wl-page-text'>{loadingText}</div>
|
||
</div>
|
||
|
||
<style>{`
|
||
.wl-page-loading {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
align-items: center;
|
||
height: 100vh;
|
||
width: 100%;
|
||
background: #fafbfc;
|
||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||
user-select: none;
|
||
overflow: hidden;
|
||
position: relative;
|
||
}
|
||
.wl-page-loading::before {
|
||
content: '';
|
||
position: absolute;
|
||
width: 420px;
|
||
height: 420px;
|
||
border-radius: 50%;
|
||
background: radial-gradient(
|
||
circle,
|
||
var(--brand-primary-soft, rgba(99, 102, 241, 0.12)),
|
||
transparent 70%
|
||
);
|
||
filter: blur(24px);
|
||
pointer-events: none;
|
||
}
|
||
.wl-page-box {
|
||
position: relative;
|
||
z-index: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
animation: wl-page-fade 0.5s ease-out both;
|
||
}
|
||
@keyframes wl-page-fade {
|
||
from { opacity: 0; transform: translateY(12px); }
|
||
to { opacity: 1; transform: translateY(0); }
|
||
}
|
||
.wl-page-logo-ring {
|
||
position: relative;
|
||
width: 84px;
|
||
height: 84px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
margin-bottom: 22px;
|
||
}
|
||
.wl-page-logo-ring::before {
|
||
content: '';
|
||
position: absolute;
|
||
inset: 0;
|
||
border-radius: 50%;
|
||
border: 3px solid var(--brand-primary-soft, rgba(22, 104, 220, 0.16));
|
||
border-top-color: var(--brand-primary, #1668dc);
|
||
animation: wl-page-spin 0.9s linear infinite;
|
||
}
|
||
@keyframes wl-page-spin {
|
||
to { transform: rotate(360deg); }
|
||
}
|
||
.wl-page-logo-slot {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 56px;
|
||
height: 56px;
|
||
}
|
||
.wl-page-logo {
|
||
width: 56px;
|
||
height: 56px;
|
||
border-radius: 14px;
|
||
object-fit: cover;
|
||
display: block;
|
||
}
|
||
.wl-page-mono {
|
||
width: 56px;
|
||
height: 56px;
|
||
border-radius: 14px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 26px;
|
||
font-weight: 700;
|
||
color: #fff;
|
||
background: linear-gradient(
|
||
135deg,
|
||
var(--brand-gradient-from, #4096ff),
|
||
var(--brand-gradient-to, #0958d9)
|
||
);
|
||
}
|
||
.wl-page-brand {
|
||
font-size: 20px;
|
||
font-weight: 700;
|
||
letter-spacing: 1px;
|
||
color: var(--brand-primary, #1668dc);
|
||
margin-bottom: 14px;
|
||
min-height: 24px;
|
||
}
|
||
.wl-page-text {
|
||
font-size: 13px;
|
||
color: #94a3b8;
|
||
letter-spacing: 0.5px;
|
||
animation: wl-page-blink 1.6s ease-in-out infinite;
|
||
}
|
||
@keyframes wl-page-blink {
|
||
0%, 100% { opacity: 0.45; }
|
||
50% { opacity: 1; }
|
||
}
|
||
@media (prefers-color-scheme: dark) {
|
||
.wl-page-loading { background: #0f1115; }
|
||
.wl-page-text { color: #64748b; }
|
||
}
|
||
html.dark .wl-page-loading,
|
||
body[theme-mode='dark'] .wl-page-loading { background: #0f1115; }
|
||
html.dark .wl-page-text,
|
||
body[theme-mode='dark'] .wl-page-text { color: #64748b; }
|
||
|
||
/* 无障碍:尊重系统"减少动效"偏好 */
|
||
@media (prefers-reduced-motion: reduce) {
|
||
.wl-page-logo-ring::before,
|
||
.wl-page-box,
|
||
.wl-page-text {
|
||
animation: none !important;
|
||
}
|
||
.wl-page-logo-ring::before {
|
||
border-color: var(--brand-primary, #1668dc);
|
||
opacity: 0.6;
|
||
}
|
||
.wl-page-text { opacity: 0.75; }
|
||
}
|
||
`}</style>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default Loading;
|