feat: 1.升级 Ant Design Ui 至 v6 2. 修复企业充值金额输入限制
This commit is contained in:
@@ -39,6 +39,7 @@ import { useLocation } from 'react-router-dom';
|
||||
import { useActualTheme } from '../../context/Theme';
|
||||
import { normalizeLanguage } from '../../i18n/language';
|
||||
import { colord } from 'colord';
|
||||
import './antd-v5-compat.css';
|
||||
|
||||
// 与下方 Ant Design locale 一一对应的 dayjs 语言(未覆盖语言与 Ant Design 一样回退中文)。
|
||||
const DAYJS_LOCALES = {
|
||||
@@ -57,6 +58,17 @@ const DAYJS_LOCALES = {
|
||||
const PROTOTYPE_DARK_PRIMARY = '#d1963a';
|
||||
const PROTOTYPE_DARK_SEED = '#f2ad41';
|
||||
|
||||
// v5 used these shadows in both themes; v6 derives white shadows in dark mode.
|
||||
const v5ShadowTokens = {
|
||||
...Object.fromEntries(
|
||||
Object.entries(theme.getDesignToken()).filter(([name]) =>
|
||||
name.startsWith('boxShadow'),
|
||||
),
|
||||
),
|
||||
boxShadowTertiary:
|
||||
'0 1px 2px 0 rgba(0,0,0,0.03), 0 1px 6px -1px rgba(0,0,0,0.02), 0 2px 4px 0 rgba(0,0,0,0.02)',
|
||||
};
|
||||
|
||||
// 页面局部“品牌强调色”(原型 --brand):等于当前主题的种子色。
|
||||
// 浅色与自定义主色时即 colorPrimary;仅默认暗色主色 #d1963a 时回到原型种子 #f2ad41,
|
||||
// 保证浅色 / 深色 / 自定义主题色三态都只由主题 token 推导,不在页面里另写颜色。
|
||||
@@ -82,6 +94,7 @@ export const prototypeTheme = (dark) => ({
|
||||
};
|
||||
},
|
||||
token: {
|
||||
...v5ShadowTokens,
|
||||
colorPrimary: dark ? PROTOTYPE_DARK_PRIMARY : '#b96508',
|
||||
colorInfo: dark ? PROTOTYPE_DARK_PRIMARY : '#b96508',
|
||||
colorBgLayout: dark ? '#11151c' : '#f4f6f9',
|
||||
@@ -108,6 +121,13 @@ export const prototypeTheme = (dark) => ({
|
||||
},
|
||||
});
|
||||
|
||||
// Keep v5 tag borders and overlay masks while inheriting the existing theme.
|
||||
const v5ComponentDefaults = {
|
||||
tag: { variant: 'outlined' },
|
||||
modal: { mask: { blur: false } },
|
||||
drawer: { mask: { blur: false } },
|
||||
};
|
||||
|
||||
function TokenBridge() {
|
||||
const { token } = theme.useToken();
|
||||
useLayoutEffect(() => {
|
||||
@@ -249,14 +269,14 @@ export default function UiThemeProvider({ children }) {
|
||||
useEffect(() => {
|
||||
ConfigProvider.config({
|
||||
holderRender: (nodes) => (
|
||||
<ConfigProvider theme={config} locale={locale}>
|
||||
<ConfigProvider {...v5ComponentDefaults} theme={config} locale={locale}>
|
||||
{nodes}
|
||||
</ConfigProvider>
|
||||
),
|
||||
});
|
||||
}, [config, locale]);
|
||||
return (
|
||||
<ConfigProvider theme={config} locale={locale}>
|
||||
<ConfigProvider {...v5ComponentDefaults} theme={config} locale={locale}>
|
||||
<App>
|
||||
<TokenBridge />
|
||||
{children}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/* Keep v5 spacing at component specificity so page overrides still take priority. */
|
||||
:where(body[data-ui-scope='admin']) .ant-tag {
|
||||
margin-inline-end: 8px;
|
||||
}
|
||||
|
||||
/* The v6 suffix layout makes automatic pagination selects 3px narrower. */
|
||||
:where(body[data-ui-scope='admin'])
|
||||
.ant-pagination-options-size-changer
|
||||
.ant-select-suffix {
|
||||
margin-inline-start: 3px;
|
||||
}
|
||||
|
||||
/* v6 changed the required-mark font; retain v5 label metrics and form spacing. */
|
||||
body[data-ui-scope='admin']
|
||||
.ant-form-item-label
|
||||
> label.ant-form-item-required::before {
|
||||
font-family: SimSun, sans-serif;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ export const Button = forwardRef(function Button(
|
||||
danger={danger}
|
||||
size={useConsoleControlSize(size)}
|
||||
shape={circle ? 'circle' : undefined}
|
||||
iconPosition={iconPosition === 'right' ? 'end' : 'start'}
|
||||
iconPlacement={iconPosition === 'right' ? 'end' : 'start'}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -193,6 +193,10 @@ export function Select({
|
||||
prefix,
|
||||
dropdownStyle,
|
||||
dropdownClassName,
|
||||
autoClearSearchValue,
|
||||
onSearch,
|
||||
searchValue,
|
||||
filterSort,
|
||||
...props
|
||||
}) {
|
||||
const canSearch =
|
||||
@@ -210,28 +214,39 @@ export function Select({
|
||||
}
|
||||
styles={{
|
||||
...props.styles,
|
||||
popup: { ...props.styles?.popup, root: dropdownStyle },
|
||||
popup: {
|
||||
...props.styles?.popup,
|
||||
root: dropdownStyle ?? props.styles?.popup?.root,
|
||||
},
|
||||
}}
|
||||
classNames={{
|
||||
...props.classNames,
|
||||
popup: { ...props.classNames?.popup, root: dropdownClassName },
|
||||
popup: {
|
||||
...props.classNames?.popup,
|
||||
root: dropdownClassName ?? props.classNames?.popup?.root,
|
||||
},
|
||||
}}
|
||||
options={optionList || options}
|
||||
allowClear={showClear ?? props.allowClear}
|
||||
showSearch={canSearch}
|
||||
filterOption={
|
||||
remote
|
||||
showSearch={{
|
||||
enabled: canSearch,
|
||||
filterOption: remote
|
||||
? false
|
||||
: typeof filter === 'function'
|
||||
? filter
|
||||
: filter === false
|
||||
? false
|
||||
: undefined
|
||||
}
|
||||
optionFilterProp='label'
|
||||
: undefined,
|
||||
optionFilterProp: 'label',
|
||||
...(typeof props.showSearch === 'object' ? props.showSearch : {}),
|
||||
...(autoClearSearchValue !== undefined ? { autoClearSearchValue } : {}),
|
||||
...(onSearch !== undefined ? { onSearch } : {}),
|
||||
...(searchValue !== undefined ? { searchValue } : {}),
|
||||
...(filterSort !== undefined ? { filterSort } : {}),
|
||||
}}
|
||||
notFoundContent={emptyContent}
|
||||
status={statusOf(validateStatus)}
|
||||
onOpenChange={onDropdownVisibleChange}
|
||||
onOpenChange={onDropdownVisibleChange ?? props.onOpenChange}
|
||||
prefix={prefix}
|
||||
popupRender={
|
||||
outerBottomSlot || innerBottomSlot
|
||||
@@ -348,7 +363,7 @@ export function Switch({
|
||||
{...props}
|
||||
checkedChildren={checkedText}
|
||||
unCheckedChildren={uncheckedText}
|
||||
size={size === 'small' ? 'small' : 'default'}
|
||||
size={size === 'small' ? 'small' : 'medium'}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -369,6 +384,8 @@ export function DatePicker({
|
||||
presets,
|
||||
size,
|
||||
inputReadOnly,
|
||||
dropdownClassName,
|
||||
dropdownStyle,
|
||||
...props
|
||||
}) {
|
||||
const range = type?.toLowerCase().includes('range');
|
||||
@@ -377,6 +394,20 @@ export function DatePicker({
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
classNames={{
|
||||
...props.classNames,
|
||||
popup: {
|
||||
...props.classNames?.popup,
|
||||
root: dropdownClassName ?? props.classNames?.popup?.root,
|
||||
},
|
||||
}}
|
||||
styles={{
|
||||
...props.styles,
|
||||
popup: {
|
||||
...props.styles?.popup,
|
||||
root: dropdownStyle ?? props.styles?.popup?.root,
|
||||
},
|
||||
}}
|
||||
{...(value !== undefined ? { value: convert(value) } : {})}
|
||||
defaultValue={
|
||||
defaultValue === undefined ? undefined : convert(defaultValue)
|
||||
@@ -426,11 +457,13 @@ export function TreeSelect({
|
||||
{...props}
|
||||
treeData={treeNodes(treeData)}
|
||||
allowClear={showClear}
|
||||
showSearch={!!filterTreeNode}
|
||||
treeNodeFilterProp='title'
|
||||
filterTreeNode={
|
||||
typeof filterTreeNode === 'function' ? filterTreeNode : undefined
|
||||
}
|
||||
showSearch={{
|
||||
enabled: !!filterTreeNode,
|
||||
filterTreeNode:
|
||||
typeof filterTreeNode === 'function' ? filterTreeNode : undefined,
|
||||
treeNodeFilterProp: 'title',
|
||||
...(typeof props.showSearch === 'object' ? props.showSearch : {}),
|
||||
}}
|
||||
treeDefaultExpandAll={expandAll}
|
||||
/>
|
||||
);
|
||||
@@ -461,12 +494,19 @@ export function AutoComplete({
|
||||
renderItem,
|
||||
emptyContent,
|
||||
onEnterPress,
|
||||
onSearch,
|
||||
showSearch,
|
||||
size,
|
||||
...props
|
||||
}) {
|
||||
return (
|
||||
<AntAutoComplete
|
||||
{...props}
|
||||
showSearch={
|
||||
onSearch
|
||||
? { ...(typeof showSearch === 'object' ? showSearch : {}), onSearch }
|
||||
: showSearch
|
||||
}
|
||||
options={data?.map((item) =>
|
||||
typeof item === 'string' ? { value: item } : item,
|
||||
)}
|
||||
|
||||
+55
-23
@@ -27,7 +27,7 @@ import {
|
||||
paginationEvents,
|
||||
paginationShowTotal,
|
||||
} from './pagination';
|
||||
import { overlayMaskClosable } from './overlayPolicy';
|
||||
import { overlayMask } from './overlayPolicy';
|
||||
import './pagination.css';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import { useConsolePage } from '../console/ConsoleContext';
|
||||
@@ -132,7 +132,7 @@ export const Card = forwardRef(function Card(
|
||||
variant={
|
||||
props.variant ?? (bordered === false ? 'borderless' : 'outlined')
|
||||
}
|
||||
size={size === 'small' ? 'small' : 'default'}
|
||||
size={size === 'small' ? 'small' : 'medium'}
|
||||
title={
|
||||
props.title ??
|
||||
header?.title ??
|
||||
@@ -141,7 +141,7 @@ export const Card = forwardRef(function Card(
|
||||
: undefined)
|
||||
}
|
||||
extra={headerExtraContent ?? header?.extra}
|
||||
styles={{ header: headerStyle, body: bodyStyle }}
|
||||
styles={{ header: headerStyle, body: bodyStyle, ...props.styles }}
|
||||
>
|
||||
{props.children}
|
||||
{footer && <div className='ui-card-footer'>{footer}</div>}
|
||||
@@ -151,15 +151,15 @@ export const Card = forwardRef(function Card(
|
||||
export const Space = ({ spacing, vertical, size, ...props }) => (
|
||||
<Ant.Space
|
||||
{...props}
|
||||
direction={vertical ? 'vertical' : 'horizontal'}
|
||||
orientation={vertical ? 'vertical' : 'horizontal'}
|
||||
size={spacing === 'medium' ? 'middle' : (spacing ?? size)}
|
||||
/>
|
||||
);
|
||||
export const Divider = ({ margin, align, layout, style, ...props }) => (
|
||||
<Ant.Divider
|
||||
{...props}
|
||||
orientation={align}
|
||||
type={layout === 'vertical' ? 'vertical' : 'horizontal'}
|
||||
titlePlacement={align}
|
||||
orientation={layout === 'vertical' ? 'vertical' : 'horizontal'}
|
||||
style={{ margin, ...style }}
|
||||
/>
|
||||
);
|
||||
@@ -174,6 +174,7 @@ export const Tag = forwardRef(function Tag(
|
||||
prefix,
|
||||
children,
|
||||
color,
|
||||
bordered,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
@@ -182,6 +183,7 @@ export const Tag = forwardRef(function Tag(
|
||||
<Ant.Tag
|
||||
{...props}
|
||||
ref={ref}
|
||||
variant={props.variant ?? (bordered === false ? 'filled' : 'outlined')}
|
||||
color={
|
||||
['white', 'grey', 'light-blue', 'light-green'].includes(color)
|
||||
? {
|
||||
@@ -231,6 +233,8 @@ export const Spin = ({
|
||||
style,
|
||||
className,
|
||||
'data-testid': testId,
|
||||
tip,
|
||||
wrapperClassName,
|
||||
...props
|
||||
}) =>
|
||||
children ? (
|
||||
@@ -239,14 +243,20 @@ export const Spin = ({
|
||||
className={`ui-spin-shell ${className || ''}`}
|
||||
data-testid={testId}
|
||||
>
|
||||
<Ant.Spin {...props} size={controlSize(size)}>
|
||||
<Ant.Spin
|
||||
{...props}
|
||||
description={tip ?? props.description}
|
||||
classNames={{ root: wrapperClassName, ...props.classNames }}
|
||||
size={size === 'default' ? 'medium' : size}
|
||||
>
|
||||
<div style={childStyle}>{children}</div>
|
||||
</Ant.Spin>
|
||||
</div>
|
||||
) : (
|
||||
<Ant.Spin
|
||||
{...props}
|
||||
size={controlSize(size)}
|
||||
size={size === 'default' ? 'medium' : size}
|
||||
description={tip ?? props.description}
|
||||
style={style}
|
||||
className={className}
|
||||
data-testid={testId}
|
||||
@@ -556,8 +566,8 @@ export const Timeline = Object.assign(
|
||||
.filter(React.isValidElement)
|
||||
.map((child) => ({
|
||||
color: child.props.type === 'ongoing' ? 'blue' : undefined,
|
||||
label: child.props.time,
|
||||
children: (
|
||||
title: child.props.time,
|
||||
content: (
|
||||
<>
|
||||
{child.props.children}
|
||||
{child.props.extra}
|
||||
@@ -634,7 +644,7 @@ export const Banner = ({
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
message={title}
|
||||
title={title}
|
||||
type={type === 'danger' ? 'error' : type}
|
||||
showIcon
|
||||
closable={!!closeIcon}
|
||||
@@ -642,9 +652,9 @@ export const Banner = ({
|
||||
/>
|
||||
);
|
||||
};
|
||||
export const Alert = (props) => {
|
||||
export const Alert = ({ message, ...props }) => {
|
||||
const Component = useConsolePage() ? ConsoleAlert : Ant.Alert;
|
||||
return <Component {...props} />;
|
||||
return <Component {...props} title={props.title ?? message} />;
|
||||
};
|
||||
|
||||
function modalProps({
|
||||
@@ -659,20 +669,23 @@ function modalProps({
|
||||
type,
|
||||
bodyStyle,
|
||||
maskStyle,
|
||||
mask,
|
||||
maskClosable,
|
||||
destroyOnClose,
|
||||
...props
|
||||
}) {
|
||||
return {
|
||||
...props,
|
||||
maskClosable: overlayMaskClosable(props.maskClosable),
|
||||
mask: overlayMask(mask, maskClosable),
|
||||
open: visible,
|
||||
title: header === null ? null : (props.title ?? header),
|
||||
keyboard: closeOnEsc,
|
||||
forceRender: lazyRender === false,
|
||||
destroyOnHidden: keepDOM === false || destroyOnClose,
|
||||
destroyOnHidden:
|
||||
keepDOM === false || destroyOnClose || props.destroyOnHidden,
|
||||
width: size === 'full-width' ? '100%' : props.width,
|
||||
okButtonProps: { danger: okType === 'danger', ...props.okButtonProps },
|
||||
styles: { body: bodyStyle, mask: maskStyle },
|
||||
styles: { body: bodyStyle, mask: maskStyle, ...props.styles },
|
||||
};
|
||||
}
|
||||
export const Modal = Object.assign(
|
||||
@@ -702,18 +715,31 @@ export const SideSheet = ({
|
||||
headerStyle,
|
||||
maskStyle,
|
||||
destroyOnClose,
|
||||
mask,
|
||||
maskClosable,
|
||||
width,
|
||||
height,
|
||||
...props
|
||||
}) => {
|
||||
const Component = useConsolePage() ? ConsoleDrawer : Ant.Drawer;
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
maskClosable={overlayMaskClosable(props.maskClosable)}
|
||||
mask={overlayMask(mask, maskClosable)}
|
||||
size={
|
||||
props.size ??
|
||||
(['top', 'bottom'].includes(props.placement) ? height : width)
|
||||
}
|
||||
open={visible}
|
||||
onClose={onCancel}
|
||||
keyboard={closeOnEsc}
|
||||
destroyOnHidden={destroyOnClose}
|
||||
styles={{ body: bodyStyle, header: headerStyle, mask: maskStyle }}
|
||||
destroyOnHidden={destroyOnClose ?? props.destroyOnHidden}
|
||||
styles={{
|
||||
body: bodyStyle,
|
||||
header: headerStyle,
|
||||
mask: maskStyle,
|
||||
...props.styles,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -727,7 +753,12 @@ export const ImagePreview = ({
|
||||
}) => (
|
||||
<Ant.Image.PreviewGroup
|
||||
items={Array.isArray(src) ? src : [src]}
|
||||
preview={{ visible, onVisibleChange, current: currentIndex, onChange }}
|
||||
preview={{
|
||||
open: visible,
|
||||
onOpenChange: onVisibleChange,
|
||||
current: currentIndex,
|
||||
onChange,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -747,11 +778,12 @@ Toast.destroyAll = Ant.message.destroy;
|
||||
export const Notification = Object.fromEntries(
|
||||
['success', 'info', 'warning', 'error', 'open'].map((method) => [
|
||||
method,
|
||||
(config) =>
|
||||
({ title, message, content, description, btn, actions, ...config }) =>
|
||||
Ant.notification[method]({
|
||||
...config,
|
||||
message: config.title ?? config.message,
|
||||
description: config.content ?? config.description,
|
||||
title: title ?? message,
|
||||
description: content ?? description,
|
||||
actions: actions ?? btn,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -32,3 +32,16 @@ export function overlayMaskClosable(
|
||||
pathname.startsWith('/user-center/');
|
||||
return scoped ? true : configured;
|
||||
}
|
||||
|
||||
export function overlayMask(mask, maskClosable, pathname) {
|
||||
const config =
|
||||
typeof mask === 'object' && mask !== null
|
||||
? mask
|
||||
: mask === undefined
|
||||
? {}
|
||||
: { enabled: mask };
|
||||
return {
|
||||
...config,
|
||||
closable: overlayMaskClosable(config.closable ?? maskClosable, pathname),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user