(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 (
);
};
// 删除
const FormDel = (props: any) => {
const [formProps, commonProps] = useFormCommon(props);
const bFullMode = props.item.mode === "full";
return (
);
};
// 复制
const FormCopy = (props: any) => {
const [formProps, commonProps] = useFormCommon(props);
const bFullMode = props.item.mode === "full";
return (
);
};
// 保存
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 (
);
};
// 创建新数据集
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 (
);
};
// 按钮组件
const FormBtnHandle = (props: any) => {
const [formProps, commonProps] = useFormCommon(props);
const { slave0Data, setState, settingPorps = {} } = useContext(myContext);
const { form } = commonProps;
const selectData = useMemo(
() =>
slave0Data
?.filter((item: any) => item.bVisible && item.sControlName?.startsWith("Btn"))
.map((item: any) => ({
label: item.sChinese,
value: item.sControlName,
})) || [],
[!!slave0Data]
);
const { open, condition, conditionData, index, name } = settingPorps;
useEffect(() => {
if (!open) {
const data = [...(form.getFieldValue("data") || [])];
if (condition && conditionData) {
data[index][name] = condition;
data[index][`${name}Data`] = conditionData;
form.setFieldValue("data", data);
} else if (conditionData == "[1]") {
delete data[index][name];
delete data[index][`${name}Data`];
}
setTimeout(() => {
setState({
settingPorps: {},
});
form.submit();
}, 100);
}
}, [open]);
const handleOpenSettingModal = (index: number, name: string) => {
const itemData = form.getFieldValue("data")[index];
if (!itemData) {
message.error("请先选择按钮名称!");
return;
}
setState({
settingPorps: {
open: true,
index,
name,
conditionData: form.getFieldValue("data")[index][`${name}Data`],
},
});
};
const removeLine = (index: number) => {
const data = [...form.getFieldValue("data")];
data.splice(index, 1);
form.setFieldValue("data", data);
form.submit();
};
return (
{(fields, { add, remove }) => (
<>
{fields.map((field, index) => (
<>
配置{index + 1}
removeLine(index)}
/>
配
置
}
>
配
置
}
>
>
))}
>
)}
);
};
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 && (
)}
{bArea ? (
) : (
{">>"}}>
>
);
};
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 (
);
};
const CommonSingleChoice = (props: any) => {
const { sName = "bPreviewOnly", sLabel = "不显示打印" } = props;
return (
{sLabel}
);
};
const CommonDataset = (props: any) => {
const {
form,
sName = "dataset",
sLabel = "辅助数据集",
onlyAllData,
bMust,
configOptions = [],
} = props;
const searchRef = useRef(null);
const [searchValue, setSearchValue] = useState("");
// 获取当前已选择的值
const selectedValues = Form.useWatch(sName, form) || [];
if (typeof selectedValues === "string" && selectedValues) {
form.setFieldsValue({ [sName]: selectedValues.split(",") });
return null;
}
const option0 = configOptions.map((item: { label: any; value: any }) => ({
...item,
label: `${item.label}(${item.value})`,
}));
// 根据已选择的值动态生成选项
const options = useMemo(() => {
return option0.filter(
(item: { value: string }) =>
!selectedValues.some((i: string) => i.split("@")[0] === item.value)
);
}, [selectedValues]);
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={
{
handleChangeValue({
...record,
sFieldNameOldPre: value,
sFieldNameOld: "",
index,
});
}}
/>
}
/>
);
},
},
{
title: () => {
return (
操作
);
},
width: 150,
dataIndex: "operation",
render: (_, _1, index) => {
return (
);
},
},
]}
locale={{ emptyText: "暂无数据" }}
pagination={false}
scroll={{ y: 410 }}
/>
>
);
};
const MyFilterRulesGroup = ({ dataSetList, rowValues, rowKey, onChange, form }: any) => {
const {
configOptions = [],
configValueOptions = {},
srcModelsOptions = [],
} = useContext(myContext);
const { pre1, value1, condition, pre2, value2 } = rowValues;
const bHasDataset = !!form?.getFieldValue("dataset");
let conditionOption = CONDITION_DATA; // 条件下拉
let hide2 = false; // pre2、value2隐藏
let showRaido = false; // 显示raido选择框
let bModelsId = value1 === "sSrcModelsId"; // 是否模块id
let bCustom = pre1 === "custom"; // 自定义代码
//如果pre1为slave之类
if (
pre1 &&
value1 &&
pre1 !== "master" &&
configOptions.some((item: any) => item.value === pre1) &&
!bHasDataset
) {
// value1为b开头
if (value1.startsWith("b")) {
hide2 = true;
conditionOption = CONDITION_DATA_TYPEB;
} else {
conditionOption = CONDITION_DATA_TYPE_NOTB;
}
}
// 如果是模块id且pre1为props|master,condition取前两个
if (bModelsId && ["props", "master"].includes(pre1)) {
conditionOption = [conditionOption[0], conditionOption[1]];
}
// 如果条件包含empty字段
if (condition?.includes("empty")) {
hide2 = true;
}
if (["props", "master"].includes(pre1) && (value1?.startsWith("b") || value1 === "enabled")) {
showRaido = true;
}
// condition默认为第一个
useEffect(() => {
if (!condition || !conditionOption.some((item: any) => item.value === condition)) {
onChange(rowKey, { ...rowValues, condition: conditionOption[0].value });
}
}, [pre1]);
// 如果hide2为true,保证pre2、value2为空
useEffect(() => {
if (hide2 && (pre2 || value2)) {
onChange(rowKey, { ...rowValues, pre2: undefined, value2: "" });
}
}, [hide2]);
// 如果显示raido选择框且condition不包含empty字段时,默认condition为是
useEffect(() => {
if (showRaido && !condition?.includes("empty")) {
onChange(rowKey, { ...rowValues, condition: "!empty", pre2: undefined, value2: "" });
}
}, [showRaido]);
// 如果value1为s|i|d|t开头且hide2为false
useEffect(() => {
let addState = {} as any;
// condition默认为第一个
if (!condition || !conditionOption.some((item: any) => item.value === condition)) {
addState.condition = conditionOption[0].value;
}
if (
value1?.startsWith("s") ||
value1?.startsWith("i") ||
value1?.startsWith("d") ||
value1?.startsWith("t")
) {
if (!hide2 && (value1?.startsWith("s") || value1?.startsWith("t"))) {
// 如果pre2不是string,设置为string
if (pre2 !== "string") {
addState.pre2 = "string";
}
}
if (!hide2 && (value1?.startsWith("i") || value1?.startsWith("d"))) {
// 如果pre2不是number,设置为number
if (pre2 !== "number") {
addState.pre2 = "number";
}
}
}
if (JSON.stringify(addState) !== "{}") {
onChange(rowKey, { ...rowValues, ...addState });
}
}, [value1, condition]);
// 自定义时多余字段清空
useEffect(() => {
if (bCustom) {
onChange(rowKey, { ...rowValues, condition: undefined, pre2: undefined, value2: "" });
}
}, [bCustom]);
const handleChangeValue = (value: any, key: string) => {
let changeValue = { pre1, value1, condition, pre2, value2, [key]: value };
onChange(rowKey, changeValue);
};
const options = [
...dataSetList,
...PROPS_OPTIONS,
...(!bHasDataset ? configOptions : []),
{ label: "自定义", value: "custom" },
];
return (
{
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 && (
item.value === value1) ? value1 : null
}
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;
}}
optionRender={({ label, value }) => {
return (
{label}({value})
);
}}
onChange={value => handleChangeValue(value, "value1")}
/>
)
}
value={value1}
onChange={e => handleChangeValue(e.target.value, "value1")}
/>
{(() => {
if (bCustom) return "";
if (showRaido) {
return (
handleChangeValue(e.target.value, "condition")}
value={condition}
optionType="button"
buttonStyle="solid"
/>
);
}
return (
<>
{
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: (
item.value === value2)
? value2
: null
}
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, "value2")}
/>
),
};
}
return {};
})()}
/>
>
);
})()}
);
};
const CommonCondition = (props: any) => {
const { form, item, dependsWith } = props;
const typeJson = SIMPLE_DATASET_FILTER_OPTIONS.reduce((pre: any, item) => {
pre[item.value] = item.label;
return pre;
}, {});
const desDataset = Form.useWatch("desDataset", form) || "";
const dataset = Form.useWatch("dataset", form) || [];
const dataSetList = dataset.map((item: any) => ({
label: item.split("@")[0] + typeJson[item.split("@")[1] || ""],
value: item.split("@")[0],
}));
const initData = {
key: shortid(),
level: 1,
type: 1,
children: [
{
rowValues: INIT_ROW_VALUES,
key: shortid(),
level: 1,
},
],
};
const [data, setData] = useState(initData);
const conditionData = Form.useWatch("conditionData", form);
const flag = useRef(0);
useEffect(() => {
if (flag.current > 2) return;
if (conditionData) {
const dataNew = JSON.parse(conditionData);
if (dataNew.length >= 2) {
setData(convertStr2Data(dataNew));
}
}
}, [conditionData]);
let preDataSetList = desDataset
? [{ label: `${desDataset}每条数据`, value: `${desDataset}One` }]
: [];
if (item.type === "filter") {
const srcDataset = Form.useWatch("srcDataset", form) || "";
const srcDatasetNew = srcDataset.split("@")[0];
preDataSetList = srcDataset
? [{ label: `${srcDatasetNew}每条数据`, value: `${srcDatasetNew}One` }]
: [];
} else if (item.type === "edit") {
const desDatasetNew = desDataset.split("@")[0];
preDataSetList = desDataset
? [{ label: `${desDatasetNew}每条数据`, value: `${desDatasetNew}One` }]
: [];
} else if (dependsWith) {
// const dataset = Form.useWatch(dependsWith, form) || [];
// preDataSetList = dataset.length ? [{ label: `${dataset[0].split("@")[0]}One`, value: `${dataset[0].split("@")[0]}One` }] : [];
}
return (
<>
(
)}
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);
flag.current++;
form.setFieldValue("condition", convertData2Str(valueNew, false));
form.setFieldValue("conditionData", JSON.stringify(convertData2Str(valueNew, true)));
}}
initValues={INIT_ROW_VALUES}
notEmpty={{ data: false }}
/>
>
);
};
const CommonSaveBtn = (props: any) => {
return (
);
};
const handleGetChangeData = (props: any) => {
const { instructionList, item } = props;
const instructionListNew = cloneDeep(instructionList) as InstructionItem[];
const findNodePath = (treeData: any[], key: string, path: number[] = []): number[] | null => {
for (let i = 0; i < treeData.length; i++) {
const node = treeData[i];
// 如果当前节点匹配key,返回当前路径
if (node.key === key) {
return [...path, i];
}
// 如果当前节点有子节点,递归查找
if (node.children && node.children.length > 0) {
const foundPath = findNodePath(node.children, key, [...path, i]);
if (foundPath) {
return foundPath;
}
}
}
// 未找到返回null
return null;
};
const targetNodePath = findNodePath(instructionListNew, item.key) || [];
let targetItem = instructionListNew as any;
for (let i = 0; i < targetNodePath.length; i++) {
if (i === targetNodePath.length - 1) {
targetItem = targetItem[targetNodePath[i]];
} else {
targetItem = targetItem[targetNodePath[i]].children;
}
}
return {
instructionListNew,
targetItem,
targetNodePath,
};
};
const handleUpdateData = (props: any, handleType = "update") => {
const { setState, form, item } = props;
const { instructionListNew, targetItem, targetNodePath } = handleGetChangeData(props);
if (handleType == "update") {
// Step 2: 修改节点
const values = form.getFieldsValue();
targetItem.content = Object.keys(values).reduce(
(pre: { opr: any; [key: string]: any }, key) => {
if (key === "data" && values[key].length) {
pre[key] = values[key].map((item: any) => {
if (item.name && typeof item.name === "object") {
return {
...item,
name: item.name.join(","),
};
} else {
return item;
}
});
} else if (typeof values[key] === "object" && key !== "data") {
pre[key] = values[key].join(",");
} else if (values[key]) {
pre[key] = values[key];
}
return pre;
},
{ opr: item.type }
) as any;
} else if (handleType == "delete") {
// Step 2: 删除节点
let evalStr = "instructionListNew";
for (let i = 0; i < targetNodePath.length; i++) {
if (i === targetNodePath.length - 1) {
evalStr += `.splice(${targetNodePath[i]}, 1)`;
} else {
evalStr += `[${targetNodePath[i]}].children`;
}
}
eval(evalStr);
}
setState({ instructionList: instructionListNew });
};
export default Index;