补充Schema

This commit is contained in:
2betop 2020-09-10 12:16:33 +08:00
parent 3ce08784a4
commit 2cc0aaf2c6
18 changed files with 339 additions and 56 deletions

View File

@ -44,6 +44,7 @@ import {VBoxSchema} from './renderers/VBox';
import {VideoSchema} from './renderers/Video';
import {WizardSchema} from './renderers/Wizard';
import {WrapperSchema} from './renderers/Wrapper';
import {TableSchema} from './renderers/Table';
// 每加个类型,这补充一下。
export type SchemaType =
@ -95,6 +96,7 @@ export type SchemaType =
| 'service'
| 'status'
| 'switch'
| 'table'
| 'tabs'
| 'tasks'
| 'vbox'
@ -143,6 +145,7 @@ export type SchemaObject =
| ServiceSchema
| StatusSchema
| SwitchSchema
| TableSchema
| TabsSchema
| TasksSchema
| VBoxSchema

View File

@ -4,7 +4,8 @@ import Alert, {AlertProps} from '../components/Alert2';
import {BaseSchema, SchemaCollection} from '../Schema';
/**
* Alert https://baidu.gitee.io/amis/docs/components/alert
* Alert
* https://baidu.gitee.io/amis/docs/components/alert
*/
export interface AlertSchema extends BaseSchema {
/**

View File

@ -8,7 +8,8 @@ import {filter} from '../utils/tpl';
import {BaseSchema, SchemaUrlPath} from '../Schema';
/**
* Audio https://baidu.gitee.io/amis/docs/components/audio
* Audio
* https://baidu.gitee.io/amis/docs/components/audio
*/
export interface AudioSchema extends BaseSchema {
/**

View File

@ -5,7 +5,8 @@ import {BaseSchema, SchemaClassName, SchemaExpression} from '../Schema';
import {ActionSchema} from './Action';
/**
* Button Group https://baidu.gitee.io/amis/docs/components/button-group
* Button Group
* https://baidu.gitee.io/amis/docs/components/button-group
*/
export interface ButtonGroupSchema extends BaseSchema {
/**

View File

@ -4,7 +4,8 @@ import {BaseSchema} from '../Schema';
import {ActionSchema} from './Action';
/**
* Button Toolar https://baidu.gitee.io/amis/docs/components/button-toolbar
* Button Toolar
* https://baidu.gitee.io/amis/docs/components/button-toolbar
*/
export interface ButtonToolbarSchema extends BaseSchema {
/**

View File

@ -49,6 +49,7 @@ import {
import {ActionSchema} from './Action';
import {CardsSchema} from './Cards';
import {ListSchema} from './List';
import {TableSchema} from './Table';
export interface CRUDCommonSchema extends BaseSchema {
/**
@ -234,11 +235,15 @@ export type CRUDListSchema = CRUDCommonSchema & {
mode: 'list';
} & Omit<ListSchema, 'type'>;
export type CRUDTableSchem = CRUDCommonSchema & {
mode?: 'table';
} & Omit<TableSchema, 'type'>;
/**
* CRUD
* https://baidu.gitee.io/amis/docs/components/crud
*/
export type CRUDSchema = CRUDCardsSchema | CRUDListSchema; // todo
export type CRUDSchema = CRUDCardsSchema | CRUDListSchema | CRUDTableSchem;
export interface CRUDProps extends RendererProps, CRUDCommonSchema {
store: ICRUDStore;

View File

@ -8,10 +8,10 @@ import Checkbox from '../components/Checkbox';
import {IItem} from '../store/list';
import {padArr, isVisible, isDisabled, noop} from '../utils/helper';
import {resolveVariable} from '../utils/tpl-builtin';
import QuickEdit from './QuickEdit';
import PopOver from './PopOver';
import QuickEdit, {SchemaQuickEdit} from './QuickEdit';
import PopOver, {SchemaPopOver} from './PopOver';
import {TableCell} from './Table';
import Copyable from './Copyable';
import Copyable, {SchemaCopyable} from './Copyable';
import {Icon} from '../components/icons';
import {
BaseSchema,
@ -24,8 +24,36 @@ import {
} from '../Schema';
import {ActionSchema} from './Action';
export type CardBodyField = BaseSchema & {
/**
*
*/
label: string;
/**
*
*/
name?: string;
/**
*
*/
popOver?: SchemaPopOver;
/**
*
*/
quickEdit?: SchemaQuickEdit;
/**
*
*/
copyable?: SchemaCopyable;
};
/**
* Card https://baidu.gitee.io/amis/docs/components/card
* Card
* https://baidu.gitee.io/amis/docs/components/card
*/
export interface CardSchema extends BaseSchema {
/**
@ -110,7 +138,7 @@ export interface CardSchema extends BaseSchema {
/**
*
*/
body?: SchemaCollection; // todo 实际上应该只有固定的一些 field
body?: Array<CardBodyField>;
/**
*

View File

@ -26,7 +26,8 @@ import {
import {CardSchema} from './Card';
/**
* Cards https://baidu.gitee.io/amis/docs/components/card
* Cards
* https://baidu.gitee.io/amis/docs/components/card
*/
export interface CardsSchema extends BaseSchema {
/**

View File

@ -16,7 +16,8 @@ import {Icon} from '../components/icons';
import {BaseSchema, SchemaName, SchemaObject, SchemaTpl} from '../Schema';
/**
* Carousel https://baidu.gitee.io/amis/docs/components/carousel
* Carousel
* https://baidu.gitee.io/amis/docs/components/carousel
*/
export interface CarouselSchema extends BaseSchema {
/**

View File

@ -23,7 +23,8 @@ import {
import {ActionSchema} from './Action';
/**
* Chart https://baidu.gitee.io/amis/docs/components/carousel
* Chart
* https://baidu.gitee.io/amis/docs/components/carousel
*/
export interface ChartSchema extends BaseSchema {
/**

View File

@ -10,19 +10,26 @@ import hoistNonReactStatic from 'hoist-non-react-statics';
import Button from '../components/Button';
import {filter} from '../utils/tpl';
import {Icon} from '../components/icons';
import {SchemaIcon, SchemaTpl} from '../Schema';
export interface CopyableConfig {}
export interface SchemaCopyableObject {
/**
*
*/
icon?: SchemaIcon;
export interface CopyableConfig {
icon?: string;
content?: string;
[propName: string]: any;
/**
*
*/
content?: SchemaTpl;
}
export type SchemaCopyable = boolean | SchemaCopyableObject;
export interface CopyableProps extends RendererProps {
name?: string;
label?: string;
copyable: boolean | CopyableConfig;
copyable: SchemaCopyable;
}
export const HocCopyable = () => (Component: React.ComponentType<any>): any => {
@ -45,7 +52,8 @@ export const HocCopyable = () => (Component: React.ComponentType<any>): any => {
if (copyable && !noHoc) {
const content = filter(
(copyable as CopyableConfig).content || '${' + name + ' | raw }',
(copyable as SchemaCopyableObject).content ||
'${' + name + ' | raw }',
data
);
if (content) {

View File

@ -89,14 +89,9 @@ export type FormGroup = FormSchema & {
export type FormGroupNode = FormGroup | FormGroupArray;
export interface FormGroupArray extends Array<FormGroupNode> {}
export interface FormHorizontal {
leftFixed?: boolean | string;
left: string | number;
right: string | number;
offset: string | number;
}
export type FormHorizontal = FormSchemaHorizontal;
export interface FormProps extends RendererProps, FormSchema {
export interface FormProps extends RendererProps, Omit<FormSchema, 'mode'> {
data: any;
store: IFormStore;
wrapperComponent: React.ReactType;

View File

@ -17,11 +17,11 @@ import {
noop
} from '../utils/helper';
import {resolveVariable} from '../utils/tpl-builtin';
import QuickEdit from './QuickEdit';
import PopOver from './PopOver';
import QuickEdit, {SchemaQuickEdit} from './QuickEdit';
import PopOver, {SchemaPopOver} from './PopOver';
import Sortable from 'sortablejs';
import {TableCell} from './Table';
import Copyable from './Copyable';
import Copyable, {SchemaCopyable} from './Copyable';
import {Icon} from '../components/icons';
import {
BaseSchema,
@ -36,6 +36,33 @@ import {
import {ActionSchema} from './Action';
import {SchemaRemark} from './Remark';
export type ListBodyField = BaseSchema & {
/**
*
*/
label: string;
/**
*
*/
name?: string;
/**
*
*/
popOver?: SchemaPopOver;
/**
*
*/
quickEdit?: SchemaQuickEdit;
/**
*
*/
copyable?: SchemaCopyable;
};
export interface ListItemSchema extends Omit<BaseSchema, 'type'> {
actions?: Array<ActionSchema>;
@ -47,7 +74,7 @@ export interface ListItemSchema extends Omit<BaseSchema, 'type'> {
/**
*
*/
body?: SchemaCollection; // todo 实际上应该只有固定的一些 field
body?: Array<ListBodyField>;
/**
*

View File

@ -12,13 +12,28 @@ import {RootCloseWrapper} from 'react-overlays';
import PopOver, {Offset} from '../components/PopOver';
import Overlay from '../components/Overlay';
import {Icon} from '../components/icons';
import {SchemaCollection} from '../Schema';
export interface PopOverConfig {
saveImmediately?: boolean;
export interface SchemaPopOverObject {
/**
*
*/
className?: string;
/**
*
*/
mode?: 'dialog' | 'drawer' | 'popOver';
title?: string;
/**
*
*/
size?: 'sm' | 'md' | 'lg' | 'xl';
position:
/**
*
*/
position?:
| 'center'
| 'left-top'
| 'right-top'
@ -29,14 +44,29 @@ export interface PopOverConfig {
| 'fixed-right-top'
| 'fixed-left-bottom'
| 'fixed-right-bottom';
offset?: Offset;
[propName: string]: any;
/**
*
*/
offset?: {
top?: number;
left?: number;
};
/**
*
*/
title?: string;
body?: SchemaCollection;
}
export type SchemaPopOver = boolean | SchemaPopOverObject;
export interface PopOverProps extends RendererProps {
name?: string;
label?: string;
popOver: boolean | PopOverConfig;
popOver: boolean | SchemaPopOverObject;
onPopOverOpened: (popover: any) => void;
onPopOverClosed: (popover: any) => void;
}
@ -45,7 +75,7 @@ export interface PopOverState {
isOpened: boolean;
}
export const HocPopOver = (config: Partial<PopOverConfig> = {}) => (
export const HocPopOver = (config: Partial<SchemaPopOverObject> = {}) => (
Component: React.ComponentType<any>
): any => {
class PopOverComponent extends React.Component<PopOverProps, PopOverState> {
@ -136,8 +166,8 @@ export const HocPopOver = (config: Partial<PopOverConfig> = {}) => (
} = this.props;
if (
popOver &&
((popOver as PopOverConfig).mode === 'dialog' ||
(popOver as PopOverConfig).mode === 'drawer')
((popOver as SchemaPopOverObject).mode === 'dialog' ||
(popOver as SchemaPopOverObject).mode === 'drawer')
) {
return render('popover-detail', this.buildSchema(), {
show: true,
@ -147,14 +177,15 @@ export const HocPopOver = (config: Partial<PopOverConfig> = {}) => (
}
const content = render('popover-detail', this.buildSchema(), {
className: cx((popOver as PopOverConfig).className)
className: cx((popOver as SchemaPopOverObject).className)
}) as JSX.Element;
if (!popOverContainer) {
popOverContainer = () => findDOMNode(this);
}
const position = (popOver && (popOver as PopOverConfig).position) || '';
const position =
(popOver && (popOver as SchemaPopOverObject).position) || '';
const isFixed = /^fixed\-/.test(position);
return isFixed ? (
@ -179,7 +210,7 @@ export const HocPopOver = (config: Partial<PopOverConfig> = {}) => (
<PopOver
classPrefix={ns}
className={cx('PopOverAble-popover')}
offset={(popOver as PopOverConfig).offset}
offset={(popOver as SchemaPopOverObject).offset}
>
{content}
</PopOver>

View File

@ -18,8 +18,42 @@ import matches from 'dom-helpers/query/matches';
import Overlay from '../components/Overlay';
import PopOver from '../components/PopOver';
import {Icon} from '../components/icons';
import {FormControlSchema} from './Form/Item';
export interface QuickEditConfig {}
export type SchemaQuickEditObject =
/**
*
*/
| ({
/**
*
*/
saveImmediately?: boolean;
/**
*
*/
mode?: 'inline';
} & FormControlSchema)
/**
*
*/
| {
/**
*
*/
saveImmediately?: boolean;
/**
*
*/
mode?: 'inline';
controls: Array<FormControlSchema>;
};
export type SchemaQuickEdit = boolean | SchemaQuickEditObject;
export interface QuickEditConfig {
saveImmediately?: boolean;

View File

@ -52,7 +52,7 @@ export interface ServiceSchema extends BaseSchema {
*
* @deprecated api sendOn
*/
initFetchOn?: boolean;
initFetchOn?: SchemaExpression;
/**
* Schema api
@ -93,6 +93,10 @@ export interface ServiceSchema extends BaseSchema {
export interface ServiceProps extends RendererProps, ServiceSchema {
store: IServiceStore;
messages: {
fetchSuccess?: string;
fetchFailed?: string;
};
}
export default class Service extends React.Component<ServiceProps> {
timer: NodeJS.Timeout;
@ -127,9 +131,7 @@ export default class Service extends React.Component<ServiceProps> {
const props = this.props;
const store = props.store;
const {
messages: {fetchSuccess, fetchFailed}
} = props;
const {fetchSuccess, fetchFailed} = props.messages!;
isApiOutdated(prevProps.api, props.api, prevProps.data, props.data) &&
store

View File

@ -27,10 +27,148 @@ import {TableRow} from './TableRow';
import {HeadCellFilterDropDown} from './HeadCellFilterDropdown';
import {HeadCellSearchDropDown} from './HeadCellSearchDropdown';
import {TableContent} from './TableContent';
import {
BaseSchema,
SchemaClassName,
SchemaObject,
SchemaTokenizeableString
} from '../../Schema';
import {FormControlSchema, FormControlType} from '../Form/Item';
import {SchemaPopOver} from '../PopOver';
import {SchemaQuickEdit} from '../QuickEdit';
import {SchemaCopyable} from '../Copyable';
export interface Column {
type: string;
[propName: string]: any;
export type TableColumn = BaseSchema & {
/**
*
*/
label: string;
/**
*
*/
fixed?: 'left' | 'right' | 'none';
/**
*
*/
name?: string;
/**
*
*/
popOver?: SchemaPopOver;
/**
*
*/
quickEdit?: SchemaQuickEdit;
/**
*
*/
copyable?: SchemaCopyable;
/**
*
*/
sortable?: boolean;
/**
*
*/
toggled?: boolean;
/**
*
*/
width?: number | string;
/**
* footable 使
* *xssmmdlg指定 footable
*/
breakpoint?: '*' | 'xs' | 'sm' | 'md' | 'lg';
};
/**
* Table
* https://baidu.gitee.io/amis/docs/components/table
*/
export interface TableSchema extends BaseSchema {
/**
*
*/
type: 'table';
/**
*
*/
affixHeader?: boolean;
/**
*
*/
columns: Array<TableColumn>;
/**
* 5
*/
columnsTogglable?: boolean | 'auto';
/**
*
*/
footable?:
| boolean
| {
expand?: 'first' | 'all' | 'none';
};
/**
* CSS
*/
footerClassName?: SchemaClassName;
/**
* CSS
*/
headerClassName?: SchemaClassName;
/**
*
*/
placeholder?: string;
/**
*
*/
showFooter?: boolean;
/**
*
*/
showHeader?: boolean;
/**
*
*/
source?: SchemaTokenizeableString;
/**
* CSS
*/
tableClassName?: SchemaClassName;
/**
*
*/
title?: string;
/**
* CSS
*/
toolbarClassName?: SchemaClassName;
}
export interface TableProps extends RendererProps {
@ -42,7 +180,7 @@ export interface TableProps extends RendererProps {
headerClassName?: string;
footerClassName?: string;
store: ITableStore;
columns?: Array<Column>;
columns?: Array<TableColumn>;
headingClassName?: string;
toolbarClassName?: string;
headerToolbarClassName?: string;

View File

@ -6,7 +6,12 @@ import {isVisible, autobind, isDisabled} from '../utils/helper';
import findIndex from 'lodash/findIndex';
import {Tabs as CTabs, Tab} from '../components/Tabs';
import {ClassNamesFn} from '../theme';
import {BaseSchema, SchemaClassName, SchemaIcon} from '../Schema';
import {
BaseSchema,
SchemaClassName,
SchemaCollection,
SchemaIcon
} from '../Schema';
import {ActionSchema} from './Action';
export interface TabSchema extends Omit<BaseSchema, 'type'> {
@ -19,12 +24,12 @@ export interface TabSchema extends Omit<BaseSchema, 'type'> {
*
* @deprecated body
*/
tab?: SchemaNode;
tab?: SchemaCollection;
/**
*
*/
body?: SchemaNode;
body?: SchemaCollection;
/**
*