feat(backend): 新增 QuickJS 运行时支持 JavaScript 执行器
refactor(backend): 重构 script_js 执行器实现 JavaScript 文件/内联脚本执行 feat(backend): 变量节点支持表达式/引用快捷语法输入 docs: 添加变量节点使用文档说明快捷语法功能 style(frontend): 调整测试面板样式和布局 fix(frontend): 修复测试面板打开时自动关闭节点编辑侧栏 build(backend): 添加 rquickjs 依赖用于 JavaScript 执行
This commit is contained in:
@ -31,6 +31,24 @@ function getFlowIdFromUrl(): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
// 新增:针对后端的 design_json 兼容性转换
|
||||
// - 将前端 UI 的 type: 'code' 映射为后端可识别并映射到 script_js 执行器的 'javascript'
|
||||
// - 其余字段保持不变
|
||||
function transformDesignJsonForBackend(json: any): any {
|
||||
try {
|
||||
const clone = JSON.parse(JSON.stringify(json));
|
||||
clone.nodes = (clone.nodes || []).map((n: any) => {
|
||||
if (n && n.type === 'code') {
|
||||
return { ...n, type: 'javascript' };
|
||||
}
|
||||
return n;
|
||||
});
|
||||
return clone;
|
||||
} catch {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export class CustomService {
|
||||
@inject(FreeLayoutPluginContext) ctx!: FreeLayoutPluginContext;
|
||||
@ -52,7 +70,9 @@ export class CustomService {
|
||||
}
|
||||
const json = this.document.toJSON() as any;
|
||||
const yaml = stringifyFlowDoc(json);
|
||||
const design_json = JSON.stringify(json);
|
||||
// 使用转换后的 design_json,以便后端将 code 节点识别为 javascript 并选择 script_js 执行器
|
||||
const designForBackend = transformDesignJsonForBackend(json);
|
||||
const design_json = JSON.stringify(designForBackend);
|
||||
const { data } = await api.put<ApiResp<{ saved: boolean }>>(`/flows/${id}`, { yaml, design_json });
|
||||
if (data?.code === 0) {
|
||||
if (!silent) Toast.success(I18n.t('Saved'));
|
||||
|
||||
Reference in New Issue
Block a user