change tuple type

This commit is contained in:
yehuozhili 2020-09-05 07:22:56 +08:00
parent 316344e5a4
commit 91feab72cf
4 changed files with 17 additions and 93 deletions

View File

@ -1,6 +1,3 @@
{ {
"extends": "react-app", "extends": "react-app"
"rules": {
"react/react-in-jsx-scope": "off"
}
} }

View File

@ -2,7 +2,7 @@ import { dynamic } from 'umi';
import Loading from '../LoadingCp'; import Loading from '../LoadingCp';
import { useMemo, memo, FC } from 'react'; import { useMemo, memo, FC } from 'react';
import React from 'react'; import React from 'react';
import { UnionData, AllTemplateType } from './schema'; import { AllTemplateType } from './schema';
const needList = ['Tab', 'Carousel', 'Upload', 'Video', 'Icon']; const needList = ['Tab', 'Carousel', 'Upload', 'Video', 'Icon'];
const DynamicFunc = (type: AllTemplateType) => const DynamicFunc = (type: AllTemplateType) =>
@ -33,11 +33,12 @@ const DynamicFunc = (type: AllTemplateType) =>
type DynamicType = { type DynamicType = {
isTpl: boolean; isTpl: boolean;
config: UnionData<'config'>; config: { [key: string]: any };
type: AllTemplateType; type: AllTemplateType;
}; };
const DynamicEngine = memo((props: DynamicType) => { const DynamicEngine = memo((props: DynamicType) => {
const { type, config, isTpl } = props; const { type, config, isTpl } = props;
console.log(config);
const Dynamic = useMemo(() => { const Dynamic = useMemo(() => {
return (DynamicFunc(type) as unknown) as FC<DynamicType>; return (DynamicFunc(type) as unknown) as FC<DynamicType>;
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps

View File

@ -75,12 +75,7 @@ export type CarouselImgTypeItem = BasicDataImgUrl;
export type CarouselImgType = BasicDataSource; export type CarouselImgType = BasicDataSource;
export interface CarouselSchema extends SchemaBasicImplement { export interface CarouselSchema extends SchemaBasicImplement {
editData: [ editData: Array<CarouselEditItem<CraouselKeyType>>;
CarouselEditItem<'direction'>,
CarouselEditItem<'swipeable'>,
CarouselEditItem<'autoPlay'>,
CarouselEditItem<'imgList'>,
];
config: CarouselConfigType; config: CarouselConfigType;
} }
//__________________________________________ //__________________________________________
@ -104,13 +99,7 @@ export interface TextEditItem<T extends TextKeyType> {
} }
export interface TextSchema extends SchemaBasicImplement { export interface TextSchema extends SchemaBasicImplement {
editData: [ editData: Array<TextEditItem<TextKeyType>>;
TextEditItem<'text'>,
TextEditItem<'color'>,
TextEditItem<'fontSize'>,
TextEditItem<'align'>,
TextEditItem<'lineHeight'>,
];
config: TextConfigType; config: TextConfigType;
} }
@ -140,14 +129,7 @@ export type TabEditItem<T extends TabKeyType> = {
}; };
export interface TabSchema extends SchemaBasicImplement { export interface TabSchema extends SchemaBasicImplement {
editData: [ editData: Array<TabEditItem<TabKeyType>>;
TabEditItem<'tabs'>,
TabEditItem<'activeColor'>,
TabEditItem<'color'>,
TabEditItem<'fontSize'>,
TabEditItem<'imgSize'>,
TabEditItem<'sourceData'>,
];
config: TabConfigType; config: TabConfigType;
} }
//__________________________________________ //__________________________________________
@ -173,12 +155,7 @@ export type NoticeEditItem<T extends NoticeKeyType> = {
range?: Array<NoticeThemeRageItem>; range?: Array<NoticeThemeRageItem>;
}; };
export interface NoticeSchema extends SchemaBasicImplement { export interface NoticeSchema extends SchemaBasicImplement {
editData: [ editData: Array<NoticeEditItem<NoticeKeyType>>;
NoticeEditItem<'text'>,
NoticeEditItem<'speed'>,
NoticeEditItem<'theme'>,
NoticeEditItem<'isClose'>,
];
config: NoticeConfigType; config: NoticeConfigType;
} }
@ -202,12 +179,7 @@ export type QRCodeEditItem<T extends QRCodeKeyType> = {
}; };
export interface QRCodeSchema extends SchemaBasicImplement { export interface QRCodeSchema extends SchemaBasicImplement {
editData: [ editData: Array<QRCodeEditItem<QRCodeKeyType>>;
QRCodeEditItem<'qrcode'>,
QRCodeEditItem<'text'>,
QRCodeEditItem<'color'>,
QRCodeEditItem<'fontSize'>,
];
config: QRCodeConfigType; config: QRCodeConfigType;
} }
@ -233,14 +205,7 @@ export type FooterEditItem<T extends FooterKeyType> = {
}; };
export interface FooterSchema extends SchemaBasicImplement { export interface FooterSchema extends SchemaBasicImplement {
editData: [ editData: Array<FooterEditItem<FooterKeyType>>;
FooterEditItem<'bgColor'>,
FooterEditItem<'height'>,
FooterEditItem<'text'>,
FooterEditItem<'fontSize'>,
FooterEditItem<'color'>,
FooterEditItem<'align'>,
];
config: FooterConfigType; config: FooterConfigType;
} }
@ -262,7 +227,7 @@ export type ImageEditItem<T extends ImageKeyType> = {
}; };
export interface ImageSchema extends SchemaBasicImplement { export interface ImageSchema extends SchemaBasicImplement {
editData: [ImageEditItem<'imgUrl'>, ImageEditItem<'round'>]; editData: Array<ImageEditItem<ImageKeyType>>;
config: ImageConfigType; config: ImageConfigType;
} }
@ -289,14 +254,7 @@ export type HeaderEditItem<T extends HeaderKeyType> = {
}; };
export interface HeaderSchema extends SchemaBasicImplement { export interface HeaderSchema extends SchemaBasicImplement {
editData: [ editData: Array<HeaderEditItem<HeaderKeyType>>;
HeaderEditItem<'bgColor'>,
HeaderEditItem<'height'>,
HeaderEditItem<'logo'>,
HeaderEditItem<'logoText'>,
HeaderEditItem<'color'>,
HeaderEditItem<'fontSize'>,
];
config: HeaderConfigType; config: HeaderConfigType;
} }
@ -320,13 +278,7 @@ export type ListEditItem<T extends ListKeyType> = {
}; };
export interface ListSchema extends SchemaBasicImplement { export interface ListSchema extends SchemaBasicImplement {
editData: [ editData: Array<ListEditItem<ListKeyType>>;
ListEditItem<'sourceData'>,
ListEditItem<'round'>,
ListEditItem<'imgSize'>,
ListEditItem<'fontSize'>,
ListEditItem<'color'>,
];
config: ListConfigType; config: ListConfigType;
} }
//__________________________________________ //__________________________________________
@ -392,12 +344,7 @@ export type IconEditItem<T extends IconKeyType> = {
}; };
export interface IconSchema extends SchemaBasicImplement { export interface IconSchema extends SchemaBasicImplement {
editData: [ editData: Array<IconEditItem<IconKeyType>>;
IconEditItem<'color'>,
IconEditItem<'size'>,
IconEditItem<'spin'>,
IconEditItem<'type'>,
];
config: IconConfigType; config: IconConfigType;
} }
@ -418,7 +365,7 @@ export type VideoEditItem<T extends VideoKeyType> = {
}; };
export interface VideoSchema extends SchemaBasicImplement { export interface VideoSchema extends SchemaBasicImplement {
editData: [VideoEditItem<'poster'>, VideoEditItem<'url'>]; editData: Array<VideoEditItem<VideoKeyType>>;
config: VideoConfigType; config: VideoConfigType;
} }
@ -444,13 +391,7 @@ export type XProgressEditItem<T extends XProgressKeyType> = {
}; };
export interface XProgressSchema extends SchemaBasicImplement { export interface XProgressSchema extends SchemaBasicImplement {
editData: [ editData: Array<XProgressEditItem<XProgressKeyType>>;
XProgressEditItem<'theme'>,
XProgressEditItem<'shape'>,
XProgressEditItem<'size'>,
XProgressEditItem<'percent'>,
XProgressEditItem<'strokeWidth'>,
];
config: XProgressConfigType; config: XProgressConfigType;
} }
@ -472,20 +413,6 @@ export interface SchemaType extends SchemaImplement {
XProgress: XProgressSchema; XProgress: XProgressSchema;
} }
export type UnionData<T extends keyof SchemaBasicImplement> =
| CarouselSchema[T]
| TextSchema[T]
| TabSchema[T]
| NoticeSchema[T]
| QRCodeSchema[T]
| FooterSchema[T]
| ImageSchema[T]
| HeaderSchema[T]
| ListSchema[T]
| IconSchema[T]
| VideoSchema[T]
| XProgressSchema[T];
const schema: SchemaType = { const schema: SchemaType = {
Carousel: { Carousel: {
editData: [ editData: [

View File

@ -6,7 +6,7 @@ import MutiText from '../MutiText';
import Color from '../Color'; import Color from '../Color';
import CardPicker from '../CardPicker'; import CardPicker from '../CardPicker';
import { Store } from 'antd/lib/form/interface'; import { Store } from 'antd/lib/form/interface';
import { UnionData, BasicRangeType, IconSchema } from '../DynamicEngine/schema'; import { BasicRangeType, IconSchema } from '../DynamicEngine/schema';
// import styles from './index.less'; // import styles from './index.less';
const normFile = (e: any) => { const normFile = (e: any) => {
console.log('Upload event:', e); console.log('Upload event:', e);
@ -34,7 +34,6 @@ interface FormEditorProps {
const FormEditor = (props: FormEditorProps) => { const FormEditor = (props: FormEditorProps) => {
const { config, defaultValue, onSave, onDel, uid } = props; const { config, defaultValue, onSave, onDel, uid } = props;
console.log(config, defaultValue, uid);
const onFinish = (values: Store) => { const onFinish = (values: Store) => {
onSave && onSave(values); onSave && onSave(values);
}; };