更新 Schema

This commit is contained in:
2betop 2020-09-09 15:58:05 +08:00
parent 4341bebf91
commit 7dd979981f
6 changed files with 221 additions and 48 deletions

View File

@ -15,6 +15,8 @@ import {CollapseSchema} from './renderers/Collapse';
import {ColorSchema} from './renderers/Color';
import {ContainerSchema} from './renderers/Container';
import {CRUDSchema} from './renderers/CRUD';
import {DateSchema} from './renderers/Date';
import {DividerSchema} from './renderers/Divider';
// 每加个类型,这补充一下。
export type SchemaType =
@ -37,7 +39,11 @@ export type SchemaType =
| 'collapse'
| 'color'
| 'container'
| 'crud';
| 'crud'
| 'date'
| 'datetime'
| 'time'
| 'divider';
export type SchemaObject =
| PageSchema
@ -56,7 +62,9 @@ export type SchemaObject =
| CollapseSchema
| ColorSchema
| ContainerSchema
| CRUDSchema;
| CRUDSchema
| DateSchema
| DividerSchema;
export type SchemaCollection =
| SchemaObject

View File

@ -104,7 +104,7 @@ export interface ButtonSchema extends BaseSchema {
/**
*
*/
activeClassName: string;
activeClassName?: string;
/**
*
@ -128,8 +128,7 @@ export interface AjaxActionSchema extends ButtonSchema {
*/
api: SchemaApi;
// todo
feedback?: any;
feedback?: DialogSchema;
reload?: SchemaReload;
redirect?: string;
@ -158,8 +157,7 @@ export interface DialogActionSchema extends ButtonSchema {
*/
actionType: 'dialog';
// todo
dialog: any;
dialog: DialogSchema;
/**
*
@ -174,8 +172,10 @@ export interface DrawerActionSchema extends ButtonSchema {
*
*/
actionType: 'drawer';
// todo
drawer: any;
/**
*
*/
drawer: DrawerSchema;
/**
*
@ -284,6 +284,8 @@ import {
SchemaTooltip,
SchemaTpl
} from '../Schema';
import {DialogSchema} from './Dialog';
import {DrawerSchema} from './Drawer';
export interface ActionProps
extends ButtonSchema,

View File

@ -1,16 +1,46 @@
import React from 'react';
import {Renderer, RendererProps} from '../factory';
import moment from 'moment';
import {BaseSchema} from '../Schema';
export interface DateProps extends RendererProps {
className?: string;
placeholder?: string;
/**
* Date
* https://baidu.gitee.io/amis/docs/components/date
*/
export interface DateSchema extends BaseSchema {
/**
*
*/
type: 'date' | 'datetime' | 'time';
/**
* moment
*/
format?: string;
/**
*
*/
placeholder?: string;
/**
* moment
*/
valueFormat?: string;
/**
* 1
*/
fromNow?: boolean;
/**
* 1
*/
updateFrequency?: number;
}
export interface DateProps extends RendererProps, DateSchema {}
export interface DateState {
random?: number;
}
@ -18,7 +48,10 @@ export interface DateState {
export class DateField extends React.Component<DateProps, DateState> {
refreshInterval: NodeJS.Timeout;
static defaultProps: Partial<DateProps> = {
static defaultProps: Pick<
DateProps,
'placeholder' | 'format' | 'valueFormat' | 'fromNow' | 'updateFrequency'
> = {
placeholder: '-',
format: 'YYYY-MM-DD',
valueFormat: 'X',

View File

@ -12,11 +12,75 @@ import {ModalStore, IModalStore} from '../store/modal';
import {findDOMNode} from 'react-dom';
import {Spinner} from '../components';
import {IServiceStore} from '../store/service';
import {
BaseSchema,
SchemaClassName,
SchemaCollection,
SchemaName,
SchemaObject,
SchemaTpl
} from '../Schema';
import {ActionSchema} from './Action';
export interface DialogProps extends RendererProps {
title?: string; // 标题
size?: 'md' | 'lg' | 'sm' | 'xl' | 'full';
/**
* Dialog
* https://baidu.gitee.io/amis/docs/components/dialog
*/
export interface DialogSchema extends Omit<BaseSchema, 'type'> {
/**
*
*/
actions?: Array<ActionSchema>;
/**
*
*/
body?: SchemaCollection;
/**
* Body className
*/
bodyClassName?: SchemaClassName;
/**
* ESC Dialog
*/
closeOnEsc?: boolean;
name?: SchemaName;
/**
* Dialog
*/
size?: 'xs' | 'sm' | 'md' | 'lg' | 'full';
/**
* title
*/
title?: SchemaTpl | SchemaObject;
header?: SchemaTpl | SchemaObject;
headerClassName?: SchemaClassName;
footer?: SchemaTpl | SchemaObject;
/**
*
*/
confirm?: boolean;
/**
*
*/
showCloseButton?: boolean;
/**
*
*/
showErrorMsg?: boolean;
}
export interface DialogProps extends RendererProps, DialogSchema {
onClose: () => void;
onConfirm: (
values: Array<object>,
@ -26,18 +90,9 @@ export interface DialogProps extends RendererProps {
) => void;
children?: React.ReactNode | ((props?: any) => React.ReactNode);
store: IModalStore;
className?: string;
header?: SchemaNode;
body?: SchemaNode;
headerClassName?: string;
bodyClassName?: string;
footer?: SchemaNode;
confirm?: boolean;
show?: boolean;
lazyRender?: boolean;
wrapperComponent: React.ReactType;
showCloseButton?: boolean;
showErrorMsg?: boolean;
wrapperComponent: React.ElementType;
}
export interface DialogState {
@ -122,14 +177,14 @@ export default class Dialog extends React.Component<DialogProps, DialogState> {
this.isDead = true;
}
buildActions(): Array<Action> {
buildActions(): Array<ActionSchema> {
const {actions, confirm, translate: __} = this.props;
if (typeof actions !== 'undefined') {
return actions;
}
let ret: Array<Action> = [];
let ret: Array<ActionSchema> = [];
ret.push({
type: 'button',
actionType: 'cancel',

View File

@ -1,13 +1,18 @@
import React from 'react';
import {Renderer, RendererProps} from '../factory';
import {ServiceStore, IServiceStore} from '../store/service';
import {filter} from '../utils/tpl';
import cx from 'classnames';
import {BaseSchema} from '../Schema';
export interface DividerProps extends RendererProps {
lineStyle: 'dashed' | 'solid';
/**
* Divider 线
* https://baidu.gitee.io/amis/docs/components/divider
*/
export interface DividerSchema extends BaseSchema {
type: 'divider';
lineStyle?: 'dashed' | 'solid';
}
export interface DividerProps extends RendererProps, DividerSchema {}
export default class Divider extends React.Component<DividerProps, object> {
static defaultProps: Pick<DividerProps, 'className' | 'lineStyle'> = {
className: '',

View File

@ -11,12 +11,90 @@ import {IModalStore, ModalStore} from '../store/modal';
import {filter} from '../utils/tpl';
import {Spinner} from '../components';
import {IServiceStore} from '../store/service';
import {
BaseSchema,
SchemaClassName,
SchemaCollection,
SchemaName,
SchemaObject,
SchemaTpl
} from '../Schema';
import {ActionSchema} from './Action';
export interface DrawerProps extends RendererProps {
title?: string; // 标题
size?: 'md' | 'lg' | 'xs' | 'sm';
position?: 'left' | 'right' | 'top' | 'bottom';
/**
* Drawer
* https://baidu.gitee.io/amis/docs/components/drawer
*/
export interface DrawerSchema extends Omit<BaseSchema, 'type'> {
/**
*
*/
actions?: Array<ActionSchema>;
/**
*
*/
body?: SchemaCollection;
/**
* Body className
*/
bodyClassName?: SchemaClassName;
/**
* ESC Dialog
*/
closeOnEsc?: boolean;
name?: SchemaName;
/**
* Dialog
*/
size?: 'xs' | 'sm' | 'md' | 'lg' | 'full';
/**
* title
*/
title?: SchemaTpl | SchemaObject;
/**
*
*/
position?: 'left' | 'right' | 'top' | 'bottom';
/**
*
*/
header?: SchemaCollection;
/**
*
*/
footer?: SchemaCollection;
/**
*
*/
confirm?: boolean;
/**
*
*/
resizable?: boolean;
/**
*
*/
overlay?: boolean;
/**
*
*/
closeOnOutside?: boolean;
}
export interface DrawerProps extends RendererProps, DrawerSchema {
onClose: () => void;
onConfirm: (
values: Array<object>,
@ -26,16 +104,8 @@ export interface DrawerProps extends RendererProps {
) => void;
children?: React.ReactNode | ((props?: any) => React.ReactNode);
store: IModalStore;
className?: string;
header?: SchemaNode;
body?: SchemaNode;
bodyClassName?: string;
footer?: SchemaNode;
confirm?: boolean;
show?: boolean;
resizable?: boolean;
overlay?: boolean;
closeOnOutside?: boolean;
drawerContainer?: () => HTMLElement;
}
@ -113,14 +183,14 @@ export default class Drawer extends React.Component<DrawerProps, object> {
this.reaction && this.reaction();
}
buildActions(): Array<Action> {
buildActions(): Array<ActionSchema> {
const {actions, confirm, translate: __} = this.props;
if (typeof actions !== 'undefined') {
return actions;
}
let ret: Array<Action> = [];
let ret: Array<ActionSchema> = [];
ret.push({
type: 'button',
actionType: 'close',