Archer_cdm
2 years ago
6 changed files with 221 additions and 45 deletions
@ -0,0 +1,99 @@ |
|||
import React, { useRef } from 'react'; |
|||
import { Modal, Form, Button, Input } from '@douyinfe/semi-ui'; |
|||
|
|||
const FolderModal = (props) => { |
|||
const { modalData, oldData, onCancel, onOk } = props; |
|||
const { title, childFolder, departmentName, trainDate } = modalData; |
|||
const add = title.includes("新建"); |
|||
|
|||
const form = useRef();//表单 |
|||
const validatName = (val) => { |
|||
if (val && '' == val.trim()) { |
|||
return '不可以为空'; |
|||
} else |
|||
if (val.length > 20) { |
|||
return '最大20字符'; |
|||
} else { |
|||
if (oldData.children) { |
|||
if (childFolder) {//三级目录 |
|||
let deptChild = oldData.children.find(r => r.label == departmentName).children; |
|||
if (!add) { |
|||
deptChild = deptChild.filter(r => trainDate != r.label); |
|||
} |
|||
const old = deptChild.find(r => r.label == val.trim()); |
|||
if (old) { |
|||
return ("该文件已存在"); |
|||
} else { |
|||
return ''; |
|||
} |
|||
} else { //二级目录 |
|||
let deptData = oldData.children; |
|||
if (!add) { |
|||
deptData = deptData.filter(r => departmentName != r.label); |
|||
} |
|||
const old = deptData.find(r => r.label == val.trim()); |
|||
if (old) { |
|||
return ("该文件已存在"); |
|||
} else { |
|||
return ''; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return ''; |
|||
} |
|||
const handleOk = () => { |
|||
|
|||
form.current.validate().then((values) => { |
|||
if (!add) { |
|||
values.oldDepName = departmentName; |
|||
values.oldTrainDate = trainDate; |
|||
} |
|||
onOk(add, values); |
|||
}); |
|||
} |
|||
return (<Modal |
|||
title={`${title}文件夹`} |
|||
visible={true} |
|||
maskClosable={false} |
|||
onOk={handleOk} |
|||
onCancel={onCancel}> |
|||
<Form |
|||
getFormApi={(formApi) => (form.current = formApi)} |
|||
labelPosition={'left'} |
|||
labelAlign={'right'} |
|||
labelCol={{ span: 6 }} |
|||
wrapperCol={{ span: 18 }} |
|||
> |
|||
{!childFolder && <Form.Input |
|||
field="name" |
|||
label="主文件夹" |
|||
initValue="公司档案" |
|||
disabled={true} |
|||
/>} |
|||
<Form.Input |
|||
field="departmentName" |
|||
label="二级文件夹" |
|||
initValue={departmentName} |
|||
disabled={childFolder} |
|||
validate={validatName} |
|||
trigger='blur' |
|||
rules={[{ required: true, message: "请输入二级文件夹" }, |
|||
{ whitespace: true, message: '不允许输入空格' }, |
|||
// { max: 20, message: "最多输入20个字符" } |
|||
]} |
|||
/> |
|||
{childFolder && |
|||
< Form.Input |
|||
field="trainDate" |
|||
label="子文件夹" |
|||
initValue={trainDate} |
|||
validate={validatName} |
|||
trigger='blur' |
|||
rules={[{ required: true, message: "请输入子文件夹" }]} |
|||
/>} |
|||
</Form> |
|||
</Modal > |
|||
) |
|||
} |
|||
export default FolderModal |
Loading…
Reference in new issue