From 9c44e0b229b2e52efe71ad57c71712cc18ca8021 Mon Sep 17 00:00:00 2001 From: Katherine Date: Thu, 8 Aug 2024 13:14:06 +0800 Subject: [PATCH] fix: bug (#5009) --- .../schema-component/common/utils/uitls.tsx | 4 +- .../src/client/schemaSettings.tsx | 45 ++++++++++++------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/packages/core/client/src/schema-component/common/utils/uitls.tsx b/packages/core/client/src/schema-component/common/utils/uitls.tsx index 2b846022be..4c7e4be08a 100644 --- a/packages/core/client/src/schema-component/common/utils/uitls.tsx +++ b/packages/core/client/src/schema-component/common/utils/uitls.tsx @@ -151,9 +151,9 @@ const getVariablesData = (localVariables) => { export async function getRenderContent(templateEngine, content, variables, localVariables, defaultParse) { if (content && templateEngine === 'handlebars') { - const renderedContent = Handlebars.compile(content); - // 处理渲染后的内容 try { + const renderedContent = Handlebars.compile(content); + // 处理渲染后的内容 const data = getVariablesData(localVariables); const html = renderedContent({ ...variables.ctxRef.current, ...data }); return await defaultParse(html); diff --git a/packages/plugins/@nocobase/plugin-block-iframe/src/client/schemaSettings.tsx b/packages/plugins/@nocobase/plugin-block-iframe/src/client/schemaSettings.tsx index 4aed0deea4..ee695c3ac4 100644 --- a/packages/plugins/@nocobase/plugin-block-iframe/src/client/schemaSettings.tsx +++ b/packages/plugins/@nocobase/plugin-block-iframe/src/client/schemaSettings.tsx @@ -87,6 +87,17 @@ const commonOptions: any = { }, }); }; + // 外部定义 description 的内容 + const descriptionContent = ( + <> + + {t('Syntax references')}: + + + Handlebars.js + + + ); return { title: t('Edit iframe'), @@ -129,6 +140,7 @@ const commonOptions: any = { title: '{{t("Template engine")}}', 'x-component': 'Radio.Group', 'x-decorator': 'FormItem', + default: 'string', enum: [ { value: 'string', label: t('String template') }, { value: 'handlebars', label: t('Handlebars') }, @@ -151,24 +163,25 @@ const commonOptions: any = { rows: 10, }, required: true, - description: ( - <> - - {t('Syntax references')}: - - - Handlebars.js - - - ), - 'x-reactions': { - dependencies: ['mode'], - fulfill: { - state: { - hidden: '{{$deps[0] === "url"}}', + description: descriptionContent, + 'x-reactions': [ + { + dependencies: ['mode'], + fulfill: { + state: { + hidden: '{{$deps[0] === "url"}}', + }, }, }, - }, + (field) => { + const { engine } = field.form.values; + if (engine === 'handlebars') { + field.description = descriptionContent; + } else { + field.description = null; + } + }, + ], }, }, } as ISchema,