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
+164 -9
View File
@@ -9,6 +9,10 @@ import * as Ant from 'antd';
import { transformWithEsbuild } from 'vite';
import i18next from 'i18next';
import * as pagination from '../../src/components/ui/pagination.js';
import {
buildOrgLogFilters,
sameOrgRankingFilters,
} from '../../src/helpers/orgLogFilters.js';
await i18next.init({
lng: 'zh',
@@ -53,6 +57,8 @@ async function exercise(
expectedPage = 3,
pageKey = 'p',
values = {},
responseData,
response,
},
failure = false,
) {
@@ -62,6 +68,7 @@ async function exercise(
errors = [];
const context = {
URLSearchParams,
AbortController,
Date,
Promise,
console: { error() {} },
@@ -129,18 +136,21 @@ async function exercise(
get: async (url, options = {}) => {
calls.push({ url, options });
if (failure) throw new Error('simulated pagination failure');
if (response) return { data: await response(options) };
return {
data: {
success: true,
data: {
items: [sentinel],
list: [sentinel],
total: 156,
page: expectedPage,
page_size: expectedSize,
requests: { items: [sentinel], total: 156 },
audits: { items: [sentinel], total: 156 },
},
data: responseData
? responseData(options)
: {
items: [sentinel],
list: [sentinel],
total: 156,
page: expectedPage,
page_size: expectedSize,
requests: { items: [sentinel], total: 156 },
audits: { items: [sentinel], total: 156 },
},
},
};
},
@@ -366,6 +376,151 @@ for (const cfg of [
exercise(cfg, true));
}
const rankingValues = () => ({
buildOrgLogFilters,
request: { current: null },
emptyRankingPage: { items: [], total: 0, page: 1, page_size: 10 },
});
test('Member ranking sends applied filters and uses the server page and total', async () => {
const signal = new AbortController().signal;
const { calls, states } = await exercise({
file: 'src/hooks/org/useOrgData.js',
fn: 'fetch',
root: 'useOrgMemberRanking',
expectedPath: '/api/org/logs/ranking',
args: [
{
userId: 7,
modelName: 'model-a',
startTimestamp: 100,
endTimestamp: 200,
},
{ page: 3, pageSize: 50, noCache: true, signal },
],
values: rankingValues(),
});
assert.equal(calls.length, 1);
assert.deepEqual(
{ ...calls[0].options.params },
{
p: 3,
page_size: 50,
user_id: 7,
model_name: 'model-a',
start_timestamp: 100,
end_timestamp: 200,
nocache: 1,
},
);
assert.equal(calls[0].options.headers['X-Org-Id'], '77');
assert.equal(calls[0].options.signal, signal);
assert.equal(states.setRankingPage.page, 3);
assert.equal(states.setRankingPage.page_size, 50);
assert.equal(states.setRankingPage.total, 156);
assert.deepEqual(states.setRankingPage.items, [sentinel]);
});
test('Member ranking returns to the last available page when a refresh shrinks the results', async () => {
const { calls, states } = await exercise({
file: 'src/hooks/org/useOrgData.js',
fn: 'fetch',
root: 'useOrgMemberRanking',
expectedPath: '/api/org/logs/ranking',
args: [{}, { page: 3, pageSize: 50, noCache: true }],
values: rankingValues(),
responseData: ({ params }) => ({
items: params.p === 2 ? [sentinel] : [],
total: 51,
page: params.p,
page_size: params.page_size,
snapshot: 'fresh',
}),
});
assert.deepEqual(
calls.map(({ options }) => options.params.p),
[3, 2],
);
assert.equal(calls[1].options.params.snapshot, 'fresh');
assert.equal(calls[1].options.params.nocache, undefined);
assert.equal(states.setRankingPage.page, 2);
assert.deepEqual(states.setRankingPage.items, [sentinel]);
assert.equal(states.setLoading, false);
});
for (const expiresAgain of [false, true]) {
test(`Expired ranking snapshot restarts once on page one (retry fails: ${expiresAgain})`, async () => {
const expired = {
success: false,
code: 'ranking_snapshot_expired',
message: 'expired',
};
const { calls, errors, states } = await exercise({
file: 'src/hooks/org/useOrgData.js',
fn: 'fetch',
root: 'useOrgMemberRanking',
expectedPath: '/api/org/logs/ranking',
args: [
{ modelName: 'sample' },
{ page: 3, pageSize: 50, snapshot: 'old' },
],
values: rankingValues(),
response: ({ params }) =>
params.snapshot || expiresAgain
? expired
: {
success: true,
data: {
items: [sentinel],
total: 1,
page: 1,
page_size: 50,
snapshot: 'new',
},
},
});
assert.deepEqual(
calls.map(({ options }) => ({ ...options.params })),
[
{ model_name: 'sample', p: 3, page_size: 50, snapshot: 'old' },
{ model_name: 'sample', p: 1, page_size: 50 },
],
);
assert.equal(states.setRankingPage.page, 1);
assert.equal(
states.setRankingPage.snapshot,
expiresAgain ? undefined : 'new',
);
assert.deepEqual(errors, expiresAgain ? ['expired'] : []);
assert.equal(states.setLoading, false);
});
}
test('Member ranking refresh preserves the page only for the same applied filters', () => {
const applied = {
userId: 7,
modelName: 'model-a',
startTimestamp: 10,
endTimestamp: 20,
};
assert.equal(
sameOrgRankingFilters(applied, { ...applied, modelName: 'model-b' }, true),
false,
);
assert.equal(
sameOrgRankingFilters(applied, { ...applied, userId: 8 }, true),
false,
);
assert.equal(
sameOrgRankingFilters(applied, { ...applied, endTimestamp: 21 }, false),
false,
);
assert.equal(
sameOrgRankingFilters(applied, { ...applied, endTimestamp: 21 }, true),
true,
);
});
test('Resizing emits one size callback and never a stale page request', () => {
const calls = [];
const events = pagination.centerPaginationEvents({