sync: 同步 monkey-ai@weiyuan(ddc5b9443) 的 web/ 到 ui-optimization
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
This commit is contained in:
+25
-9
@@ -17,8 +17,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useContext } from 'react';
|
||||
import { Navigate, useLocation } from 'react-router-dom';
|
||||
import React, { useContext, useEffect, useRef } from 'react';
|
||||
import { Navigate, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { history } from './history';
|
||||
import { UserContext } from '../context/User';
|
||||
import { StatusContext } from '../context/Status';
|
||||
@@ -26,11 +26,11 @@ import { canAccessDelegatedAdminPage } from './adminDelegation';
|
||||
import { ADMIN_DELEGATION_OPTION_KEY } from '../constants/settingTabs';
|
||||
import Loading from '../components/common/ui/Loading';
|
||||
import {
|
||||
DEFAULT_LOGIN_REDIRECT,
|
||||
getUserData,
|
||||
isSafePostLoginRedirect,
|
||||
savePostLoginRedirect,
|
||||
} from './data';
|
||||
import { authRedirectTarget } from './authRedirect';
|
||||
|
||||
/**
|
||||
* 判断是否处于认证类页面(登录/注册/重置密码/企业登录/企业注册)。
|
||||
@@ -62,14 +62,30 @@ const getLoginTarget = (location) => {
|
||||
export const AuthRedirect = ({ children }) => {
|
||||
const [userState] = useContext(UserContext);
|
||||
const cachedUser = getUserData();
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const initiallyAuthenticated = useRef(Boolean(userState?.user || cachedUser));
|
||||
|
||||
// LoginForm publishes the user before it navigates to the saved deep link.
|
||||
// Schedule the default guard redirect in an effect so the explicit deep
|
||||
// link navigation wins the same login transition.
|
||||
useEffect(() => {
|
||||
if (
|
||||
!initiallyAuthenticated.current ||
|
||||
!userState?.user ||
|
||||
location.pathname !== '/login'
|
||||
)
|
||||
return;
|
||||
const target = authRedirectTarget({
|
||||
authenticated: true,
|
||||
redirectReady: true,
|
||||
orgOnly: userState.user.org_only_mode === true,
|
||||
});
|
||||
if (target) navigate(target, { replace: true });
|
||||
}, [location.pathname, navigate, userState?.user]);
|
||||
|
||||
if (userState?.user) {
|
||||
// org_only(仅企业资源)员工登录后直接进入企业空间
|
||||
if (userState.user.org_only_mode === true) {
|
||||
return <Navigate to='/org' replace />;
|
||||
}
|
||||
// 已登录用户统一跳转到默认登录落地页,而不是控制台(控制台需要管理员权限)
|
||||
return <Navigate to={DEFAULT_LOGIN_REDIRECT} replace />;
|
||||
return children;
|
||||
}
|
||||
if (!userState?.authChecked && cachedUser) {
|
||||
return <Loading />;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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 { DEFAULT_LOGIN_REDIRECT } from './data.js';
|
||||
|
||||
export function authRedirectTarget({
|
||||
authenticated,
|
||||
redirectReady,
|
||||
orgOnly = false,
|
||||
}) {
|
||||
if (!authenticated || !redirectReady) return null;
|
||||
return orgOnly ? '/org' : DEFAULT_LOGIN_REDIRECT;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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 test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { authRedirectTarget } from './authRedirect.js';
|
||||
|
||||
test('认证状态刚切换时等待回跳目标完成,避免覆盖深链', () => {
|
||||
assert.equal(
|
||||
authRedirectTarget({ authenticated: true, redirectReady: false }),
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
authRedirectTarget({ authenticated: true, redirectReady: true }),
|
||||
// ui 基线:密钥管理迁至 /user-center/key-management(旧路径重定向)
|
||||
'/user-center/key-management',
|
||||
);
|
||||
});
|
||||
|
||||
test('仅企业账号稳定登录后仍进入企业空间', () => {
|
||||
assert.equal(
|
||||
authRedirectTarget({
|
||||
authenticated: true,
|
||||
redirectReady: true,
|
||||
orgOnly: true,
|
||||
}),
|
||||
'/org',
|
||||
);
|
||||
});
|
||||
@@ -123,6 +123,12 @@ export function setUserData(data) {
|
||||
export function clearUserData() {
|
||||
localStorage.removeItem(USER_STORAGE_KEY);
|
||||
localStorage.removeItem('current_org_id');
|
||||
// 智能路由侧边栏的个人授权缓存属于当前用户:同一标签页换账号登录时不能沿用
|
||||
try {
|
||||
sessionStorage.removeItem('smart_router_personal_consent_granted');
|
||||
} catch {
|
||||
// sessionStorage 不可用时无需清理
|
||||
}
|
||||
}
|
||||
|
||||
export function isSafePostLoginRedirect(path) {
|
||||
|
||||
@@ -77,8 +77,10 @@ import {
|
||||
Package,
|
||||
Activity,
|
||||
PieChart,
|
||||
HandCoins,
|
||||
Building2,
|
||||
Handshake,
|
||||
Route,
|
||||
Globe,
|
||||
CalendarDays,
|
||||
} from 'lucide-react';
|
||||
@@ -125,8 +127,12 @@ export function getLucideIcon(key, selected = false) {
|
||||
return <Package {...commonProps} color={iconColor} />;
|
||||
case 'monitor':
|
||||
return <Activity {...commonProps} color={iconColor} />;
|
||||
case 'commission':
|
||||
return <HandCoins {...commonProps} color={iconColor} />;
|
||||
case 'analytics':
|
||||
return <PieChart {...commonProps} color={iconColor} />;
|
||||
case 'smart-router':
|
||||
return <Route {...commonProps} color={iconColor} />;
|
||||
case 'organizations':
|
||||
return <Building2 {...commonProps} color={iconColor} />;
|
||||
case 'partner':
|
||||
@@ -985,6 +991,8 @@ function renderPriceSimpleCore({
|
||||
cacheCreationRatio5m = 1.0,
|
||||
cacheCreationTokens1h = 0,
|
||||
cacheCreationRatio1h = 1.0,
|
||||
cacheCreationTokensUnlabeled = 0,
|
||||
cacheCreationRatioUnlabeled = 1.0,
|
||||
image = false,
|
||||
imageRatio = 1.0,
|
||||
isSystemPromptOverride = false,
|
||||
@@ -1016,6 +1024,10 @@ function renderPriceSimpleCore({
|
||||
hasSplitCacheCreation && cacheCreationTokens5m > 0;
|
||||
const shouldShowCacheCreation1h =
|
||||
hasSplitCacheCreation && cacheCreationTokens1h > 0;
|
||||
// 上游给了总量却没给分档的那部分按「默认档位」计价,倍率可能既不等于 5m 也不等于 1h。
|
||||
// 与分档并存时它是独立的一项,漏掉这一项用户就对不出总价。
|
||||
const shouldShowCacheCreationUnlabeled =
|
||||
hasSplitCacheCreation && cacheCreationTokensUnlabeled > 0;
|
||||
|
||||
const parts = [];
|
||||
// base: model ratio
|
||||
@@ -1047,6 +1059,13 @@ function renderPriceSimpleCore({
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (shouldShowCacheCreationUnlabeled) {
|
||||
parts.push(
|
||||
i18next.t('未分档缓存创建: {{cacheCreationRatioUnlabeled}}', {
|
||||
cacheCreationRatioUnlabeled,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else if (shouldShowLegacyCacheCreation) {
|
||||
parts.push(
|
||||
i18next.t('缓存创建: {{cacheCreationRatio}}', { cacheCreationRatio }),
|
||||
@@ -1451,6 +1470,8 @@ export function renderModelPriceSimple(
|
||||
cacheCreationRatio5m = 1.0,
|
||||
cacheCreationTokens1h = 0,
|
||||
cacheCreationRatio1h = 1.0,
|
||||
cacheCreationTokensUnlabeled = 0,
|
||||
cacheCreationRatioUnlabeled = 1.0,
|
||||
image = false,
|
||||
imageRatio = 1.0,
|
||||
isSystemPromptOverride = false,
|
||||
@@ -1469,6 +1490,8 @@ export function renderModelPriceSimple(
|
||||
cacheCreationRatio5m,
|
||||
cacheCreationTokens1h,
|
||||
cacheCreationRatio1h,
|
||||
cacheCreationTokensUnlabeled,
|
||||
cacheCreationRatioUnlabeled,
|
||||
image,
|
||||
imageRatio,
|
||||
isSystemPromptOverride,
|
||||
|
||||
Reference in New Issue
Block a user