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'; import { getValueFromEvent } from '@utils/index' const { post, api, xPost } = apiObj; const { Option } = Select; const { TextArea } = Input; function AddRules(props) { const [form] = Form.useForm(); const { back, userChange } = 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 [tableCname, setTableCname] = useState(); const [tableEname, setTableEname] = useState(); const [columnCname, setcolumnCname] = useState(); const [columnEname, setcolumnEname] = useState(); const [disable, seDisable] = useState([true]); const { type, detail } = useContext(FiledContext); const { back, form, cancel } = props; const initialValues = detail console.log(type); 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() { post(api.getAddUpColumnName, { tableCname: tableCname, tableEname: tableEname, columnId: type == 2 ? detail.columnId : null, 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].getColumnNameDTOList setColList([...colList]) } }); }); } } }) } //表选择 function tablechange(i, value, options, ins) { const formData = form.getFieldsValue(); if (value) { colList[i] = list[options.key].getColumnNameDTOList disable[i] = false seDisable([...disable]) setColList([...colList]) } else { colList[i] = [] disable[i] = true seDisable([...disable]) setColList([...colList]) getAddUpColumnName() } let columnList = formData.columnList; if (ins == 1) { if (value) { columnList[i].tableEname = options.val } else { columnList[i].tableEname = undefined } } else { if (value) { columnList[i].tableCname = options.val } else { columnList[i].tableCname = undefined } } columnList[i].columnCname = undefined columnList[i].columnEname = undefined form.setFieldsValue({ columnList: columnList }); } function colchange(i, value, options, ins) { const formData = form.getFieldsValue(); let columnList = formData.columnList; if (value) { columnList[i].id = options.key } else { columnList[i].id = undefined } if (ins == 1) { if (value) { columnList[i].columnEname = options.val } else { columnList[i].columnEname = undefined } } else { if (value) { columnList[i].columnCname = options.val } else { columnList[i].columnCname = undefined } } form.setFieldsValue({ columnList: columnList }); } //表名称搜索(中文) function cnameSearch(val) { setTableCname(val) getAddUpColumnName() } //表名称搜索(英文) function enameSearch(val) { setTableEname(val) getAddUpColumnName() } //字段名称搜索(中文) function colmeSearch(val) { setcolumnCname(val) getAddUpColumnName() } //字段名称搜索(英文) function coleneSearch(val) { setcolumnEname(val) getAddUpColumnName() } //表字段添加 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 }); const index = columnList.length - 1 colList.push(...[[]]) setColList([...colList]) disable[index] = true seDisable([...disable]) } //标准值维护 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) } }); 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} hidden={type == 2} />
) }) }
{ standardValueList.map((it, i) => { return (
modifyStand(i)} src={i == 0 ? add : del} />
) }) }