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