feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
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 assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import { toConsoleTableChange } from '../src/components/console/consoleTableAdapter.js';
|
||||
import {
|
||||
consoleMenuPaths,
|
||||
consolePages,
|
||||
getConsoleMenuKeys,
|
||||
isNavigationPathActive,
|
||||
resolveConsolePage,
|
||||
} from '../src/components/console/consoleRoutes.js';
|
||||
|
||||
test('console metadata covers every concrete console route without duplicates', () => {
|
||||
const app = readFileSync(new URL('../src/App.jsx', import.meta.url), 'utf8');
|
||||
const routes = [...app.matchAll(/path='(\/console\/[^']+)'/g)]
|
||||
.map((match) => match[1].replace('/:id?', ''))
|
||||
.filter((path) => path !== '/console/experience-center-audit');
|
||||
assert.equal(
|
||||
new Set(consolePages.map((page) => page.path)).size,
|
||||
consolePages.length,
|
||||
);
|
||||
assert.deepEqual(
|
||||
new Set(routes),
|
||||
new Set(consolePages.map((page) => page.path)),
|
||||
);
|
||||
for (const page of consolePages) {
|
||||
assert.equal(consoleMenuPaths[page.menuKey || page.key], page.path);
|
||||
assert.ok(page.title && page.description);
|
||||
}
|
||||
});
|
||||
|
||||
test('both token sidebar entries navigate to the same console page', () => {
|
||||
assert.equal(consoleMenuPaths.token, '/console/token');
|
||||
assert.equal(consoleMenuPaths['admin-token'], consoleMenuPaths.token);
|
||||
assert.equal(resolveConsolePage(consoleMenuPaths.token).key, 'token');
|
||||
assert.deepEqual(getConsoleMenuKeys('/console/token').sort(), [
|
||||
'admin-token',
|
||||
'token',
|
||||
]);
|
||||
assert.deepEqual(getConsoleMenuKeys('/console/token/?page=2').sort(), [
|
||||
'admin-token',
|
||||
'token',
|
||||
]);
|
||||
assert.deepEqual(getConsoleMenuKeys(undefined), []);
|
||||
});
|
||||
|
||||
test('dashboard sidebar entries use the analytics route and remain selected', () => {
|
||||
assert.equal(consoleMenuPaths.detail, '/console/analytics');
|
||||
assert.equal(consoleMenuPaths.analytics, consoleMenuPaths.detail);
|
||||
assert.deepEqual(getConsoleMenuKeys('/console/analytics').sort(), [
|
||||
'analytics',
|
||||
'detail',
|
||||
]);
|
||||
});
|
||||
|
||||
test('console navigation remains active for descendants with full segment boundaries', () => {
|
||||
for (const page of consolePages) {
|
||||
assert.ok(isNavigationPathActive(page.path, '/console'));
|
||||
assert.ok(isNavigationPathActive(`${page.path}/42/edit`, '/console'));
|
||||
}
|
||||
assert.ok(isNavigationPathActive('/console', '/console/'));
|
||||
assert.equal(isNavigationPathActive('/console-other', '/console'), false);
|
||||
assert.equal(
|
||||
isNavigationPathActive('/user-center/setting', '/console'),
|
||||
false,
|
||||
);
|
||||
assert.equal(isNavigationPathActive('/market-detail', '/market'), false);
|
||||
assert.equal(isNavigationPathActive('/console', undefined), false);
|
||||
assert.equal(isNavigationPathActive('/console', '/'), false);
|
||||
});
|
||||
|
||||
test('breadcrumbs and page titles follow the current route, including deep paths', () => {
|
||||
assert.deepEqual(
|
||||
resolveConsolePage('/console/task/?page=2#result').breadcrumbs,
|
||||
[
|
||||
{ path: '/console', title: '控制台' },
|
||||
{ path: '/console/task', title: '任务日志' },
|
||||
],
|
||||
);
|
||||
const detail = resolveConsolePage('/console/user/42/edit');
|
||||
assert.equal(detail.key, 'user');
|
||||
assert.equal(detail.title, '编辑');
|
||||
assert.deepEqual(
|
||||
detail.breadcrumbs.map((item) => item.title),
|
||||
['控制台', '用户管理', '详情', '编辑'],
|
||||
);
|
||||
assert.equal(detail.breadcrumbs.at(-1).path, '/console/user/42/edit');
|
||||
assert.equal(
|
||||
resolveConsolePage('/console/chat/session-abc-123').title,
|
||||
'详情',
|
||||
);
|
||||
});
|
||||
|
||||
test('longest registered route wins and preserves its registered ancestors', () => {
|
||||
const pages = [
|
||||
{ path: '/console/setting', key: 'setting', title: '系统设置' },
|
||||
{ path: '/console/setting/security', key: 'security', title: '安全设置' },
|
||||
];
|
||||
const page = resolveConsolePage('/console/setting/security/edit', pages);
|
||||
assert.equal(page.key, 'security');
|
||||
assert.deepEqual(
|
||||
page.breadcrumbs.map((item) => item.title),
|
||||
['控制台', '系统设置', '安全设置', '编辑'],
|
||||
);
|
||||
});
|
||||
|
||||
test('unknown paths have a useful breadcrumb fallback and tolerate malformed encoding', () => {
|
||||
assert.equal(resolveConsolePage('/console').title, '控制台');
|
||||
assert.deepEqual(
|
||||
resolveConsolePage('/console/new-section/detail').breadcrumbs.map(
|
||||
(item) => item.title,
|
||||
),
|
||||
['控制台', 'new section', '详情'],
|
||||
);
|
||||
assert.equal(resolveConsolePage('/console/%E0%A4%A').title, '%E0%A4%A');
|
||||
assert.equal(resolveConsolePage('/console/user-agent').key, 'fallback');
|
||||
});
|
||||
|
||||
test('console titles and descriptions are translated in all nine locales', () => {
|
||||
for (const locale of [
|
||||
'zh',
|
||||
'zh-TW',
|
||||
'en',
|
||||
'ja',
|
||||
'ko',
|
||||
'fr',
|
||||
'ru',
|
||||
'vi',
|
||||
'th',
|
||||
]) {
|
||||
const data = JSON.parse(
|
||||
readFileSync(
|
||||
new URL(`../src/i18n/locales/${locale}.json`, import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
).translation;
|
||||
for (const page of consolePages) {
|
||||
assert.ok(data[page.title], `${locale}: ${page.title}`);
|
||||
assert.ok(
|
||||
data[`consoleUi.descriptions.${page.description}`],
|
||||
`${locale}: ${page.description}`,
|
||||
);
|
||||
}
|
||||
assert.ok(data['consoleUi.descriptions.fallback']);
|
||||
}
|
||||
});
|
||||
|
||||
test('console table adapters preserve legacy sorting, filtering and pagination callbacks', () => {
|
||||
const pagination = { current: 2, pageSize: 20 };
|
||||
const filters = { status: ['enabled'] };
|
||||
const result = toConsoleTableChange(
|
||||
pagination,
|
||||
filters,
|
||||
{ field: 'id', order: 'ascend' },
|
||||
{ action: 'sort' },
|
||||
);
|
||||
assert.equal(result.pagination, pagination);
|
||||
assert.equal(result.filters, filters);
|
||||
assert.equal(result.sorter.dataIndex, 'id');
|
||||
assert.equal(result.sorter.sortOrder, 'ascend');
|
||||
assert.equal(result.action, 'sort');
|
||||
assert.equal(
|
||||
toConsoleTableChange(pagination, filters, { field: 'id' }).sorter.sortOrder,
|
||||
undefined,
|
||||
);
|
||||
assert.equal(
|
||||
toConsoleTableChange(pagination, filters, [
|
||||
{ field: 'id', order: 'descend' },
|
||||
]).sorter[0].sortOrder,
|
||||
'descend',
|
||||
);
|
||||
});
|
||||
@@ -28,7 +28,10 @@ import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import * as Ant from 'antd';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
|
||||
const css = readFileSync(new URL('../src/styles/prototype.css', import.meta.url), 'utf8');
|
||||
const css = readFileSync(
|
||||
new URL('../src/styles/prototype.css', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
const root = postcss.parse(css);
|
||||
|
||||
const normalizeSelector = (selector) => selector.replace(/\s+/g, ' ').trim();
|
||||
@@ -70,14 +73,18 @@ test('standard modal bodies only scroll vertically', () => {
|
||||
});
|
||||
|
||||
test('fixed-width modal shells stay inside the viewport', () => {
|
||||
assert.equal(declarations(findRule('.ant-modal'))['max-width'], 'calc(100vw - 32px)');
|
||||
assert.equal(declarations(findRule('.viewport-preview-modal.ant-modal'))['max-width'], '100vw');
|
||||
assert.equal(
|
||||
declarations(findRule('.ant-modal'))['max-width'],
|
||||
'calc(100vw - 32px)',
|
||||
);
|
||||
assert.equal(
|
||||
declarations(findRule('.viewport-preview-modal.ant-modal'))['max-width'],
|
||||
'100vw',
|
||||
);
|
||||
});
|
||||
|
||||
test('headerless viewport previews override standard body overflow', () => {
|
||||
const rule = findRule(
|
||||
'.viewport-preview-modal .ant-modal-body',
|
||||
);
|
||||
const rule = findRule('.viewport-preview-modal .ant-modal-body');
|
||||
assert.deepEqual(
|
||||
{
|
||||
maxWidth: declarations(rule)['max-width'],
|
||||
@@ -89,28 +96,64 @@ test('headerless viewport previews override standard body overflow', () => {
|
||||
});
|
||||
|
||||
const file = new URL('../src/components/ui/form.jsx', import.meta.url);
|
||||
const { code } = await transformWithEsbuild(await readFile(file, 'utf8'), file.pathname, {
|
||||
loader: 'jsx', format: 'cjs', jsx: 'transform',
|
||||
});
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(file, 'utf8'),
|
||||
file.pathname,
|
||||
{
|
||||
loader: 'jsx',
|
||||
format: 'cjs',
|
||||
jsx: 'transform',
|
||||
},
|
||||
);
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
module, exports: module.exports,
|
||||
module,
|
||||
exports: module.exports,
|
||||
require(name) {
|
||||
if (name === 'react') return React;
|
||||
if (name === 'antd') return Ant;
|
||||
if (name === './controls') return Object.fromEntries(
|
||||
['Input', 'TextArea', 'InputNumber', 'Select', 'DatePicker', 'TimePicker', 'RadioGroup', 'CheckboxGroup', 'TagInput', 'TreeSelect', 'AutoComplete', 'Upload', 'Switch'].map(key => [key, Ant.Input]),
|
||||
);
|
||||
if (name === '../console/ConsoleContext')
|
||||
return { useConsolePage: () => null };
|
||||
if (name === '../console/ConsolePrimitives') return {};
|
||||
if (name === './controls')
|
||||
return Object.fromEntries(
|
||||
[
|
||||
'Input',
|
||||
'TextArea',
|
||||
'InputNumber',
|
||||
'Select',
|
||||
'DatePicker',
|
||||
'TimePicker',
|
||||
'RadioGroup',
|
||||
'CheckboxGroup',
|
||||
'TagInput',
|
||||
'TreeSelect',
|
||||
'AutoComplete',
|
||||
'Upload',
|
||||
'Switch',
|
||||
].map((key) => [key, Ant.Input]),
|
||||
);
|
||||
throw new Error(`Unexpected dependency: ${name}`);
|
||||
},
|
||||
});
|
||||
const { Form } = module.exports;
|
||||
const render = (props) => renderToStaticMarkup(
|
||||
React.createElement(Form, { labelPosition: 'left', ...props },
|
||||
React.createElement(Form.Input, { field: 'sample', label: 'Setting label' })),
|
||||
);
|
||||
const render = (props) =>
|
||||
renderToStaticMarkup(
|
||||
React.createElement(
|
||||
Form,
|
||||
{ labelPosition: 'left', ...props },
|
||||
React.createElement(Form.Input, {
|
||||
field: 'sample',
|
||||
label: 'Setting label',
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
for (const [width, css] of [[180, '180px'], ['120px', '120px'], ['25%', '25%']]) {
|
||||
for (const [width, css] of [
|
||||
[180, '180px'],
|
||||
['120px', '120px'],
|
||||
['25%', '25%'],
|
||||
]) {
|
||||
test(`form label width ${width} keeps its unit and cannot grow across the row`, () => {
|
||||
const html = render({ labelWidth: width });
|
||||
assert.ok(html.includes(`flex:0 0 ${css}`));
|
||||
@@ -118,7 +161,11 @@ for (const [width, css] of [[180, '180px'], ['120px', '120px'], ['25%', '25%']])
|
||||
});
|
||||
}
|
||||
test('explicit Ant Design column settings take precedence over legacy labelWidth', () => {
|
||||
const html = render({ labelWidth: 180, labelCol: { flex: '0 0 96px' }, wrapperCol: { flex: '1 1 240px' } });
|
||||
const html = render({
|
||||
labelWidth: 180,
|
||||
labelCol: { flex: '0 0 96px' },
|
||||
wrapperCol: { flex: '1 1 240px' },
|
||||
});
|
||||
assert.ok(html.includes('flex:0 0 96px'));
|
||||
assert.ok(html.includes('flex:1 1 240px'));
|
||||
assert.ok(!html.includes('flex:0 0 180px'));
|
||||
@@ -129,20 +176,44 @@ test('vertical forms without label widths keep the default Ant layout', () => {
|
||||
assert.ok(!html.includes('flex:0 0'));
|
||||
});
|
||||
|
||||
const stylesheet = postcss.parse(await readFile(new URL('../src/pages/Setting/Setting.css', import.meta.url), 'utf8'));
|
||||
const stylesheet = postcss.parse(
|
||||
await readFile(
|
||||
new URL('../src/pages/Setting/Setting.css', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
test('settings labels stack on narrow screens without overriding inline flex declarations', () => {
|
||||
let mobileRule;
|
||||
stylesheet.walkRules(rule => {
|
||||
if (rule.selectors.includes('.settings-page .ant-form-horizontal .ant-form-item-row')) mobileRule = rule;
|
||||
stylesheet.walkRules((rule) => {
|
||||
if (
|
||||
rule.selectors.includes(
|
||||
'.settings-page .ant-form-horizontal .ant-form-item-row',
|
||||
)
|
||||
)
|
||||
mobileRule = rule;
|
||||
});
|
||||
assert.ok(mobileRule.selectors.includes('.settings-form-dialog .ant-form-horizontal .ant-form-item-row'));
|
||||
assert.ok(
|
||||
mobileRule.selectors.includes(
|
||||
'.settings-form-dialog .ant-form-horizontal .ant-form-item-row',
|
||||
),
|
||||
);
|
||||
assert.match(mobileRule.parent.params, /max-width: 767px/);
|
||||
assert.ok(mobileRule.nodes.some(node => node.prop === 'display' && node.value === 'block'));
|
||||
assert.ok(
|
||||
mobileRule.nodes.some(
|
||||
(node) => node.prop === 'display' && node.value === 'block',
|
||||
),
|
||||
);
|
||||
});
|
||||
test('settings layout rules stay scoped and use the existing scrollbar policy', () => {
|
||||
stylesheet.walkRules(rule => {
|
||||
assert.ok(rule.selectors.every(selector => selector.startsWith('.settings-page') || selector.startsWith('.settings-form-dialog')));
|
||||
rule.walkDecls(decl => {
|
||||
stylesheet.walkRules((rule) => {
|
||||
assert.ok(
|
||||
rule.selectors.every(
|
||||
(selector) =>
|
||||
selector.startsWith('.settings-page') ||
|
||||
selector.startsWith('.settings-form-dialog'),
|
||||
),
|
||||
);
|
||||
rule.walkDecls((decl) => {
|
||||
assert.equal(Boolean(decl.important), false);
|
||||
assert.ok(!['scrollbar-width', 'scrollbar-color'].includes(decl.prop));
|
||||
});
|
||||
|
||||
@@ -50,6 +50,13 @@ const orgLogs = readFileSync(
|
||||
new URL('../src/pages/Organization/OrgLogs.jsx', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
const orgTaskRecords = readFileSync(
|
||||
new URL(
|
||||
'../src/pages/Organization/components/OrgTaskRecords.jsx',
|
||||
import.meta.url,
|
||||
),
|
||||
'utf8',
|
||||
);
|
||||
const usageRecord = readFileSync(
|
||||
new URL('../src/pages/UserCenter/UsageRecord.jsx', import.meta.url),
|
||||
'utf8',
|
||||
@@ -58,18 +65,24 @@ const usageRecord = readFileSync(
|
||||
test('enterprise task records use the organization-scoped endpoint', () => {
|
||||
assert.match(hook, /organizationMode/);
|
||||
assert.match(hook, /`\/api\/org\/tasks\?\$\{params\.toString\(\)\}`/);
|
||||
assert.match(
|
||||
orgLogs,
|
||||
/sharedStartTimestamp=\{appliedFilters\.startTimestamp\}/,
|
||||
);
|
||||
assert.match(orgLogs, /sharedEndTimestamp=\{appliedFilters\.endTimestamp\}/);
|
||||
assert.match(orgLogs, /sharedFilterRevision=\{taskFilterRevision\}/);
|
||||
assert.match(hook, /DEFAULT_TASK_RANGE_DAYS = 7/);
|
||||
assert.match(hook, /const usesSharedDateRange/);
|
||||
assert.match(filters, /hideDateRange = false/);
|
||||
assert.match(filters, /!hideDateRange/);
|
||||
});
|
||||
|
||||
// 2026-11-07 用户确认:与原型一致,“绘图与视频”使用自身可编辑的时间范围,不再复用“明细日志”已提交区间
|
||||
test('enterprise task records keep their own editable date range', () => {
|
||||
assert.match(orgLogs, /<OrgTaskRecords \/>/);
|
||||
assert.doesNotMatch(orgLogs, /sharedStartTimestamp=/);
|
||||
assert.match(
|
||||
orgTaskRecords,
|
||||
/useTaskLogsData\(\{ organizationMode: true \}\)/,
|
||||
);
|
||||
assert.doesNotMatch(orgTaskRecords, /hideDateRange/);
|
||||
assert.match(orgTaskRecords, /<TaskLogsFilters \{\.\.\.taskLogsData\} usageRecordMode \/>/);
|
||||
});
|
||||
|
||||
test('platform is not exposed as a task-log presentation field', () => {
|
||||
assert.doesNotMatch(columns, /COLUMN_KEYS\.PLATFORM/);
|
||||
assert.doesNotMatch(columns, /title: t\('平台'\)/);
|
||||
|
||||
@@ -27,6 +27,7 @@ import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import * as Ant from 'antd';
|
||||
import * as pagination from '../src/components/ui/pagination.js';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
import * as clipboard from '../src/helpers/clipboard.js';
|
||||
|
||||
async function compile(relativePath) {
|
||||
const filename = new URL(relativePath, import.meta.url);
|
||||
@@ -61,6 +62,7 @@ const { createCardProPagination } = loadUtils({
|
||||
'./officialPrice': {},
|
||||
'./data': {},
|
||||
'./tableCompactMode.js': {},
|
||||
'./clipboard': clipboard,
|
||||
});
|
||||
const loadUsersPage = await compile('../src/components/table/users/index.jsx');
|
||||
|
||||
@@ -75,8 +77,11 @@ function paginationProps(element) {
|
||||
function foundationFor(props) {
|
||||
const events = paginationEvents(props);
|
||||
return {
|
||||
changePageSize: size => { events.onShowSizeChange(props.currentPage, size); events.onChange(props.currentPage, size); },
|
||||
goPage: page => events.onChange(page, props.pageSize),
|
||||
changePageSize: (size) => {
|
||||
events.onShowSizeChange(props.currentPage, size);
|
||||
events.onChange(props.currentPage, size);
|
||||
},
|
||||
goPage: (page) => events.onChange(page, props.pageSize),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -130,6 +135,7 @@ for (const isMobile of [false, true]) {
|
||||
'../../../hooks/users/useUsersData': { useUsersData: () => usersData },
|
||||
'../../../hooks/common/useIsMobile': { useIsMobile: () => isMobile },
|
||||
'../../../helpers/utils': { createCardProPagination },
|
||||
'../../console/ConsoleContext': { useConsolePage: () => null },
|
||||
});
|
||||
const renderPagination = () => {
|
||||
const card = React.Children.toArray(UsersPage().props.children).find(
|
||||
@@ -166,9 +172,14 @@ const { Table, Pagination } = loadUi({
|
||||
antd: Ant,
|
||||
'./controls': { controlSize: (size) => size },
|
||||
'./pagination': pagination,
|
||||
'./pagination.css': {},
|
||||
'../../hooks/common/useIsMobile': { useIsMobile: () => false },
|
||||
'./overlayPolicy': {},
|
||||
'./form': {},
|
||||
'./chat': {},
|
||||
'../console/ConsoleContext': { useConsolePage: () => null },
|
||||
'../console/ConsolePrimitives': {},
|
||||
'../console/consoleTableAdapter': {},
|
||||
});
|
||||
|
||||
for (const [name, render] of [
|
||||
@@ -181,7 +192,7 @@ for (const [name, render] of [
|
||||
pagination: props,
|
||||
}),
|
||||
],
|
||||
['Pagination', (props) => Pagination(props)],
|
||||
['Pagination', (props) => React.createElement(Pagination, props)],
|
||||
]) {
|
||||
test(`${name} renders legacy boolean showTotal without crashing`, () => {
|
||||
const element = render({ total: 25, pageSize: 10, showTotal: true });
|
||||
|
||||
Reference in New Issue
Block a user