zmh
2 years ago
3 changed files with 141 additions and 16 deletions
@ -0,0 +1,70 @@ |
|||
import React, { useEffect, useState } from 'react'; |
|||
import { Modal, Input, Form, message } from 'antd'; |
|||
const TagSetModal = (props) => { |
|||
const { tagList, onConfirm, onCancel, editData } = props; |
|||
const [form] = Form.useForm(); |
|||
useEffect(() => { |
|||
}, []); |
|||
const handleOk = () => { |
|||
form.validateFields().then(values => { |
|||
if (onConfirm) { |
|||
if (editData.setEditData) { |
|||
//标签集新建、修改
|
|||
let exist = false; |
|||
if (editData.name) { |
|||
exist = tagList.find(m => m.tagSetName === values.name && m.tagSetId != editData.id); |
|||
} else { |
|||
exist = tagList.find(m => m.tagSetName === values.name); |
|||
} |
|||
if (exist) { |
|||
message.error('该标签集名称已存在'); |
|||
return false; |
|||
} |
|||
} else { |
|||
let exist = false; |
|||
if (editData.name) { |
|||
tagList.map(tl => { |
|||
if (!exist) |
|||
exist = tl.tags.find(t => t.name === values.name && t.id != editData.id); |
|||
}) |
|||
} else { |
|||
tagList.map(tl => { |
|||
if (!exist) |
|||
exist = tl.tags.find(t => t.name === values.name); |
|||
}) |
|||
} |
|||
if (exist) { |
|||
message.error('该标签名称已存在'); |
|||
return false; |
|||
} |
|||
} |
|||
onConfirm(values) |
|||
} |
|||
}) |
|||
} |
|||
const validatorNull = (rule, value, getFieldValue, validateFields) => { |
|||
if (!value || !value.trim().length) { |
|||
return Promise.reject(new Error(`${editData.label}不可空字符串`)); |
|||
} |
|||
return Promise.resolve(); |
|||
} |
|||
return ( |
|||
<Modal title={editData.title} visible={true} destroyOnClose |
|||
okText='保存' width={800} |
|||
onOk={() => handleOk(null)} |
|||
onCancel={onCancel}> |
|||
<Form form={form} labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} initialValues={editData || {}}> |
|||
<Form.Item |
|||
label={editData.label} |
|||
name='name' |
|||
rules={[{ required: true, message: '' }, { max: 50, message: `${editData.label}不超过50个字` }, |
|||
({ getFieldValue, validateFields }) => ({ |
|||
validator(_, value) { return validatorNull(_, value, getFieldValue, validateFields) } |
|||
})]}> |
|||
<Input style={{ width: '90%' }} placeholder={`请输入${editData.label}`} /> |
|||
</Form.Item> |
|||
</Form> |
|||
</Modal> |
|||
) |
|||
} |
|||
export default TagSetModal; |
Loading…
Reference in new issue