Browse Source

fix: render form schema

master
yangpei 4 years ago
parent
commit
27c6ab2ecd
  1. 11
      packages/core/src/components/schemaForm/index.tsx
  2. 6
      packages/core/src/mods/settingBar/components/json/index.tsx

11
packages/core/src/components/schemaForm/index.tsx

@ -1,10 +1,9 @@
import React from 'react'; import React from 'react';
import { Form, Input, Switch, Select, Radio, Checkbox, DatePicker, TimePicker } from 'antd'; import { Form, Input, Switch, Select, Radio, Checkbox, DatePicker, TimePicker, Empty } from 'antd';
import moment from 'moment'; import moment from 'moment';
const FormItem = Form.Item const FormItem = Form.Item
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const { Option } = Select; const { Option } = Select;
interface INum { interface INum {
label: string, label: string,
value: string value: string
@ -24,7 +23,7 @@ const formLayout = {
const SchemaForm: React.FC<IProps> = (props) => { const SchemaForm: React.FC<IProps> = (props) => {
return ( return (
<Form {...formLayout}> Object.keys(props.schema).length > 0 ? <Form {...formLayout}>
{props.schema?.properties && Object.keys(props.schema.properties).map((key: string) => { {props.schema?.properties && Object.keys(props.schema.properties).map((key: string) => {
const obj = props.schema.properties[key] const obj = props.schema.properties[key]
const options: INum[] = obj.enum ? obj.enum.map((item: string, idx: number) => { const options: INum[] = obj.enum ? obj.enum.map((item: string, idx: number) => {
@ -82,7 +81,11 @@ const SchemaForm: React.FC<IProps> = (props) => {
{ele} {ele}
</FormItem> </FormItem>
})} })}
</Form> </Form> :
<Empty
description={'请编辑投放配置schema'}
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
); );
}; };

6
packages/core/src/mods/settingBar/components/json/index.tsx

@ -4,7 +4,7 @@ import 'antd/es/modal/style';
import 'antd/es/button/style'; import 'antd/es/button/style';
import 'antd/es/message/style'; import 'antd/es/message/style';
import JsonView from 'react-json-view'; import JsonView from 'react-json-view';
import { Button, Tabs, Modal, Card } from 'antd'; import { Button, Tabs, Modal, Card, message } from 'antd';
const { TabPane } = Tabs; const { TabPane } = Tabs;
import { safeParse } from '../../../../utils'; import { safeParse } from '../../../../utils';
import CodeEditor from '../../../../components/codeEditor'; import CodeEditor from '../../../../components/codeEditor';
@ -129,12 +129,10 @@ const EditModal: React.FC<IEditorModalProps> = (props) => {
if (JSON.stringify(JSON.parse(json)) === '{}') { if (JSON.stringify(JSON.parse(json)) === '{}') {
// @ts-ignore // @ts-ignore
const value = formRef.current && formRef.current.getValue() const value = formRef.current && formRef.current.getValue()
console.log(value.schema)
props.changeSchema(value.schema) props.changeSchema(value.schema)
setJson(value) setJson(value)
} else { } else {
console.log(JSON.parse(json)) props.changeSchema(JSON.parse(json).schema)
props.changeSchema(JSON.parse(json))
} }
} else { } else {
JSON.parse(json); JSON.parse(json);

Loading…
Cancel
Save