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:
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
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 { API, showError } from '../../helpers';
|
||||
import i18n from '../../i18n/i18n';
|
||||
|
||||
// 智能模型路由接口(后端 router/smart-router.go)。
|
||||
// mode: personal(个人)/ admin(平台 system 集合)/ org(企业,X-Org-Id 由 API 拦截器注入)
|
||||
// 所有请求都跳过全局错误提示(skipErrorHandler),由调用方只弹一次业务文案,避免英文报错与重复提示。
|
||||
export const routerBase = (mode) => {
|
||||
if (mode === 'admin') return '/api/router/admin';
|
||||
if (mode === 'org') return '/api/org/router';
|
||||
return '/api/router';
|
||||
};
|
||||
|
||||
const opts = (orgId, extra = {}) => ({
|
||||
skipErrorHandler: true,
|
||||
...(orgId ? { headers: { 'X-Org-Id': String(orgId) } } : {}),
|
||||
...extra,
|
||||
});
|
||||
|
||||
const friendly = (e) => {
|
||||
const msg = e?.response?.data?.message;
|
||||
if (msg) return msg;
|
||||
const status = e?.response?.status;
|
||||
if (status === 429) return i18n.t('操作过于频繁,请稍后再试');
|
||||
if (status === 401 || status === 403) return i18n.t('没有权限执行该操作');
|
||||
return i18n.t('请求失败,请稍后重试');
|
||||
};
|
||||
|
||||
const call = async (fn) => {
|
||||
let res;
|
||||
try {
|
||||
res = await fn();
|
||||
} catch (e) {
|
||||
// 401 交给全局处理:清理登录态并跳转登录页(skipErrorHandler 会跳过它)。
|
||||
// 之后不再抛出,调用方也就不会再弹一次"没有权限"——页面马上会跳走
|
||||
if (e?.response?.status === 401) {
|
||||
showError(e);
|
||||
return new Promise(() => {});
|
||||
}
|
||||
throw new Error(friendly(e));
|
||||
}
|
||||
const { success, message, data } = res?.data || {};
|
||||
if (!success) throw new Error(message || i18n.t('请求失败,请稍后重试'));
|
||||
return data;
|
||||
};
|
||||
|
||||
export const listProfiles = (mode, orgId) =>
|
||||
call(() => API.get(`${routerBase(mode)}/profiles`, opts(orgId)));
|
||||
|
||||
export const saveProfile = (mode, orgId, profile) => {
|
||||
const base = routerBase(mode);
|
||||
return call(() =>
|
||||
profile.id
|
||||
? API.put(`${base}/profiles/${profile.id}`, profile, opts(orgId))
|
||||
: API.post(`${base}/profiles`, profile, opts(orgId)),
|
||||
);
|
||||
};
|
||||
|
||||
export const deleteProfile = (mode, orgId, id) =>
|
||||
call(() => API.delete(`${routerBase(mode)}/profiles/${id}`, opts(orgId)));
|
||||
|
||||
export const simulateProfile = (mode, orgId, id, payload) =>
|
||||
call(() =>
|
||||
API.post(
|
||||
`${routerBase(mode)}/profiles/${id}/simulate`,
|
||||
payload,
|
||||
opts(orgId),
|
||||
),
|
||||
);
|
||||
|
||||
export const listDecisions = (mode, orgId, params) =>
|
||||
call(() => API.get(`${routerBase(mode)}/decisions`, opts(orgId, { params })));
|
||||
|
||||
export const getConsents = (mode, orgId) =>
|
||||
call(() => API.get(`${routerBase(mode)}/consents`, opts(orgId)));
|
||||
|
||||
// 个人是否仍有生效中的出境同意:平台关闭智能路由后,侧边栏据此保留入口供撤回(会话内缓存,避免每次进页面都请求)
|
||||
const CONSENT_CACHE_KEY = 'smart_router_personal_consent_granted';
|
||||
|
||||
export const readPersonalConsentCache = () => {
|
||||
try {
|
||||
return sessionStorage.getItem(CONSENT_CACHE_KEY);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const writePersonalConsentCache = (rows) => {
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
CONSENT_CACHE_KEY,
|
||||
(rows || []).some((x) => x && x.granted === true) ? '1' : '0',
|
||||
);
|
||||
} catch {
|
||||
// 无痕模式等场景下 sessionStorage 不可用:不缓存即可
|
||||
}
|
||||
};
|
||||
|
||||
export const loadPersonalConsentGranted = async () => {
|
||||
const rows = await getConsents('personal');
|
||||
writePersonalConsentCache(rows);
|
||||
return (rows || []).some((x) => x && x.granted === true);
|
||||
};
|
||||
|
||||
export const updateConsent = async (mode, orgId, kind, granted) => {
|
||||
const rows = await call(() =>
|
||||
API.put(`${routerBase(mode)}/consents`, { kind, granted }, opts(orgId)),
|
||||
);
|
||||
if (mode !== 'org' && mode !== 'admin') writePersonalConsentCache(rows);
|
||||
return rows;
|
||||
};
|
||||
|
||||
// 候选模型下拉的数据来源:个人=自己分组可用模型;平台=全部启用模型;企业=企业可用模型
|
||||
export const listCandidateModels = async (mode, orgId) => {
|
||||
let url = '/api/user/models';
|
||||
if (mode === 'admin') url = '/api/channel/models_enabled';
|
||||
if (mode === 'org') url = '/api/org/models';
|
||||
const data = await call(() => API.get(url, opts(orgId)));
|
||||
return (data || []).filter(
|
||||
(m) => typeof m === 'string' && !m.startsWith('router/'),
|
||||
);
|
||||
};
|
||||
|
||||
export const getAdminStatus = () =>
|
||||
call(() => API.get('/api/router/admin/status', opts()));
|
||||
|
||||
export const setJevKey = (provider, key, clear = false) =>
|
||||
call(() =>
|
||||
API.put('/api/router/admin/jev-key', { provider, key, clear }, opts()),
|
||||
);
|
||||
|
||||
export const loadOptions = () => call(() => API.get('/api/option/', opts()));
|
||||
|
||||
export const saveOption = (key, value) =>
|
||||
call(() => API.put('/api/option/', { key, value }, opts()));
|
||||
Reference in New Issue
Block a user