feat: 同步权限管理、企业成员排行与消费计费明细

- 接入平台与企业角色权限,按权限展示菜单、页面及操作。
- 企业成员排行按需加载,翻页沿用同一榜单快照,保留连续名次与前三名样式。
- 更新消费日志的费用明细、超管指标和官方价格汇率设置,补齐翻译与回归测试。
This commit is contained in:
qiubaishen
2026-11-25 21:08:24 +08:00
parent ed693a450a
commit 870b51d054
134 changed files with 20354 additions and 4133 deletions
+59 -7
View File
@@ -15,6 +15,13 @@ import {
DEFAULT_READ_TIMEOUT_MS,
installRequestLifecycle,
} from './requestLifecycle';
import {
getCurrentOrgId,
getProxySession,
clearProxySession,
isProxyMode,
markProxyExpired,
} from './orgContext';
function createAPIInstance() {
const serverURL = getServerURL();
@@ -46,10 +53,9 @@ function patchAPIInstance(instance) {
return originalGet(url, config);
}
const fallbackOrgId =
url.startsWith('/api/org/') && typeof localStorage !== 'undefined'
? localStorage.getItem('current_org_id') || ''
: '';
const fallbackOrgId = url.startsWith('/api/org/')
? String(getCurrentOrgId() || '')
: '';
const requestKey = buildGetRequestKey(
url,
config,
@@ -72,15 +78,60 @@ function patchAPIInstance(instance) {
};
}
// 添加 request interceptor:自动为 /api/org/ 请求注入 X-Org-Id 头
// 表示代理会话已失效、需清掉本标签页代理上下文的返回码
const PROXY_INVALID_CODES = new Set([
'proxy_invalid',
'proxy_timeout',
'proxy_org_mismatch',
]);
// 企业会话须先修改初始密码(服务端在改密前拒绝企业业务接口):回到企业登录页的改密步骤。
// 已在企业登录页时不再跳转(登录页自己处理),同一页面只跳一次。
let redirectingToChangePassword = false;
function redirectToChangeInitialPassword() {
if (redirectingToChangePassword || typeof window === 'undefined') return;
const { pathname, search, hash } = window.location;
if (/^\/org(?:\/[^/]+)?\/login\/?$/.test(pathname)) return;
redirectingToChangePassword = true;
const params = new URLSearchParams({ must_change: '1' });
if (pathname.startsWith('/org')) {
params.set('redirect', `${pathname}${search}${hash}`);
}
window.location.replace(`/org/login?${params.toString()}`);
}
// 添加 response interceptor:按业务返回码维护企业上下文(HTTP 200 + success:false)
function addOrgResponseInterceptor(instance) {
instance.interceptors.response.use((response) => {
const code = response?.data?.code;
// 代理会话失效(超时、重新登录、被结束、企业不一致):清掉本标签页的代理上下文,提示从企业管理重新进入。
// proxy_error 是服务端校验出错("稍后重试"),代理会话本身仍有效,不清理
if (PROXY_INVALID_CODES.has(code) && isProxyMode()) {
clearProxySession();
// 记下"本标签页代理已失效":企业中心据此固定显示失效提示,不回落到 localStorage 里的企业
markProxyExpired();
}
if (code === 'must_change_password' && response?.data?.success === false) {
redirectToChangeInitialPassword();
}
return response;
});
}
// 添加 request interceptor:自动为 /api/org/ 请求注入 X-Org-Id 头;超管代理标签页同时带上
// X-Proxy-Session(企业以代理会话为准,X-Org-Id 只做一致性校验)
function addOrgHeaderInterceptor(instance) {
instance.interceptors.request.use((config) => {
config.headers['New-API-User'] = getUserIdFromLocalStorage();
if (config.url && config.url.startsWith('/api/org/')) {
const explicitOrgId = getHeaderValue(config.headers, 'X-Org-Id');
const orgId = explicitOrgId || localStorage.getItem('current_org_id');
const orgId = explicitOrgId || getCurrentOrgId();
if (orgId && !explicitOrgId) {
config.headers['X-Org-Id'] = orgId;
config.headers['X-Org-Id'] = String(orgId);
}
const proxy = getProxySession();
if (proxy) {
config.headers['X-Proxy-Session'] = proxy.id;
}
}
return config;
@@ -91,6 +142,7 @@ export function updateAPI() {
const instance = createAPIInstance();
patchAPIInstance(instance);
addOrgHeaderInterceptor(instance);
addOrgResponseInterceptor(instance);
const previous = retireAPI;
retireAPI = installRequestLifecycle(instance, {
onError: (error) => showError(error, { redirectOnUnauthorized: false }),