import React, {ChangeEvent, Component, useContext, useEffect, useRef, useState} from "react"; import {Dropdown, Form, Input, InputRef, LabeledValue, MenuProps, Select, Space, Table} from "antd"; import {FormInstance} from "antd/es/form"; import style from "@/component/step/http/Http.module.less"; import {PlusOutlined} from "@ant-design/icons"; type EditableTableProps = Parameters[0]; type ColumnTypes = Exclude; const EditableContext = React.createContext | null>(null); interface EditableRowProps { index: number; } type HandleSave = (record: DataType) => void; interface EditableCellProps { title: React.ReactNode; editable: boolean; children: React.ReactNode; dataIndex: keyof DataType; record: DataType; handleSave: HandleSave } interface DataType { key: number obj: React.Key condition: CheckEnum check: string } enum SelectAddEnum { ADD, IMPORT } // 函数方法枚举 enum CheckEnum { Comparison, outweigh, outweighEqual, less, lessEqual, NotEqual, contain, notContain, exist, absent, list, notList, interval, notInterval } const FuncList = ["对象比较", '大于', "大于等于", "小于", "小于等于", '不等于', "包含", "不包含", "存在", "不存在", "属于集合", "不属于集合", "区间范围", "非区间范围"] const FuncSelectItem: LabeledValue[] = [] // const Func for (let func in FuncList) { FuncSelectItem.push({ value: func, label: FuncList[func] }) } const EditableRow: React.FC = ({index, ...props}) => { const [form] = Form.useForm(); return (
); }; const EditableCell: React.FC = ({ title, editable, children, dataIndex, record, handleSave, ...restProps }) => { const [editing, setEditing] = useState(false); const inputRef = useRef(null); const form = useContext(EditableContext)!; useEffect(() => { if (editing) { inputRef.current!.focus(); } }, [editing]); const toggleEdit = () => { setEditing(!editing); form.setFieldsValue({[dataIndex]: record[dataIndex]}); }; const save = async () => { try { const values = await form.validateFields(); toggleEdit(); handleSave({...record, ...values}); } catch (errInfo) { console.log('Save failed:', errInfo); } }; let childNode = children; if (editable) { childNode = editing ? ( ) : (
{children}
); } return {childNode}; }; const addSelectItem: MenuProps['items'] = [ { key: SelectAddEnum.ADD, label: (
添加一行
), }, { key: SelectAddEnum.IMPORT, label: (
导入
), } ] const Check = () => { const [dataSource, setDataSource] = useState([ { key: 0, condition: CheckEnum.lessEqual, check: '', obj: '', }, ]); const [count, setCount] = useState(1); const handleDelete = (key: React.Key) => { const newData = dataSource.filter((item) => item.key !== key); setDataSource(newData); }; // 用户操作 const TitleSelectClick: MenuProps['onClick'] = ({key}) => { const SelectKey = Number(key) switch (SelectKey) { case SelectAddEnum.ADD: handleAdd() break case SelectAddEnum.IMPORT: console.log("import") break default: break } console.log(key) } const funcChange = (key: number, value: number) => { console.log(key, value) const data = dataSource[Number(key)] console.log(data) data.condition = Number(value) handleSave(data) } const paramsRender = (type: CheckEnum, value: DataType, handleSave: HandleSave) => { return
123123
} const defaultColumns: (ColumnTypes[number] & { editable?: boolean; dataIndex: string })[] = [ { title: '校验对象', dataIndex: 'index', width: '300px', editable: true, }, { title: '检查条件', dataIndex: 'index', width: "200px", render: (_, record:DataType) => { return (