import { Divider, Input, InputNumber } from "antd"; import type { ITaskData } from "../../api/task"; import "../article/article.css"; import { useEffect, useState } from "react"; import ChannelSelectWithToken from "../channel/ChannelSelectWithToken"; import type { TChannelType } from "../../api/Channel"; import type { TPower } from "../../api/token"; type TParamType = | "number" | "string" | "channel:translation" | "channel:nissaya"; export interface IParam { key: string; label: string; value: string; type: TParamType; initValue: number; step: number; } export interface IProp { taskTitle: string; taskId: string; param?: IParam[]; } interface IWidget { workflow?: ITaskData[]; channelsId?: string[]; book?: number; para?: number; onChange?: (data: IProp[] | undefined) => void; } const TaskBuilderProp = ({ workflow, channelsId, book, para, onChange, }: IWidget) => { //console.debug("TaskBuilderProp render"); const [prop, setProp] = useState(); useEffect(() => { const newProp = workflow?.map((item) => { const num = item.description ?.replaceAll("}}", "|}}") .split("|") .filter((value) => value.includes("=?")) .map((item) => { const [k, v] = item.split("="); const value: IParam = { key: k, label: k, value: v, type: "number", initValue: 1, step: v === "?++" ? 1 : v === "?+" ? 0 : -1, }; return value; }); const constant = item.description ?.replaceAll("}}", "|}}") .split("|") .filter((value) => value.includes("=%")) .map((item) => { const [_k, v] = item.split("="); const paramKey = v.split("@"); const value: IParam = { key: v, label: paramKey[0], value: "", type: paramKey.length > 1 && paramKey[1] ? (paramKey[1] as TParamType) : "string", initValue: 0, step: 0, }; return value; }); let output: IParam[] = []; if (num) { output = [...output, ...num]; } if (constant) { output = [...output, ...constant]; } return { taskTitle: item.title, taskId: item.id, param: output, }; }); setProp(newProp); }, [workflow]); const change = ( tIndex: number, pIndex: number, value: string, initValue: number, step: number ) => { const newData = prop?.map((item, tId) => { return { taskTitle: item.taskTitle, taskId: item.taskId, param: item.param?.map((param, pId) => { if (tIndex === tId && pIndex === pId) { return { ...param, value: value, initValue: initValue, step: step }; } else { return param; } }), }; }); setProp(newData); console.debug("newData", newData); onChange && onChange(newData); }; const Value = (item: IParam, taskId: number, paramId: number) => { let channelType: string | undefined; const [_key, channel, power] = item.key.replaceAll("%", "").split("@"); if (item.key.includes("@channel")) { if (channel.includes(":")) { channelType = channel.split(":")[1].replaceAll("%", ""); } } return item.type === "number" ? ( { if (e) { change(taskId, paramId, item.value, e, item.step); } }} /> ) : item.type === "string" ? ( { if (e) { change(taskId, paramId, e.target.value, item.initValue, item.step); } }} /> ) : ( { console.debug("channel select onChange", e); change(taskId, paramId, e ?? "", item.initValue, item.step); }} /> ); }; const Step = (item: IParam, taskId: number, paramId: number) => { return item.type === "string" ? ( <>{"无"} ) : item.value === "?" ? ( <>{"无"} ) : ( { if (e) { change(taskId, paramId, item.value, item.initValue, e); } }} /> ); }; return ( <> {prop?.map((item, taskId) => { return (
{item.taskTitle} {item.param?.map((item, paramId) => { return ( ); })}
变量名 递增步长
{item.label} {Value(item, taskId, paramId)} {Step(item, taskId, paramId)}
); })} ); }; export default TaskBuilderProp;