import { useEffect, useState, useContext } from 'react'; import { Form, Input, Radio, Button, Select, message, Breadcrumb, Modal } from 'antd'; import './index.less'; import apiObj from '@api/index'; import backIcon from "@images/back.png"; import FiledContext from './filed-context'; import add from '@images/add-icon.png'; import del from '@images/del-icon.png'; const { post, api, xPost } = apiObj; const { Option } = Select; const { TextArea } = Input; function AddRules(props) { const [form] = Form.useForm(); const { back } = props; const [visible, setVisible] = useState(false); const { type } = useContext(FiledContext); function handleOk() { back() } function handleCancel() { setVisible(false) } const goback = () => { if (form.isFieldsTouched()) { setVisible(true) } else { back() } }; return ( <> 返回上一页 字段校验规则维护 {type == 1 ? "新增字段校验" : "修改字段校验"}

您还有内容未保存,确定要退出?

) } function ContentForm(props) { const [columnList, setColumnList] = useState([]); const [standardValueList, setStandardValueList] = useState([]); const [regularList, setRegularList] = useState([]);//正则式数据 const [tableList, setTableList] = useState([]);//表名称 const [colList, setColList] = useState([[]]);//字段名称 const [list, setList] = useState([]); const [disable, seDisable] = useState(true); const { type, detail } = useContext(FiledContext); const { back, form, cancel } = props; const initialValues = detail const vilidateRules = { required: '${label}不能为空!', }; //获取正则式名称 function getRegular(name) { const param = { name: name || '' } post(api.getRegular, param).then((res) => { if (res.data.code === 200) { const data = res.data.data; setRegularList(data); } }) } function getAddUpColumnName(tableCname, tableEname, columnCname, columnEname) { post(api.getAddUpColumnName, { tableCname: tableCname, tableEname: tableEname, columnCname: columnCname, columnEname: columnEname, }).then((res) => { if (res.data.code === 200) { const data = res.data.data; let columnList = [] data.forEach((item, i) => { item.getTableNameDTO.index = i columnList.push(item.getTableNameDTO) }); setTableList(columnList); setList(data) // if (type == 2) { // data.forEach((item, i) => { // detail.columnList.forEach(it => { // if (item.getTableNameDTO.tableCname == it.tableCname) { // let colList = [[]] // colList[0] = data[i].DTOList // setColList([...colList]) // } // }); // }); // } } }) } //表选择 function tablechange(value, options) { colList[options.key] = list[options.key].getColumnNameDTOList seDisable(false) setColList([...colList]) } function colchange(value, options) { const formData = form.getFieldsValue(); let columnList = formData.columnList; columnList[options.index].id = options.key form.setFieldsValue({ columnList: columnList }); } //表名称搜索(中文) function cnameSearch(val) { getAddUpColumnName(val, '', '', '') } //表名称搜索(英文) function enameSearch(val) { getAddUpColumnName('', val, '', '') } //字段名称搜索(中文) function colmeSearch(val) { getAddUpColumnName(val, '', '', '') } //字段名称搜索(英文) function coleneSearch(val) { getAddUpColumnName('', val, '', '') } //表字段添加 function modifyData(i) { const formData = form.getFieldsValue(); let columnList = formData.columnList; if (i == 0) { columnList.push({ columnCname: undefined, columnEname: undefined, ableCname: undefined, tableEname: undefined }) } else { columnList.splice(i, 1) } setColumnList([...columnList]) form.setFieldsValue({ columnList: columnList }); colList.push(...[[]]) setColList([...colList]) } //标准值维护 function modifyStand(i) { const formData = form.getFieldsValue(); let standardValueList = formData.standardValueList; if (i == 0) { standardValueList.push({ tit: null }) } else { standardValueList.splice(i, 1) } setStandardValueList([...standardValueList]) form.setFieldsValue({ standardValueList: standardValueList }); } //正则式名称搜索 function onSearch(val) { getRegular(val) } //正则式选择获取id function onChange(value, options) { form.setFieldsValue({ regularId: options ? options.key : '' }); } function handleSave() { form.validateFields().then((values) => { addColumnVerify() }).catch((error) => { console.log('验证失败', error) }) } function addColumnVerify() { const formData = form.getFieldsValue(); let arr = [] let url formData.standardValueList.forEach(it => { if (it.tit) { arr.push(it.tit) } }); console.log(arr); formData.standardValueList = arr if (type == 1) { url = api.addColumnVerify } else { url = api.updateColumnVerify // formData.id = detail.columnId } post(url, formData).then((res) => { if (res.data.code === 200) { message.success(res.data.message); cancel() } else { message.error(res.data.message); } }) } useEffect(() => { getRegular() getAddUpColumnName() if (detail) { const columnList = detail.columnList const standardValueList = detail.standardValueList setColumnList(columnList) setStandardValueList(standardValueList) list.forEach((item, i) => { detail.columnList.forEach(it => { if (item.getTableNameDTO.tableCname == it.tableCname) { let colList = [[]] colList[0] = list[i].getColumnNameDTOList setColList([...colList]) } }); }); } if (type == 2) { seDisable(false) } }, []); return ( <>
{ columnList.map((it, i) => { return (
modifyData(i)} src={i == 0 ? add : del} />
) }) }
{ standardValueList.map((it, i) => { return (
modifyStand(i)} src={i == 0 ? add : del} />
) }) }