feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
+232
-70
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user