feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-06 20:19:43 +08:00
parent d4495eb703
commit 84803192ba
147 changed files with 9816 additions and 8768 deletions
+67
View File
@@ -21,6 +21,12 @@ import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
import postcss from 'postcss';
import { readFile } from 'node:fs/promises';
import { runInNewContext } from 'node:vm';
import React from 'react';
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 root = postcss.parse(css);
@@ -81,3 +87,64 @@ test('headerless viewport previews override standard body overflow', () => {
{ maxWidth: 'none', overflowX: 'visible', overflowY: 'visible' },
);
});
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 module = { exports: {} };
runInNewContext(code, {
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]),
);
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' })),
);
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}`));
assert.ok(html.includes('flex:1 1 0'));
});
}
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' } });
assert.ok(html.includes('flex:0 0 96px'));
assert.ok(html.includes('flex:1 1 240px'));
assert.ok(!html.includes('flex:0 0 180px'));
});
test('vertical forms without label widths keep the default Ant layout', () => {
const html = render({ labelPosition: 'top' });
assert.match(html, /ant-form-vertical/);
assert.ok(!html.includes('flex:0 0'));
});
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;
});
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'));
});
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 => {
assert.equal(Boolean(decl.important), false);
assert.ok(!['scrollbar-width', 'scrollbar-color'].includes(decl.prop));
});
});
});