|
@@ -1,5 +1,5 @@
|
|
-import { Form, Button, Switch, Input, Radio, Space } from 'antd';
|
|
|
|
-import React from 'react';
|
|
|
|
|
|
+import { Form, Button, Switch, Input, Radio, Space, Row } from 'antd';
|
|
|
|
+import React, { useMemo, useState, useEffect } from 'react';
|
|
import { DeleteOutlined } from '@ant-design/icons';
|
|
import { DeleteOutlined } from '@ant-design/icons';
|
|
function ItemAttribute(props) {
|
|
function ItemAttribute(props) {
|
|
const { item, onChange } = props;
|
|
const { item, onChange } = props;
|
|
@@ -35,7 +35,7 @@ function ItemAttribute(props) {
|
|
FormContent = <DDSelectField {...formProps} />;
|
|
FormContent = <DDSelectField {...formProps} />;
|
|
break;
|
|
break;
|
|
case 'DDMultiSelectField':
|
|
case 'DDMultiSelectField':
|
|
- FormContent = <DDMultiSelectField item={item} onChange={onChange} />;
|
|
|
|
|
|
+ FormContent = <DDMultiSelectField {...formProps} />;
|
|
break;
|
|
break;
|
|
case 'NumberField':
|
|
case 'NumberField':
|
|
FormContent = <NumberField {...formProps} />;
|
|
FormContent = <NumberField {...formProps} />;
|
|
@@ -170,16 +170,30 @@ function TextareaField(props) {
|
|
function DDSelectField(props) {
|
|
function DDSelectField(props) {
|
|
const { item, btns, onFinish } = props;
|
|
const { item, btns, onFinish } = props;
|
|
const [form] = Form.useForm();
|
|
const [form] = Form.useForm();
|
|
|
|
+ const handleFinish = value => {
|
|
|
|
+ let tempValue = { ...value };
|
|
|
|
+ let arr = [];
|
|
|
|
+ tempValue.options.map(item => {
|
|
|
|
+ arr.push(item.value);
|
|
|
|
+ })
|
|
|
|
+ if (arr) {
|
|
|
|
+ arr = arr.filter(item => item)
|
|
|
|
+ arr = [...new Set(arr)];
|
|
|
|
+ tempValue.options = arr
|
|
|
|
+ }
|
|
|
|
+ onFinish?.(tempValue);
|
|
|
|
+ }
|
|
|
|
+
|
|
return (
|
|
return (
|
|
- <Form form={form} labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} autoComplete="off" initialValues={item.props} onFinish={onFinish}>
|
|
|
|
|
|
+ <Form form={form} labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} autoComplete="off" initialValues={item.props} onFinish={handleFinish}>
|
|
<Form.Item label="标题" name="label">
|
|
<Form.Item label="标题" name="label">
|
|
<Input />
|
|
<Input />
|
|
</Form.Item>
|
|
</Form.Item>
|
|
<Form.Item label="提示文字" name="placeholder">
|
|
<Form.Item label="提示文字" name="placeholder">
|
|
<Input />
|
|
<Input />
|
|
</Form.Item>
|
|
</Form.Item>
|
|
- <Form.Item label="选项" name="options">
|
|
|
|
- {/* <SelectItem /> */}
|
|
|
|
|
|
+ <Form.Item label="选项" name="options" wrapperCol={{ span: 24 }}>
|
|
|
|
+ <SelectItem />
|
|
</Form.Item>
|
|
</Form.Item>
|
|
<Form.Item label="必填" valuePropName="checked" name="required">
|
|
<Form.Item label="必填" valuePropName="checked" name="required">
|
|
<Switch />
|
|
<Switch />
|
|
@@ -189,50 +203,103 @@ function DDSelectField(props) {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
function DDMultiSelectField(props) {
|
|
function DDMultiSelectField(props) {
|
|
|
|
+ const { item, btns, onFinish } = props;
|
|
const [form] = Form.useForm();
|
|
const [form] = Form.useForm();
|
|
|
|
+ const handleFinish = value => {
|
|
|
|
+ let tempValue = { ...value };
|
|
|
|
+ let arr = [];
|
|
|
|
+ tempValue.options.map(item => {
|
|
|
|
+ arr.push(item.value);
|
|
|
|
+ })
|
|
|
|
+ if (arr) {
|
|
|
|
+ arr = arr.filter(item => item)
|
|
|
|
+ arr = [...new Set(arr)];
|
|
|
|
+ tempValue.options = arr
|
|
|
|
+ }
|
|
|
|
+ onFinish?.(tempValue);
|
|
|
|
+ }
|
|
return (
|
|
return (
|
|
- <Form form={form} labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} autoComplete="off">
|
|
|
|
- <Form.Item label="标题">
|
|
|
|
|
|
+ <Form form={form} labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} autoComplete="off" initialValues={item.props} onFinish={handleFinish}>
|
|
|
|
+ <Form.Item label="标题" name="label">
|
|
<Input />
|
|
<Input />
|
|
</Form.Item>
|
|
</Form.Item>
|
|
- <Form.Item label="提示文字">
|
|
|
|
|
|
+ <Form.Item label="提示文字" name="placeholder">
|
|
<Input />
|
|
<Input />
|
|
</Form.Item>
|
|
</Form.Item>
|
|
- {/* <Form.Item label="默认值">
|
|
|
|
- <Input />
|
|
|
|
- </Form.Item> */}
|
|
|
|
|
|
+ <Form.Item label="选项" name="options" wrapperCol={{ span: 24 }}>
|
|
|
|
+ <SelectItem />
|
|
|
|
+ </Form.Item>
|
|
|
|
+ <Form.Item label="必填" valuePropName="checked" name="required">
|
|
|
|
+ <Switch />
|
|
|
|
+ </Form.Item>
|
|
|
|
+ {btns}
|
|
</Form>
|
|
</Form>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
function SelectItem(props) {
|
|
function SelectItem(props) {
|
|
const { value, onChange } = props;
|
|
const { value, onChange } = props;
|
|
- console.log(value);
|
|
|
|
|
|
+ const [localValue, setLocalValue] = useState([]);
|
|
const pushItem = item => {
|
|
const pushItem = item => {
|
|
- let tempValue = [...value, item];
|
|
|
|
|
|
+ let tempValue = [...localValue, {
|
|
|
|
+ id: +new Date(),
|
|
|
|
+ value: item
|
|
|
|
+ }];
|
|
|
|
+ setLocalValue(tempValue);
|
|
onChange(tempValue);
|
|
onChange(tempValue);
|
|
}
|
|
}
|
|
|
|
+
|
|
const handleDelete = index => {
|
|
const handleDelete = index => {
|
|
- value.splice(index, 1);
|
|
|
|
|
|
+ let tempValue = [...localValue];
|
|
|
|
+ tempValue.splice(index, 1);
|
|
|
|
+ setLocalValue(tempValue);
|
|
|
|
+ onChange(tempValue);
|
|
}
|
|
}
|
|
- const handleInputOnchange = value => {
|
|
|
|
-
|
|
|
|
|
|
+ const handleInputOnChange = (targetValue, index) => {
|
|
|
|
+ let tempValue = [...localValue];
|
|
|
|
+ tempValue[index].value = targetValue;
|
|
|
|
+ setLocalValue(tempValue);
|
|
|
|
+ onChange(tempValue);
|
|
}
|
|
}
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ let tempValue = value.map(item => ({ id: +new Date(), value: item }));
|
|
|
|
+ setLocalValue(tempValue);
|
|
|
|
+ onChange(tempValue);
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
return (
|
|
return (
|
|
- <div>
|
|
|
|
|
|
+ <div style={{
|
|
|
|
+ minHeight: 40,
|
|
|
|
+ display: 'flex',
|
|
|
|
+ flexDirection: 'column'
|
|
|
|
+ }}>
|
|
<div>
|
|
<div>
|
|
|
|
+ <div style={{
|
|
|
|
+ fontSize: 4,
|
|
|
|
+ color: '#40a9ff',
|
|
|
|
+ cursor: 'pointer',
|
|
|
|
+ lineHeight: '32px'
|
|
|
|
+ }} onClick={() => { pushItem('') }}>添加选项</div>
|
|
|
|
+ </div>
|
|
|
|
+ <div style={{ minHeight: 20 }}>
|
|
{
|
|
{
|
|
- value.map((item, index) =>
|
|
|
|
- <div>
|
|
|
|
- <Input />
|
|
|
|
|
|
+ localValue.map((item, index) =>
|
|
|
|
+ <div style={{
|
|
|
|
+ display: 'flex',
|
|
|
|
+ justifyContent: 'center',
|
|
|
|
+ alignItems: 'center',
|
|
|
|
+ marginBottom: 5
|
|
|
|
+ }}
|
|
|
|
+ key={item.id}
|
|
|
|
+ >
|
|
|
|
+ <Input style={{ marginRight: 10 }} value={item.value} onChange={e => handleInputOnChange(e.target.value, index)} />
|
|
<DeleteOutlined
|
|
<DeleteOutlined
|
|
onClick={() => handleDelete(index)}
|
|
onClick={() => handleDelete(index)}
|
|
/>
|
|
/>
|
|
</div>)
|
|
</div>)
|
|
}
|
|
}
|
|
</div>
|
|
</div>
|
|
- <div onClick={() => { pushItem('') }}>添加选项</div>
|
|
|
|
- </div>
|
|
|
|
|
|
+ </div >
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|