import { createContext, useReducer, useContext, useEffect, useRef, useState, useMemo } from "react"; import { Card, Collapse, List, Form, Input, InputNumber, Button, Select, Radio, Space, Table, Checkbox, Divider, Modal, Tree, message, } from "antd"; import { PlusOutlined, MinusCircleOutlined, FileSearchOutlined, SettingOutlined, } from "@ant-design/icons"; import { cloneDeep, cond, set } from "lodash"; import Sortable from "sortablejs"; import { FilterRules } from "dt-react-component"; import styles from "./index.less"; import type { InstructionItem, ContextType } from "./type"; import { shortid } from "../utils/utils"; import { CONDITION_DATA, CONDITION_DATA_TYPEB, CONDITION_DATA_TYPE_NOTB, INIT_ROW_VALUES, ROW_PRE_OPTIONS, PROPS_OPTIONS, SIMPLE_DATASET_FILTER_OPTIONS, RADIO_OPTIONS, } from "../constants/common"; const initValues = { baseList: [ { title: "条件判断", key: "ifdo", component: (props: any) => , }, { title: "新增", key: "add", component: (props: any) => , }, { title: "修改", key: "edit", component: (props: any) => , bFullMode: true, }, { title: "删除", key: "del", component: (props: any) => , bFullMode: true, }, { title: "复制", key: "copy", component: (props: any) => , bFullMode: true, }, { title: "保存", key: "save", component: (props: any) => , }, { title: "过滤", key: "filter", component: (props: any) => , bFullMode: true, }, { title: "创建新数据集", key: "newempty", component: (props: any) => , }, { title: "清空数据集", key: "emptyAll", component: (props: any) => , }, { title: "刷新数据集", key: "refresh", component: (props: any) => , }, { title: "清空选中行", key: "clearrowkey", component: (props: any) => , }, { title: "选中表格第一行", key: "selectfirstline", component: (props: any) => , }, ], funList: [ { title: "打印", key: "print", component: (props: any) => , }, { title: "查询sql", key: "opensql", component: (props: any) => , }, { title: "执行sql", key: "exesql", component: (props: any) => , }, { title: "提示信息", key: "msg", component: (props: any) => , }, ], btnsList: [ { title: "工具栏按钮配置", key: "btnhandle", component: (props: any) => , }, ], instructionList: [], // 步骤列表 settingPorps: {}, }; const myContext = createContext(null as any); const reducer = (state: any, action: [any, any]) => { const [type, payload] = action; switch (type) { case "saveState": return { ...state, ...payload, }; default: return { ...state, ...payload, }; } }; const oThis: any = { activeJson: {}, }; const convertData2Str = (dataValue: any, bList: boolean) => { const { type, children = [] } = dataValue; const childrenFilter = children.filter((child: any) => { if (child.children?.length) { return true; } if (child.rowValues) { const { pre1, value1, condition, pre2 } = child.rowValues; return ( child.children || (pre1 === "custom" && value1 !== undefined) || (pre1 && condition && (pre2 || condition?.includes("empty") || condition?.includes("All") || condition?.includes("One"))) ); } return false; }); if (bList) { const result = [ ...childrenFilter.map((child: any) => { if (child.children) { return convertData2Str(child, bList); } else { const { pre1, value1, condition, pre2, value2 } = child.rowValues; return [pre1, value1, condition, pre2, value2]; } }), type, ]; return result; } return childrenFilter .map((child: any) => { if (child.children) { return `(${convertData2Str(child, bList)})`; } else { const { pre1, value1, condition, pre2, value2 } = child.rowValues; let key1 = ""; let key2 = ""; if (pre1 === "number" || pre1 === "boolean") { key1 = value1; } else if (pre1 === "string") { key1 = `'${value1}'`; } else { if ( value1?.startsWith("i") || value1?.startsWith("d") || value1?.startsWith("b") || value1 === "enabled" ) { key1 = `\${${pre1}.${value1}}`; } else { key1 = `'\${${pre1}.${value1}}'`; } } if (pre2 === "number" || pre2 === "boolean") { key2 = value2; } else if (pre2 === "string") { key2 = `'${value2}'`; } else { if ( value2?.startsWith("i") || value2?.startsWith("d") || value2?.startsWith("b") || value2 === "enabled" ) { key2 = `\${${pre2}.${value2}}`; } else { key2 = `'\${${pre2}.${value2}}'`; } } if (condition === "includes") { return `${key1}.includes(${key2})`; } else if (condition === "!includes") { return `!${key1}.includes(${key2})`; } else if (condition === "empty") { return `!${key1}`; } else if (condition === "!empty") { return `!!${key1}`; } else if (condition === "trueAll") { return `$\{${pre1}@all.${value1}.===.true\}`; } else if (condition === "trueOne") { return `$\{${pre1}@one.${value1}.===.true\}`; } else if (condition === "falseAll") { return `$\{${pre1}@all.${value1}.===.false\}`; } else if (condition === "falseOne") { return `$\{${pre1}@one.${value1}.===.false\}`; } else if (condition.includes("All")) { let conditionNew = condition.replace("All", ""); if (conditionNew === "!empty") { conditionNew = "!="; } else if (conditionNew === "empty") { conditionNew = "=="; } return `$\{${pre1}@all.${value1}.${conditionNew}.${value2}\}`; } else if (condition.includes("One")) { let conditionNew = condition.replace("One", ""); if (conditionNew === "!empty") { conditionNew = "!="; } else if (conditionNew === "empty") { conditionNew = "=="; } return `$\{${pre1}@one.${value1}.${conditionNew}.${value2}\}`; } else if (pre1 === "custom") { return value1; } else { return `${key1} ${condition} ${key2}`; } } }) .join(` ${type === 1 ? "&&" : "||"} `); }; const convertStr2Data = (arr: any, level: number = 1) => { const type = arr.find((item: any) => typeof item === "number"); const restArr = arr.filter((item: any) => typeof item !== "number"); return { key: shortid(), level: level, type, children: restArr.map((child: any) => { if (child.some((item: any) => typeof item === "number")) { return convertStr2Data(child, level + 1); } else { return { rowValues: { pre1: child[0], value1: child[1], condition: child[2], pre2: child[3], value2: child[4], }, key: shortid(), level: level, }; } }), }; }; // 入口 const Index = () => { const [state, dispatch] = useReducer(reducer, initValues); const setState = (payload: any) => { dispatch(["saveState", payload]); }; return ( 指令集可视化{" "} { const screenWidth = window.screen.width; const screenHeight = window.screen.height; window.open( location.origin + "/InsSet/指令集说明文档.html", "指令集说明文档", `width=${screenWidth},height=${screenHeight},left=0,top=0` ); }} /> } className={styles.indexCard} > ); }; // 左侧列表区域 const InstructionSetList = () => { const { tableName, sFieldName, baseList, funList, btnsList, instructionList, setState } = useContext(myContext); const addInstruction = (item: any) => { instructionList.push({ ...item, type: item.key, key: shortid(), mode: "easy" }); setState({ instructionList }); }; const ListItem = (item: any) => { return ( {item.title} ); }; let items = []; if (tableName === "master" && sFieldName === "sInstruct") { items = [ { key: "3", label: "按钮指令集", children: ListItem(item)} />, className: styles.collapseItem, }, ]; } else { items = [ { key: "1", label: " 基础指令集", children: ListItem(item)} />, className: styles.collapseItem, }, { key: "2", label: "功能指令集", children: ListItem(item)} />, className: styles.collapseItem, }, ]; } return ( ); }; const getTargetParentAndIndex = ( arr: InstructionItem[], path: number[] ): { parentArr: InstructionItem[]; targetIndex: number; targetItem: InstructionItem } | null => { let current: any = { children: arr }; for (let i = 0; i < path.length - 1; i++) { const index = path[i]; if (!Array.isArray(current.children) || !current.children[index]) return null; current = current.children[index]; } const targetIndex = path[path.length - 1]; const parentArr = current.children || []; const targetItem = parentArr[targetIndex]; return { parentArr, targetIndex, targetItem }; }; const updateInstructionListByMove = ( instructionList: InstructionItem[], fromPath: number[], // 被移动项的原始路径,如 [0, 1, 1] toPath: number[], // 目标插入位置路径,如 [0, 1, 2] insertIndex: number // 插入到该层级下的哪个索引 ): InstructionItem[] => { const deepClone = cloneDeep(instructionList) as InstructionItem[]; // Step 1: 获取要删除的节点及其父级数组和索引 const deleteInfo = getTargetParentAndIndex(deepClone, fromPath); if (!deleteInfo) return instructionList; const { parentArr: deleteParent, targetIndex: deleteIndex, targetItem } = deleteInfo; // Step 2: 删除节点 const deletedItem = deleteParent.splice(deleteIndex, 1)[0]; // Step 3: 获取插入位置的父级数组 const insertInfo = getTargetParentAndIndex(deepClone, toPath); if (!insertInfo) return instructionList; const { parentArr: insertParent } = insertInfo; // Step 4: 插入节点到指定位置 insertParent.splice(insertIndex, 0, deletedItem); return deepClone; }; const InstructionContent = () => { const { instructionList, setState } = useContext(myContext); const [treeData, setTreeData] = useState([]); useEffect(() => { const treeData = instructionList.map(item => { // 递归处理子节点 const processChildren = (nodeItem: any): any => { const treeNode: any = { title: , key: nodeItem.key, // 只有特定类型的节点才允许添加子节点,比如"条件判断" bDropTo: nodeItem.title === "条件判断" || nodeItem.type === "ifdo", }; // 如果有子节点,递归处理 if (nodeItem.children && nodeItem.children.length > 0) { treeNode.children = nodeItem.children.map((child: any) => processChildren(child)); } return treeNode; }; return processChildren(item); }) as any; setTreeData(treeData); }, [JSON.stringify(instructionList)]); const [expandedKeys, setExpandedKeys] = useState([]); const onDrop = (info: any) => { const dropKey = info.node.key; const dragKey = info.dragNode.key; const dropPos = info.node.pos.split("-"); const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]); // 如果节点被放入另一个节点内部,则将其加入展开列表 if (!info.dropToGap) { setExpandedKeys(prev => [...new Set([...prev, dropKey])]); } // 克隆当前 instructionList const newData = cloneDeep(instructionList); // 查找拖拽节点和目标节点 let dragItem: any = null; let dragParent: any[] = newData; let dragIndex = -1; const findDragItem = (items: any[], parent: any[], index: number) => { for (let i = 0; i < items.length; i++) { if (items[i].key === dragKey) { dragItem = items[i]; dragParent = parent; dragIndex = i; return true; } if (items[i].children) { if (findDragItem(items[i].children, items[i].children, i)) { return true; } } } return false; }; findDragItem(newData, newData, -1); // 从原位置删除拖拽节点 if (dragItem) { dragParent.splice(dragIndex, 1); } // 查找目标节点并插入 if (!info.dropToGap) { // 插入为子节点 const insertIntoChildren = (items: any[]) => { for (let i = 0; i < items.length; i++) { if (items[i].key === dropKey) { if (!items[i].children) { items[i].children = []; } items[i].children.unshift(dragItem); return true; } if (items[i].children) { if (insertIntoChildren(items[i].children)) { return true; } } } return false; }; insertIntoChildren(newData); } else { // 插入为兄弟节点 const insertAsSibling = (items: any[]) => { for (let i = 0; i < items.length; i++) { if (items[i].key === dropKey) { const parent = items === newData ? newData : items; const dropIndex = parent.indexOf(items[i]); const insertIndex = dropPosition === -1 ? dropIndex : dropIndex + 1; parent.splice(insertIndex, 0, dragItem); return true; } if (items[i].children) { if (insertAsSibling(items[i].children)) { return true; } } } return false; }; insertAsSibling(newData); } // 更新 instructionList setState({ instructionList: newData }); }; return ( { // 根据节点的自定义属性判断 if (info.dropPosition === 0) { const { bDropTo } = info.dropNode; return !!bDropTo; } return true; }} blockNode showLine onDrop={onDrop} treeData={treeData} /> ); }; // 中间内容区域 const InstructionContent1 = () => { const { instructionList, setState } = useContext(myContext); const listRef = useRef(null); const instructionListRef = useRef(null); useEffect(() => { instructionListRef.current = instructionList; }, [JSON.stringify(instructionList)]); useEffect(() => { const oDom = listRef.current as HTMLElement; new Sortable(oDom, { group: "instructionGroup", // 分组 animation: 150, // 动画时间 ghostClass: styles.draggableItemSelected, // 移动行样式 handle: ".ant-collapse-header", draggable: ".draggable-item", onEnd: evt => { const { from, to, oldIndex, newIndex, item } = evt; // 根据item的data-id获取数据并删除 const dataId = item.getAttribute("data-id") as String; const fromPath = dataId .split("-") .filter((_, index) => index > 0) .map(Number); // 根据to的data-id获取数据并添加到newIndex位置 const toDataId = to.getAttribute("data-id") as String; const toPath = toDataId.split("-").map(Number); const instructionListNew = updateInstructionListByMove( instructionListRef.current, fromPath, toPath, newIndex as number ); setState({ instructionList: instructionListNew }); }, }); }, []); const RecursiveItem = ({ item, level, index }: { item: any; level: number; index: number }) => { const currentLevelClass = `draggable-item lv${level}`; const dataId = `${level - 1}-${index}`; return (
{item.children && item.children.length > 0 && (
{item.children.map((child: any, index1: number) => ( ))}
)}
); }; return (
{instructionList.map((item: any, index) => ( ))}
); }; // 中间内容区域-具体组件 const InstructionDetail = (props: any) => { const { item, dataId } = props; const contentData = useContext(myContext); const { instructionList, setState } = contentData; const [activeKey, setActiveKey] = useState(oThis.activeJson[item.key] || [item.key]); const setInstructionMode = (value: string) => { const { instructionListNew, targetItem } = handleGetChangeData({ ...contentData, ...props }); targetItem.mode = value; setState({ instructionList: instructionListNew }); }; let lableTitle = item.content?.desDataset || item.content?.srcDataset; if (item.type === "print") { lableTitle = `${item.content?.reportName || ""}${item.content?.reportType || ""}`; } let label = `${item.title}${lableTitle ? `【${lableTitle}】` : ""}`; if (item.type === "opensql") { label = `${item.title}${ item.content?.newDataset ? `-> 保存到【${item.content.newDataset}】` : "" }`; } return (
{ setTimeout(() => { if (oThis.changeMode) { oThis.changeMode = false; return; } setActiveKey(keys); oThis.activeJson[item.key] = keys; }, 10); }} items={[ { key: item.key, label, extra: ( {item.bFullMode && ( { oThis.changeMode = true; setInstructionMode(e.target.value); }} /> )} ), children: item.component(props), }, ]} />
); }; // 右侧结果区域 const InstructionResult = () => { const { instructionList, setState, baseList, funList, btnsList, configList = [], srcModelsList = [], } = useContext(myContext); const outputContent = instructionList .filter(item => item.content) .map(item => { if (item.children && item.children.length > 0) { const processChildren = (children: any[]): any[] => { return children .map(child => { if (child.content) { if (child.children && child.children.length > 0) { return { ...child.content, conditions: [ { condition: child.content.condition, commands: processChildren(child.children), }, ], }; } return child.content; } return null; }) .filter(Boolean); }; return { ...item.content, conditions: [ { condition: item.content.condition, commands: processChildren(item.children), }, ], }; } return item.content; }); useEffect(() => { if (!configList.length) return; const configOptions = configList.map((item: any) => ({ label: item.showName, value: item.tableName, tableName: item.sTbName, })); const configValueOptions = configList.reduce((pre: any, cur: any) => { pre[cur.tableName] = cur.gdsconfigformslave .filter((x: any) => x.sName && x.showName && !x.sControlName?.startsWith("Btn")) .map((x: any) => ({ label: x.showName, value: x.sName })); return pre; }, {}); const propsOptions = [ { label: "是否可编辑", value: "enabled", }, { label: "模块id", value: "sSrcModelsId", }, ]; configValueOptions.props = propsOptions; let srcModelsOptions = []; if (srcModelsList.length) { const showKey = Object.keys(srcModelsList[0])[0]; srcModelsOptions = srcModelsList.map((x: any) => ({ label: x[showKey], value: x.sId, })); } setState({ configOptions, configValueOptions, srcModelsOptions }); }, [configList.length]); const onReceiveData = (event: any) => { // 验证来源 if (!document.referrer.includes(event.origin)) { return; } // 处理接收到的命令 if (event.data.command === "initData") { const value = event.data.value || []; // 执行相应操作 setState({ tableName: event.data.tableName, sFieldName: event.data.sFieldName, slave0Data: event.data.slave0Data, configList: event.data.configList, srcModelsList: event.data.srcModelsList, instructionList: value.map((item: any) => { const allList = [...baseList, ...funList, ...btnsList]; const config = allList.find(listItem => listItem.key === item.opr); // const bFullMode = item.bFullMode; // delete item.bFullMode; const result = { ...config, type: config?.key, key: shortid(), mode: "full", content: item, }; // if (bFullMode) { // result.bFullMode = true; // } return result; }), }); } }; useEffect(() => { window.addEventListener("message", onReceiveData); try { window.parent.postMessage( { command: "initData", }, document.referrer ); } catch (error) {} return () => { window.removeEventListener("message", onReceiveData); }; }, []); // 复制到剪贴板 const handleCopy = (bZip: boolean) => { const value = bZip ? JSON.stringify(outputContent) : JSON.stringify(outputContent, null, 2); navigator.clipboard.writeText(value); }; const handleSave = () => { window.parent.postMessage( { command: "saveData", data: outputContent, }, document.referrer ); }; return (
{/* */}
); }; const FormIfdo = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const { form } = commonProps; const conditionType = Form.useWatch("conditionType", form) || "0"; return ( <>
{conditionType === "0" && } {conditionType === "0" ? ( ) : conditionType === "1" ? ( ) : ( )} ); }; // 新增 const FormAdd = (props: any) => { const [formProps, commonProps] = useFormCommon(props); return (
); }; // 编辑 const FormEdit = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const bFullMode = props.item.mode === "full"; return (
{bFullMode && } ); }; // 删除 const FormDel = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const bFullMode = props.item.mode === "full"; return (
{bFullMode && } {bFullMode && } ); }; // 复制 const FormCopy = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const bFullMode = props.item.mode === "full"; return (
{bFullMode && } {bFullMode && } ); }; // 保存 const FormSave = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const { form, configOptions = [] } = commonProps; const saveType = Form.useWatch("saveType", form); const data = Form.useWatch("data", form) || []; return (
{saveType === "saveCustom" && ( <> {(fields, { add, remove }) => ( <> {fields.map(field => { const srcDataset = data[field.name]?.srcDataset; const selectValue = configOptions.some((item: any) => item.value === srcDataset) ? srcDataset : "custom"; return ( { // 给Input赋值 form.setFieldsValue({ data: form.getFieldValue("data").map((item: any, index: number) => index === field.name ? { ...item, srcDataset: value === "custom" ? "" : value, tablename: option.tableName || "", } : item ), }); }} /> } /> remove(field.name)} /> ); })} )} )} ); }; // 过滤 const FormFilter = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const bFullMode = props.item.mode === "full"; return (
{bFullMode && } {bFullMode && } ); }; // 创建新数据集 const FormNewempty = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const radioValue = Form.useWatch("radioValue", formProps.form) || (props.item.content?.desDataset ? "desDataset" : "") || "srcDataset"; return (
{ formProps.form.setFieldValue("radioValue", e.target.value); }} /> {radioValue === "srcDataset" ? ( ) : ( )} ); }; // 清空数据集 const FormEmptyAll = (props: any) => { const [formProps, commonProps] = useFormCommon(props); return (
); }; // 刷新数据集 const FormRefresh = (props: any) => { const [formProps, commonProps] = useFormCommon(props); return (
); }; // 清空选中行 const FormClearRowKey = (props: any) => { const [formProps, commonProps] = useFormCommon(props); return (
); }; // 选中表格第一行 const FormSelectFirstLine = (props: any) => { const [formProps, commonProps] = useFormCommon(props); return (
); }; // 打印 const FormPrint = (props: any) => { const [formProps, commonProps] = useFormCommon({ ...props, formPreFuc: (values: any) => { return { ...values, srcDataset: values.srcDataset?.split(",").filter((item: any) => item), }; }, }); return (
); }; // 查询sql const FormOpenSql = (props: any) => { const [formProps, commonProps] = useFormCommon(props); return (
); }; // 执行sql const FormExesql = (props: any) => { const [formProps, commonProps] = useFormCommon(props); return (
); }; // 消息提示 const FormMsg = (props: any) => { const [formProps, commonProps] = useFormCommon(props); const { form } = commonProps; const codeValue = Form.useWatch("code", form); return (
{ form.submit(); }} /> } > } > ))} )} ); }; const SettingModal = () => { const { setState, settingPorps } = useContext(myContext); const { open, index, name, conditionData } = settingPorps; if (!open) return ""; const initData = { key: shortid(), level: 1, type: 1, children: [ { rowValues: INIT_ROW_VALUES, key: shortid(), level: 1, }, ], }; const [data, setData] = useState( conditionData ? convertStr2Data(JSON.parse(conditionData)) : initData ); const onCancel = () => { setState({ settingPorps: { open: false } }); }; const onOk = () => { const condition = convertData2Str(data, false); const conditionData = JSON.stringify(convertData2Str(data, true)); setState({ settingPorps: { open: false, condition, conditionData, index, name } }); }; return ( } onCancel={onCancel} > } value={data} onChange={(value: any) => { let valueNew = cloneDeep(value); if (!valueNew) { valueNew = initData; } else if (!valueNew.children) { valueNew = { key: shortid(), level: 1, type: 1, children: [value], }; } else if (!valueNew.children.length) { valueNew = initData; } setData(valueNew); }} initValues={INIT_ROW_VALUES} notEmpty={{ data: false }} /> ); }; const useFormCommon = (props: any) => { const { ...rest } = useContext(myContext); const [form] = Form.useForm(); useEffect(() => { const { item, formPreFuc } = props; const { content = {} } = item; const { dataset, data } = content; let initValue = { ...content, dataset: dataset?.split(",").filter((item: any) => item), }; if (data?.length) { initValue.data = data.map((item: any) => { if (item.name && typeof item.name === "string") { return { ...item, name: item.name.split(",").filter((item: any) => item) }; } return item; }); } if (formPreFuc) { initValue = formPreFuc(initValue); } form.setFieldsValue(initValue); }, []); const commonProps = { ...props, ...rest, form, }; const onFinish = () => { handleUpdateData({ ...commonProps }); }; const formProps = { form, labelCol: { flex: "150px" }, wrapperCol: { flex: "auto" }, autoComplete: "off", onFinish, }; return [formProps, commonProps]; }; const CommonInput = (props: any) => { const { form, sName = "desDataset", sLabel = "数据集名称", bMuti, bFilter, bArea, noAddonBefore, extraProps = {}, configOptions = [], } = props; let inputValue = Form.useWatch(sName, form) || []; inputValue = inputValue.toString() || ""; const [valueFilter, afterValue = ""] = inputValue.split("@"); return ( <> {bMuti && ( {">>"}}> { let result = valueFilter; if (value) { result += `@${value}`; } form.setFieldValue(sName, result); }} /> )} ) } // addonAfter={ // } {...extraProps} /> )} ); }; const CommonInputNumber = (props: any) => { const { sName = "time", sLabel = "时间", bMust = false, extraProps = {} } = props; return ( ); }; const CommonCheckBox = (props: any) => { const { sName = "", sLabel = "", extraProps = {} } = props; return ( {sLabel} ); }; const CommonSelect = (props: any) => { const { sName = "reportType", sLabel = "报表类型", options = [] } = props; return ( setSearchValue(value)} onChange={() => { setSearchValue(""); }} options={options} filterSort={(optionA: any, optionB: any) => { const valueA = optionA.value.split("@")[0]; const valueB = optionB.value.split("@")[0]; const bType1 = option0.some((item: any) => item.value === valueA); const bType2 = option0.some((item: any) => item.value === valueB); if (bType1 && !bType2) { return -1; } if (bType2 && !bType1) { return 1; } if (bType1 && bType2) { return ( option0.findIndex((item: any) => item.value === valueA) - option0.findIndex((item: any) => item.value === valueB) ); } if (!bType1 && !bType2) { return ( selectedValues.findIndex((item: any) => item === optionA.value) - selectedValues.findIndex((item: any) => item === optionB.value) ); } return 1; }} optionRender={option => { const value0 = option.value as string; const [label, type = ""] = value0.split("@"); const labelNew = option0.find((item: { value: string }) => item.value === label)?.label || label; return (
{labelNew}
{SIMPLE_DATASET_FILTER_OPTIONS.filter(item => !onlyAllData || !item.value) .map(item => ({ title: item.label, type: item.value, })) .map(item => ( ))}
); }} />
); }; const CommonSValue = (props: any) => { const { form } = props; const dataset = Form.useWatch("dataset", form); const datasetList = dataset ? dataset.map((item: any) => ({ value: item.split("@")[0], label: item.split("@")[0], })) : []; const sValue = Form.useWatch("sValue", form); const tableData = sValue ? sValue.split(",").map((item: any, index: number) => { if (item === "*") { return { iRowNum: index + 1, sFieldNameNew: "", sFieldNameOldPre: "*", sFieldNameOld: "", }; } if (item.includes(".*")) { const sFieldNameOldPre = item.split(".*")[0]; return { iRowNum: index + 1, sFieldNameNew: "", sFieldNameOldPre, sFieldNameOld: "*", }; } const [sFieldNameNew, sFieldNameOld0 = ""] = item.split(":"); let [sFieldNameOldPre, sFieldNameOld] = [undefined as any, ""]; if (sFieldNameOld0.includes("$") || sFieldNameOld0.includes("var")) { [sFieldNameOldPre, sFieldNameOld] = ["var", sFieldNameOld0]; } else if (sFieldNameOld0.includes(".")) { [sFieldNameOldPre, sFieldNameOld] = sFieldNameOld0.split("."); } else if (sFieldNameOld0.includes("'")) { [sFieldNameOldPre, sFieldNameOld] = ["string", sFieldNameOld0.replace(/'/g, "")]; } else if (sFieldNameOld0 !== "") { [sFieldNameOldPre, sFieldNameOld] = ["number", sFieldNameOld0]; } else { [sFieldNameOldPre, sFieldNameOld] = [undefined, ""]; } return { iRowNum: index + 1, sFieldNameNew, sFieldNameOldPre, sFieldNameOld, }; }) : []; const handleChangeValue = (record: any) => { const sValueList = sValue.split(","); const { sFieldNameOldPre, index } = record; if (sFieldNameOldPre === "*") { sValueList[index] = "*"; } else if (sFieldNameOldPre === "number") { sValueList[index] = `${record.sFieldNameNew || ""}:${Number(record.sFieldNameOld) || 0}`; } else if (sFieldNameOldPre === "string") { sValueList[index] = `${record.sFieldNameNew || ""}:'${record.sFieldNameOld || ""}'`; } else if (sFieldNameOldPre === "var") { sValueList[index] = `${record.sFieldNameNew || ""}:${record.sFieldNameOld || "${}"}`; } else if (sFieldNameOldPre) { sValueList[index] = `${record.sFieldNameNew || ""}${ record.sFieldNameOld !== "*" ? ":" : "" }${sFieldNameOldPre}.${record.sFieldNameOld || ""}`; } else { sValueList[index] = `${record.sFieldNameNew || ""}:`; } form.setFieldValue("sValue", sValueList.toString()); }; return ( <> { return ( { handleChangeValue({ ...record, sFieldNameNew: event.target.value, index }); }} /> ); }, }, { title: "源字段", width: "auto", dataIndex: "sFieldNameOld", render: (text: string, record: any, index: number) => { return ( { handleChangeValue({ ...record, sFieldNameOld: event.target.value, index }); }} addonBefore={ { return ( {label}({value}) ); }} value={pre1} showSearch filterOption={(inputValue, option) => { const condition1 = option?.value?.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1; const condition2 = option?.label?.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1; return condition1 || condition2; }} onChange={value => handleChangeValue(value, "pre1")} /> } addonAfter={ !bCustom && ( { const condition1 = option?.value?.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1; const condition2 = option?.label?.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1; return condition1 || condition2; }} onChange={value => handleChangeValue(value, "condition")} /> handleChangeValue(value, "pre2")} /> } value={value2} onChange={e => handleChangeValue(e.target.value, "value2")} {...(() => { if (bModelsId) { return { addonAfter: (