模版解析正确
This commit is contained in:
parent
dbcfec2bba
commit
3c3342a94d
@ -12,25 +12,38 @@ interface FormFields {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理JSON字符串中的转义字符
|
||||||
|
const parseJsonSafely = (jsonString: string) => {
|
||||||
|
try {
|
||||||
|
// 处理Windows风格的换行符
|
||||||
|
const processed = jsonString.replace(/\r\n/g, '\n')
|
||||||
|
// 处理转义字符
|
||||||
|
.replace(/\\/g, '\\\\')
|
||||||
|
// 处理引号
|
||||||
|
.replace(/\\"/g, '\\"');
|
||||||
|
return JSON.parse(processed);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('JSON解析错误:', error);
|
||||||
|
console.debug('原始JSON字符串:', jsonString);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const NodeConfig: React.FC<NodeConfigProps> = ({ nodeType, form, onValuesChange }) => {
|
const NodeConfig: React.FC<NodeConfigProps> = ({ nodeType, form, onValuesChange }) => {
|
||||||
// 解析节点配置模式
|
// 解析节点配置模式
|
||||||
const nodeSchema = useMemo(() => {
|
const nodeSchema = useMemo(() => {
|
||||||
try {
|
if (!nodeType.configSchema) {
|
||||||
return JSON.parse(nodeType.configSchema);
|
console.warn('节点配置模式为空');
|
||||||
} catch (error) {
|
|
||||||
console.error('解析节点配置模式失败:', error);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return parseJsonSafely(nodeType.configSchema);
|
||||||
}, [nodeType.configSchema]);
|
}, [nodeType.configSchema]);
|
||||||
|
|
||||||
// 解析节点默认配置
|
// 解析节点默认配置
|
||||||
const nodeDefaultConfig = useMemo(() => {
|
const nodeDefaultConfig = useMemo(() => {
|
||||||
try {
|
if (!nodeType.defaultConfig) return {};
|
||||||
return nodeType.defaultConfig ? JSON.parse(nodeType.defaultConfig) : {};
|
const config = parseJsonSafely(nodeType.defaultConfig);
|
||||||
} catch (error) {
|
return config || {};
|
||||||
console.error('解析节点默认配置失败:', error);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}, [nodeType.defaultConfig]);
|
}, [nodeType.defaultConfig]);
|
||||||
|
|
||||||
// 当前选中的执行器
|
// 当前选中的执行器
|
||||||
@ -40,13 +53,8 @@ const NodeConfig: React.FC<NodeConfigProps> = ({ nodeType, form, onValuesChange
|
|||||||
const executorSchema = useMemo(() => {
|
const executorSchema = useMemo(() => {
|
||||||
if (!selectedExecutor || !nodeType.executors) return null;
|
if (!selectedExecutor || !nodeType.executors) return null;
|
||||||
const executor = nodeType.executors.find(e => e.code === selectedExecutor);
|
const executor = nodeType.executors.find(e => e.code === selectedExecutor);
|
||||||
if (!executor) return null;
|
if (!executor || !executor.configSchema) return null;
|
||||||
try {
|
return parseJsonSafely(executor.configSchema);
|
||||||
return JSON.parse(executor.configSchema);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('解析执行器配置模式失败:', error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, [selectedExecutor, nodeType.executors]);
|
}, [selectedExecutor, nodeType.executors]);
|
||||||
|
|
||||||
// 获取当前执行器的默认配置
|
// 获取当前执行器的默认配置
|
||||||
@ -54,12 +62,8 @@ const NodeConfig: React.FC<NodeConfigProps> = ({ nodeType, form, onValuesChange
|
|||||||
if (!selectedExecutor || !nodeType.executors) return {};
|
if (!selectedExecutor || !nodeType.executors) return {};
|
||||||
const executor = nodeType.executors.find(e => e.code === selectedExecutor);
|
const executor = nodeType.executors.find(e => e.code === selectedExecutor);
|
||||||
if (!executor || !executor.defaultConfig) return {};
|
if (!executor || !executor.defaultConfig) return {};
|
||||||
try {
|
const config = parseJsonSafely(executor.defaultConfig);
|
||||||
return JSON.parse(executor.defaultConfig);
|
return config || {};
|
||||||
} catch (error) {
|
|
||||||
console.error('解析执行器默认配置失败:', error);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}, [selectedExecutor, nodeType.executors]);
|
}, [selectedExecutor, nodeType.executors]);
|
||||||
|
|
||||||
// 当执行器变更时,重置执行器相关的配置
|
// 当执行器变更时,重置执行器相关的配置
|
||||||
@ -124,7 +128,11 @@ const NodeConfig: React.FC<NodeConfigProps> = ({ nodeType, form, onValuesChange
|
|||||||
|
|
||||||
// 添加正则校验
|
// 添加正则校验
|
||||||
if (pattern) {
|
if (pattern) {
|
||||||
rules.push({ pattern: new RegExp(pattern), message: `格式不正确` });
|
try {
|
||||||
|
rules.push({ pattern: new RegExp(pattern), message: `格式不正确` });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('正则表达式解析错误:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let formItem;
|
let formItem;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user