feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面

This commit is contained in:
zhanjunhao
2026-11-09 21:45:37 +08:00
parent 9fc5fd212d
commit 28e924e371
242 changed files with 9242 additions and 5043 deletions
+8
View File
@@ -57,6 +57,14 @@ const DAYJS_LOCALES = {
const PROTOTYPE_DARK_PRIMARY = '#d1963a';
const PROTOTYPE_DARK_SEED = '#f2ad41';
// 页面局部“品牌强调色”(原型 --brand):等于当前主题的种子色。
// 浅色与自定义主色时即 colorPrimary;仅默认暗色主色 #d1963a 时回到原型种子 #f2ad41,
// 保证浅色 / 深色 / 自定义主题色三态都只由主题 token 推导,不在页面里另写颜色。
export const brandAccentFromToken = (colorPrimary, dark) =>
dark && colorPrimary?.toLowerCase() === PROTOTYPE_DARK_PRIMARY
? PROTOTYPE_DARK_SEED
: colorPrimary;
export const prototypeTheme = (dark) => ({
algorithm: (seed, map) => {
const derive =
+8 -7
View File
@@ -36,6 +36,7 @@ import {
Space as AntSpace,
} from 'antd';
import dayjs from 'dayjs';
import { useConsoleControlSize } from '../console/ConsoleContext';
export const controlSize = (size) => (size === 'default' ? 'middle' : size);
export const placement = (position) =>
@@ -73,7 +74,7 @@ export const Input = forwardRef(function Input(
<Component
{...props}
ref={ref}
size={controlSize(size)}
size={useConsoleControlSize(size)}
readOnly={readonly ?? props.readOnly}
variant={borderless ? 'borderless' : undefined}
status={statusOf(validateStatus || status)}
@@ -126,7 +127,7 @@ export const Button = forwardRef(function Button(
ref={ref}
type={buttonType}
danger={danger}
size={controlSize(size)}
size={useConsoleControlSize(size)}
shape={circle ? 'circle' : undefined}
iconPosition={iconPosition === 'right' ? 'end' : 'start'}
/>
@@ -152,7 +153,7 @@ export const InputNumber = forwardRef(function InputNumber(
<AntInputNumber
{...props}
ref={ref}
size={controlSize(size)}
size={useConsoleControlSize(size)}
controls={!hideButtons}
suffix={suffix}
status={statusOf(validateStatus)}
@@ -199,7 +200,7 @@ export function Select({
return (
<AntSelect
{...props}
size={controlSize(size)}
size={useConsoleControlSize(size)}
mode={
allowCreate || allowAdditions
? 'tags'
@@ -311,7 +312,7 @@ export const RadioGroup = forwardRef(function RadioGroup(
<AntRadio.Group
{...props}
ref={ref}
size={controlSize(size || buttonSize)}
size={useConsoleControlSize(size || buttonSize)}
optionType={type === 'button' ? 'button' : 'default'}
className={[
props.className,
@@ -380,7 +381,7 @@ export function DatePicker({
defaultValue={
defaultValue === undefined ? undefined : convert(defaultValue)
}
size={controlSize(size)}
size={useConsoleControlSize(size)}
allowClear={showClear}
showTime={type?.toLowerCase().includes('time')}
inputReadOnly={inputReadOnly}
@@ -470,7 +471,7 @@ export function AutoComplete({
typeof item === 'string' ? { value: item } : item,
)}
notFoundContent={emptyContent}
size={controlSize(size)}
size={useConsoleControlSize(size)}
onKeyDown={(e) => {
if (e.key === 'Enter') onEnterPress?.(e);
}}
+54 -11
View File
@@ -29,6 +29,8 @@ import React, {
} from 'react';
import { Checkbox, Form as AntForm } from 'antd';
import * as Controls from './controls';
import { useConsolePage } from '../console/ConsoleContext';
import { ConsoleForm } from '../console/ConsolePrimitives';
const FormContext = createContext(null);
const fieldPath = (field) =>
@@ -36,6 +38,26 @@ const fieldPath = (field) =>
? field.replace(/\[(\d+)\]/g, '.$1').split('.')
: field;
function FormRenderContent({ form, api, children }) {
const values = form.getFieldsValue(true);
return children({ formState: { values }, formApi: api, values });
}
function fieldUpdate(form, path, value) {
let update = value;
for (let index = path.length - 1; index > 0; index--) {
const previous = form.getFieldValue(path.slice(0, index));
const parent = Array.isArray(previous)
? [...previous]
: previous == null && typeof path[index] === 'number'
? []
: { ...previous };
parent[path[index]] = update;
update = parent;
}
return { [path[0]]: update };
}
export const Form = forwardRef(function Form(
{
initValues,
@@ -56,6 +78,8 @@ export const Form = forwardRef(function Form(
},
ref,
) {
const consolePage = useConsolePage();
const FormComponent = consolePage ? ConsoleForm : AntForm;
const [form] = AntForm.useForm();
const [, renderValues] = useReducer((value) => value + 1, 0);
const callbacks = useRef({ getFormApi, onValueChange });
@@ -65,7 +89,8 @@ export const Form = forwardRef(function Form(
getValues: () => form.getFieldsValue(true),
getValue: (field) => form.getFieldValue(fieldPath(field)),
setValue: (field, value) => {
form.setFieldValue(fieldPath(field), value);
// External value updates avoid setFieldValue's redundant validation-meta reset.
form.setFieldsValue(fieldUpdate(form, fieldPath(field), value));
callbacks.current.onValueChange?.(form.getFieldsValue(true), {
[field]: value,
});
@@ -83,6 +108,12 @@ export const Form = forwardRef(function Form(
},
validate: (fields) => form.validateFields(fields?.map?.(fieldPath)),
submitForm: () => form.submit(),
scrollToError: () => {
const first = form
.getFieldsError()
.find((field) => field.errors.length);
if (first) form.scrollToField(first.name, { block: 'nearest' });
},
getFieldExist: (field) =>
form.getFieldInstance(fieldPath(field)) !== undefined,
}),
@@ -98,7 +129,7 @@ export const Form = forwardRef(function Form(
}, [form, values]);
return (
<FormContext.Provider value={form}>
<AntForm
<FormComponent
{...props}
form={form}
initialValues={initValues}
@@ -122,20 +153,32 @@ export const Form = forwardRef(function Form(
}
labelAlign={labelAlign}
onFinish={onSubmit}
onFinishFailed={onSubmitFail}
onFinishFailed={
consolePage && onSubmitFail
? ({ errorFields }) =>
onSubmitFail(
Object.fromEntries(
errorFields.map(({ name, errors }) => [
name.join('.'),
errors,
]),
),
)
: onSubmitFail
}
onValuesChange={(_, all) => {
callbacks.current.onValueChange?.(all);
renderValues();
}}
>
{typeof children === 'function'
? children({
formState: { values: form.getFieldsValue(true) },
formApi: api,
values: form.getFieldsValue(true),
})
: children}
</AntForm>
{typeof children === 'function' ? (
<FormRenderContent form={form} api={api}>
{children}
</FormRenderContent>
) : (
children
)}
</FormComponent>
</FormContext.Provider>
);
});
+232 -70
View File
@@ -20,8 +20,26 @@ For commercial licensing, please contact support@quantumnous.com
import React, { forwardRef } from 'react';
import * as Ant from 'antd';
import { controlSize, placement } from './controls';
import { paginationEvents, paginationShowTotal } from './pagination';
import {
centerPaginationEvents,
centerPaginationOptions,
isCenterPaginationScope,
paginationEvents,
paginationShowTotal,
} from './pagination';
import { overlayMaskClosable } from './overlayPolicy';
import './pagination.css';
import { useIsMobile } from '../../hooks/common/useIsMobile';
import { useConsolePage } from '../console/ConsoleContext';
import { toConsoleTableChange } from '../console/consoleTableAdapter';
import {
ConsoleAlert,
ConsoleCard,
ConsoleDrawer,
ConsoleModal,
ConsoleTable,
ConsoleTabs,
} from '../console/ConsolePrimitives';
export * from './controls';
export { Form, withField } from './form';
@@ -46,7 +64,15 @@ export const Layout = Object.assign(
},
);
export const InputGroup = Ant.Space.Compact;
export const Row = ({ type, ...props }) => <Ant.Row {...props} />;
export const Row = ({ type, gutter, ...props }) => {
const isSettings = useConsolePage()?.page.key === 'setting';
return (
<Ant.Row
{...props}
gutter={isSettings ? [24, Array.isArray(gutter) ? gutter[1] : 0] : gutter}
/>
);
};
export const Icon = ({ svg, size, ...props }) => (
<span {...props} className={`anticon ${props.className || ''}`}>
{svg}
@@ -98,8 +124,9 @@ export const Card = forwardRef(function Card(
},
ref,
) {
const Component = useConsolePage() ? ConsoleCard : Ant.Card;
return (
<Ant.Card
<Component
{...props}
ref={ref}
variant={
@@ -118,7 +145,7 @@ export const Card = forwardRef(function Card(
>
{props.children}
{footer && <div className='ui-card-footer'>{footer}</div>}
</Ant.Card>
</Component>
);
});
export const Space = ({ spacing, vertical, size, ...props }) => (
@@ -136,37 +163,43 @@ export const Divider = ({ margin, align, layout, style, ...props }) => (
style={{ margin, ...style }}
/>
);
export const Tag = ({
size,
prefixIcon,
suffixIcon,
shape,
clickable,
type,
prefix,
children,
color,
...props
}) => (
<Ant.Tag
{...props}
color={
['white', 'grey', 'light-blue', 'light-green'].includes(color)
? {
white: 'default',
grey: 'default',
'light-blue': 'blue',
'light-green': 'green',
}[color]
: color
}
icon={prefixIcon ?? props.icon}
>
{prefix}
{children}
{suffixIcon}
</Ant.Tag>
);
export const Tag = forwardRef(function Tag(
{
size,
prefixIcon,
suffixIcon,
shape,
clickable,
type,
prefix,
children,
color,
...props
},
ref,
) {
return (
<Ant.Tag
{...props}
ref={ref}
color={
['white', 'grey', 'light-blue', 'light-green'].includes(color)
? {
white: 'default',
grey: 'default',
'light-blue': 'blue',
'light-green': 'green',
}[color]
: color
}
icon={prefixIcon ?? props.icon}
>
{prefix}
{children}
{suffixIcon}
</Ant.Tag>
);
});
export const Avatar = Object.assign(
function Avatar({ color, size, shape, ...props }) {
const mapped = {
@@ -246,8 +279,13 @@ export function Table({
expandRowByClick,
pagination,
size,
onChange,
...props
}) {
const consolePage = useConsolePage();
const BaseTable = consolePage ? ConsoleTable : Ant.Table;
const unified = Boolean(pagination) && isCenterPaginationScope();
const Component = unified ? CenterPaginatedTable : BaseTable;
const expandable = expandedRowRender
? {
expandedRowRender,
@@ -258,10 +296,22 @@ export function Table({
}
: undefined;
return (
<Ant.Table
<Component
{...props}
{...(unified
? { component: BaseTable, legacyPagination: pagination }
: {})}
size={controlSize(size)}
locale={{ emptyText: empty ?? emptyText }}
onChange={
consolePage && onChange
? (...args) => onChange(toConsoleTableChange(...args))
: onChange
}
locale={
empty !== undefined || emptyText !== undefined
? { emptyText: empty ?? emptyText }
: undefined
}
expandable={expandable}
pagination={
pagination === false
@@ -280,6 +330,67 @@ export function Table({
/>
);
}
function CenterPaginatedTable({
component: Component,
legacyPagination,
...props
}) {
const isMobile = useIsMobile();
const config = legacyPagination;
const local = config.total === undefined;
const [localPage, setLocalPage] = React.useState(config.currentPage ?? 1);
const [localSize, setLocalSize] = React.useState(config.pageSize ?? 10);
const pageSize =
local && !config.onPageSizeChange ? localSize : (config.pageSize ?? 10);
const total = config.total ?? props.dataSource?.length ?? 0;
const current = Math.min(
config.currentPage ?? config.current ?? localPage,
Math.max(1, Math.ceil(total / pageSize)),
);
const events = centerPaginationEvents({
...config,
pageSize,
...(local && !config.onPageSizeChange && !config.onShowSizeChange
? {
onPageSizeChange: (size) => {
config.onPageChange?.(1);
config.onChange?.(1, size);
},
}
: {}),
});
React.useEffect(() => {
const requested = config.currentPage ?? config.current;
if (!props.loading && requested !== undefined && requested > current) {
config.onPageChange?.(current);
config.onChange?.(current, pageSize);
}
}, [current, pageSize, props.loading, config]);
return (
<Component
{...props}
pagination={{
...centerPaginationOptions(config, isMobile),
showSizeChanger: Boolean(
local ||
config.onPageSizeChange ||
config.onShowSizeChange ||
config.onChange,
),
current,
pageSize,
onShowSizeChange: undefined,
onChange: (page, size) => {
setLocalPage(size === pageSize ? page : 1);
setLocalSize(size);
events.onChange(page, size);
},
}}
/>
);
}
export function Pagination({
currentPage,
onPageChange,
@@ -290,20 +401,48 @@ export function Pagination({
showTotal,
...props
}) {
const isMobile = useIsMobile();
const unified = isCenterPaginationScope();
const { onChange: onAntChange, pageSize: configuredSize = 10 } = props;
const config = {
...props,
currentPage,
onPageChange,
onPageSizeChange,
preventPageChangeOnPageSizeChange,
};
const requestedPage = currentPage ?? props.current;
const current =
unified && props.total !== undefined && requestedPage !== undefined
? Math.min(
requestedPage,
Math.max(1, Math.ceil(props.total / configuredSize)),
)
: requestedPage;
React.useEffect(() => {
if (unified && requestedPage !== undefined && requestedPage > current) {
onPageChange?.(current);
onAntChange?.(current, configuredSize);
}
}, [
unified,
requestedPage,
current,
onPageChange,
onAntChange,
configuredSize,
]);
return (
<Ant.Pagination
{...props}
current={currentPage ?? props.current}
{...paginationEvents({
...props,
currentPage,
onPageChange,
onPageSizeChange,
preventPageChangeOnPageSizeChange,
})}
current={current}
{...(unified ? centerPaginationEvents(config) : paginationEvents(config))}
pageSizeOptions={pageSizeOpts ?? props.pageSizeOptions}
size={size === 'small' ? 'small' : 'default'}
showTotal={paginationShowTotal(showTotal)}
{...(unified
? centerPaginationOptions({ className: props.className }, isMobile)
: {})}
/>
);
}
@@ -321,6 +460,7 @@ export const Tabs = Object.assign(
keepDOM = true,
...props
}) {
const Component = useConsolePage() ? ConsoleTabs : Ant.Tabs;
const items =
tabList?.map((tab) => ({ ...tab, key: tab.itemKey ?? tab.key })) ||
React.Children.toArray(children)
@@ -334,7 +474,7 @@ export const Tabs = Object.assign(
destroyOnHidden: keepDOM === false,
}));
return (
<Ant.Tabs
<Component
{...props}
size={controlSize(size)}
type={type === 'card' ? 'card' : 'line'}
@@ -489,17 +629,23 @@ export const Banner = ({
closeIcon,
children,
...props
}) => (
<Ant.Alert
{...props}
message={title}
type={type === 'danger' ? 'error' : type}
showIcon
closable={!!closeIcon}
action={children}
/>
);
export const Alert = Ant.Alert;
}) => {
const Component = useConsolePage() ? ConsoleAlert : Ant.Alert;
return (
<Component
{...props}
message={title}
type={type === 'danger' ? 'error' : type}
showIcon
closable={!!closeIcon}
action={children}
/>
);
};
export const Alert = (props) => {
const Component = useConsolePage() ? ConsoleAlert : Ant.Alert;
return <Component {...props} />;
};
function modalProps({
visible,
@@ -531,7 +677,8 @@ function modalProps({
}
export const Modal = Object.assign(
function Modal(props) {
return <Ant.Modal {...modalProps(props)} />;
const Component = useConsolePage() ? ConsoleModal : Ant.Modal;
return <Component {...modalProps(props)} />;
},
{
destroyAll: Ant.Modal.destroyAll,
@@ -556,17 +703,20 @@ export const SideSheet = ({
maskStyle,
destroyOnClose,
...props
}) => (
<Ant.Drawer
{...props}
maskClosable={overlayMaskClosable(props.maskClosable)}
open={visible}
onClose={onCancel}
keyboard={closeOnEsc}
destroyOnHidden={destroyOnClose}
styles={{ body: bodyStyle, header: headerStyle, mask: maskStyle }}
/>
);
}) => {
const Component = useConsolePage() ? ConsoleDrawer : Ant.Drawer;
return (
<Component
{...props}
maskClosable={overlayMaskClosable(props.maskClosable)}
open={visible}
onClose={onCancel}
keyboard={closeOnEsc}
destroyOnHidden={destroyOnClose}
styles={{ body: bodyStyle, header: headerStyle, mask: maskStyle }}
/>
);
};
export const Image = Ant.Image;
export const ImagePreview = ({
src,
@@ -666,7 +816,19 @@ export const Dropdown = Object.assign(
return (
<Ant.Dropdown
{...props}
menu={menu || { items: menuItems(render) }}
menu={
Array.isArray(menu)
? {
items: menu.map(({ node, name, type, ...item }, index) => ({
...item,
key: item.key ?? index,
label: item.label ?? name,
type: node === 'divider' ? 'divider' : undefined,
danger: item.danger ?? type === 'danger',
})),
}
: menu || { items: menuItems(render) }
}
placement={placement(position)}
trigger={[
trigger ||
+15
View File
@@ -0,0 +1,15 @@
/* Keep the requested mobile controls visible below Ant's default breakpoint. */
@media (max-width: 767px) {
.center-pagination.ant-pagination {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
row-gap: 8px;
}
.center-pagination.ant-pagination .ant-pagination-options {
display: inline-flex;
align-items: center;
margin-inline-start: 8px;
}
}
+34
View File
@@ -17,6 +17,40 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import i18next from 'i18next';
export const isCenterPaginationScope = () =>
typeof window !== 'undefined' &&
/^\/(console|org)(\/|$)/.test(window.location?.pathname || '');
export const centerPaginationOptions = (config, isMobile = false) => ({
...config,
className: ['center-pagination', config.className].filter(Boolean).join(' '),
size: 'small',
showSizeChanger: true,
showQuickJumper: isMobile,
pageSizeOptions: [10, 20, 50, 100],
showTotal: (total) => i18next.t('共 {{total}} 条', { total }),
});
// Ant emits both size and page notifications for one resize. Dispatch one request.
export function centerPaginationEvents(config) {
const { onPageChange, onPageSizeChange, onChange, onShowSizeChange } = config;
return {
onChange(page, size) {
if (size !== (config.pageSize ?? 10)) {
if (onPageSizeChange) onPageSizeChange(size);
else if (onShowSizeChange) onShowSizeChange(1, size);
else onChange?.(1, size);
return;
}
onPageChange?.(page);
onChange?.(page, size);
},
onShowSizeChange: undefined,
};
}
// Legacy pagination accepts a boolean; Ant Design calls a renderer when enabled.
export const paginationShowTotal = (showTotal) =>
showTotal === true ? (total) => `${total}` : showTotal;