Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
// 进入 WeyAi 的过渡画面。授权页在三个瞬态里没有任何可操作内容:拉授权信息、
|
||||
// 静默签发、授权完成等浏览器跳走。原来这三态套在登录卡片里只放一个 Spin,
|
||||
// 而登录页背景主题是按需懒加载的 chunk,这个页面通常在 chunk 到达前就跳走了,
|
||||
// 用户看到的是"空白底 + 小转圈"。这里改为:同步渲染的 token 派生背景
|
||||
// (PageBackground,随主题预设与亮暗自动变化)+ 品牌环形加载动画 + 三步
|
||||
// 真实进度(按 phase 推进,不是假进度条)。
|
||||
//
|
||||
// 跳转卡住的兜底:授权完成后浏览器应当立刻跳走,若数秒后还停在这里(弹窗
|
||||
// 拦截、location.replace 被扩展拦下),显示手动入口,用户不至于干等。手动
|
||||
// 入口是**重新走一遍授权**(整页刷新),不是再打一次回跳地址:回跳地址里的
|
||||
// code 只能核销一次,若第一次跳转其实已经到达网关只是慢,再打一次会让网关
|
||||
// 拿着已核销的 code 报错,反而把本来会成功的登录弄坏。刷新会重新拉上下文、
|
||||
// 静默签发新 code,无论第一次是没发出去还是发出去了都能收敛。
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check } from 'lucide-react';
|
||||
import PageBackground from '../../components/common/PageBackground';
|
||||
import './WeyAiHandoff.css';
|
||||
|
||||
// 授权完成后等多久还没跳走就露出手动入口。网关换 token 正常在 1 秒内,
|
||||
// 8 秒仍未离开这一页基本可以断定跳转没发出去
|
||||
const MANUAL_RETRY_DELAY_MS = 8000;
|
||||
|
||||
export const HANDOFF_STAGE_LOADING = 0;
|
||||
export const HANDOFF_STAGE_ISSUING = 1;
|
||||
export const HANDOFF_STAGE_REDIRECT = 2;
|
||||
|
||||
export default function WeyAiHandoff({
|
||||
logo,
|
||||
stage,
|
||||
title,
|
||||
subtitle,
|
||||
clientName = 'WeyAi',
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [showManual, setShowManual] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (stage !== HANDOFF_STAGE_REDIRECT) {
|
||||
setShowManual(false);
|
||||
return undefined;
|
||||
}
|
||||
const timer = setTimeout(() => setShowManual(true), MANUAL_RETRY_DELAY_MS);
|
||||
return () => clearTimeout(timer);
|
||||
}, [stage]);
|
||||
|
||||
const steps = [
|
||||
t('验证账号'),
|
||||
t('建立安全会话'),
|
||||
t('打开 {{name}}', { name: clientName }),
|
||||
];
|
||||
|
||||
return (
|
||||
<div
|
||||
className='weyai-handoff relative overflow-hidden flex items-center justify-center px-4 sm:px-6 lg:px-8'
|
||||
style={{ minHeight: 'calc(100vh - var(--content-top-offset, 0px))' }}
|
||||
>
|
||||
<PageBackground variant='rich' grid animate />
|
||||
{/* 居中光晕:把视线聚到徽标上,颜色随品牌色 */}
|
||||
<div className='weyai-handoff__halo' aria-hidden='true' />
|
||||
|
||||
<div className='weyai-handoff__panel relative z-10'>
|
||||
<div className='weyai-handoff__emblem' aria-hidden='true'>
|
||||
<span className='weyai-handoff__pulse' />
|
||||
<span className='weyai-handoff__ring' />
|
||||
<span className='weyai-handoff__orbit'>
|
||||
<i />
|
||||
</span>
|
||||
<span className='weyai-handoff__tile'>
|
||||
<img src={logo} alt='' className='weyai-handoff__logo' />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 播报区只包住标题与副标题:整块面板做 live region 会把三个步骤名
|
||||
和链接一并复读,而步骤推进本身又不改文本、读屏听不到 */}
|
||||
<div role='status' aria-live='polite'>
|
||||
<h1 className='weyai-handoff__title'>
|
||||
{title}
|
||||
<span className='weyai-handoff__dots' aria-hidden='true'>
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
</span>
|
||||
</h1>
|
||||
<p className='weyai-handoff__subtitle'>{subtitle}</p>
|
||||
</div>
|
||||
|
||||
<ol className='weyai-handoff__steps' aria-label={t('进度')}>
|
||||
{steps.map((label, index) => {
|
||||
const state =
|
||||
index < stage ? 'done' : index === stage ? 'active' : 'todo';
|
||||
return (
|
||||
<li
|
||||
key={label}
|
||||
className={`weyai-handoff__step weyai-handoff__step--${state}`}
|
||||
aria-current={state === 'active' ? 'step' : undefined}
|
||||
>
|
||||
<span className='weyai-handoff__step-dot'>
|
||||
{state === 'done' ? (
|
||||
<Check size={11} strokeWidth={3} />
|
||||
) : null}
|
||||
</span>
|
||||
<span className='weyai-handoff__step-label'>{label}</span>
|
||||
{index < steps.length - 1 && (
|
||||
<span
|
||||
className='weyai-handoff__step-line'
|
||||
aria-hidden='true'
|
||||
/>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
|
||||
<div className='weyai-handoff__bar' aria-hidden='true'>
|
||||
{/* 高光放在已填充段内部:放在轨道上会扫过未填充的那截,暗色下像
|
||||
多了一根乱动的亮条 */}
|
||||
<span
|
||||
className='weyai-handoff__bar-fill'
|
||||
style={{ width: `${((stage + 1) / steps.length) * 100}%` }}
|
||||
>
|
||||
<span className='weyai-handoff__bar-shine' />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{showManual && (
|
||||
<button
|
||||
type='button'
|
||||
className='weyai-handoff__manual'
|
||||
onClick={() => window.location.reload()}
|
||||
>
|
||||
{t('没有自动跳转?点此重试')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user