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:
@@ -35,7 +35,11 @@ export const useNavigation = (
|
||||
orgEntry = {},
|
||||
) => {
|
||||
// 解构成基础类型,避免父组件每次渲染传入新对象字面量导致 useMemo 失效
|
||||
const { showOrgEntry = false, orgEntryPath = '/org' } = orgEntry;
|
||||
const {
|
||||
showOrgEntry = false,
|
||||
orgEntryPath = '/org',
|
||||
showPartnerEntry = false,
|
||||
} = orgEntry;
|
||||
// WeyAi 网页端入口:按 /api/status 开关与 /api/client/v1/web/access 决定是否显示
|
||||
const { visible: weyaiVisible, url: weyaiUrl } = useWeyAiWebEntry();
|
||||
const mainNavLinks = useMemo(() => {
|
||||
@@ -106,6 +110,19 @@ export const useNavigation = (
|
||||
};
|
||||
|
||||
const allLinks = [
|
||||
// 平台开放且具备新版伙伴权限时展示;放在前面,窄屏也容易找到。
|
||||
...(showPartnerEntry
|
||||
? [
|
||||
{
|
||||
text: t('伙伴工作台'),
|
||||
itemKey: 'partnerWorkspace',
|
||||
mobileText: t('导航'),
|
||||
to: '/console/my-commission',
|
||||
requireAuth: true,
|
||||
alwaysShow: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
text: t('密钥管理'),
|
||||
itemKey: 'keyManagement',
|
||||
@@ -191,6 +208,7 @@ export const useNavigation = (
|
||||
userGroup,
|
||||
showOrgEntry,
|
||||
orgEntryPath,
|
||||
showPartnerEntry,
|
||||
weyaiVisible,
|
||||
weyaiUrl,
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 { useContext, useEffect, useState } from 'react';
|
||||
import { API } from '../../helpers/api';
|
||||
import { UserContext } from '../../context/User';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { resolvePartnerWorkspaceIdentity } from '../../pages/PartnerPortal/redirect';
|
||||
import { partnerScope } from '../../pages/CommissionV2/partnerScope';
|
||||
|
||||
// 顶栏入口与工作台使用同一套服务端鉴权,不根据平台角色或旧版伙伴记录推断。
|
||||
export function usePartnerWorkspaceAccess(organizationId = null) {
|
||||
const [userState] = useContext(UserContext);
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const user = userState?.user;
|
||||
const scope = partnerScope(user?.id, organizationId);
|
||||
const portalEnabled = statusState?.status?.commission_partner_portal_enabled;
|
||||
// 分佣总开关关闭时不发起伙伴身份探测;旧后端不返回该字段,视为开启。
|
||||
const commissionEnabled = statusState?.status?.commission_enabled !== false;
|
||||
const enabled =
|
||||
commissionEnabled &&
|
||||
(portalEnabled === true || portalEnabled === 'true') &&
|
||||
scope.valid &&
|
||||
!userState?.authChecking;
|
||||
const [access, setAccess] = useState(null);
|
||||
const [attempt, setAttempt] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
setAccess(null);
|
||||
if (!enabled) return undefined;
|
||||
|
||||
resolvePartnerWorkspaceIdentity((url, config) =>
|
||||
API.get(scope.url(url), {
|
||||
...config,
|
||||
headers: scope.headers,
|
||||
}),
|
||||
).then(({ status, partnerType }) => {
|
||||
if (!cancelled)
|
||||
setAccess({ user, status, partnerType, attempt, scopeKey: scope.key });
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [enabled, user, attempt, scope.key]);
|
||||
|
||||
// 绑定本次登录的用户快照,切换账号时在 effect 执行前就隐藏旧入口。
|
||||
let status = 'loading';
|
||||
let partnerType = '';
|
||||
if (statusState?.status !== undefined && !userState?.authChecking) {
|
||||
if (!enabled) status = 'denied';
|
||||
else if (
|
||||
access?.user === user &&
|
||||
access?.attempt === attempt &&
|
||||
access?.scopeKey === scope.key
|
||||
) {
|
||||
status = access.status;
|
||||
partnerType = access.partnerType || '';
|
||||
}
|
||||
}
|
||||
return {
|
||||
status,
|
||||
partnerType,
|
||||
retry: () => setAttempt((value) => value + 1),
|
||||
};
|
||||
}
|
||||
|
||||
// 顶栏「伙伴工作台」与控制台侧栏「我的提成」只给个人伙伴:
|
||||
// 企业伙伴(含企业登录与管理企业的个人会话)统一从企业中心「企业分佣」进入,避免两处入口。
|
||||
export function usePartnerWorkspaceEntry() {
|
||||
const { status, partnerType } = usePartnerWorkspaceAccess();
|
||||
return status === 'allowed' && partnerType === 'individual';
|
||||
}
|
||||
Reference in New Issue
Block a user