From 87d3a55c1790cd0b0f64e49d452e8dd54eaded0d Mon Sep 17 00:00:00 2001 From: dengqichen Date: Wed, 12 Nov 2025 21:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=A0=81=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E8=A1=A8=E5=8D=95=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/WARP.md | 1 + .../List/components/TemplateEditor.tsx | 5 ++--- .../List/components/TemplateRender.tsx | 16 +++++++++++++--- .../Deploy/NotificationTemplate/List/service.ts | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 120000 frontend/WARP.md diff --git a/frontend/WARP.md b/frontend/WARP.md new file mode 120000 index 00000000..681311eb --- /dev/null +++ b/frontend/WARP.md @@ -0,0 +1 @@ +CLAUDE.md \ No newline at end of file diff --git a/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateEditor.tsx b/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateEditor.tsx index c37c931a..126be901 100644 --- a/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateEditor.tsx +++ b/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateEditor.tsx @@ -299,9 +299,8 @@ export const TemplateEditor: React.FC = ({ setFormData(data); }} showSubmit={false} - showCancel={false} - readonly={false} - /> + showCancel={false} + /> ) : ( diff --git a/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateRender.tsx b/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateRender.tsx index 6d3c0b16..4280e7f5 100644 --- a/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateRender.tsx +++ b/frontend/src/pages/Deploy/NotificationTemplate/List/components/TemplateRender.tsx @@ -5,6 +5,7 @@ import React, { useState, useEffect } from 'react'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Loader2, AlertCircle } from 'lucide-react'; import { NotificationChannelType } from '../../../NotificationChannel/List/types'; +import { renderTemplate } from '../service'; interface TemplateRenderProps { template: string; @@ -37,10 +38,19 @@ export const TemplateRender: React.FC = ({ setError(null); try { - // 不调用render接口,直接使用模板内容 - setPreviewContent(template); + // 调用后端 render API 进行 FreeMarker 模板渲染 + // 后端返回格式: { success: true, data: "渲染后的内容", message: "操作成功", code: 200 } + // request 工具会自动解析并返回 data 字段 + const renderedContent = await renderTemplate( + template, // templateContext + formData || {} // params + ); + + setPreviewContent(renderedContent); + setError(null); } catch (error: any) { - setError('渲染失败'); + console.error('Template render error:', error); + setError(error.response?.data?.message || error.message || '渲染失败'); setPreviewContent(''); } finally { setLoading(false); diff --git a/frontend/src/pages/Deploy/NotificationTemplate/List/service.ts b/frontend/src/pages/Deploy/NotificationTemplate/List/service.ts index c01c1685..d3fe7821 100644 --- a/frontend/src/pages/Deploy/NotificationTemplate/List/service.ts +++ b/frontend/src/pages/Deploy/NotificationTemplate/List/service.ts @@ -122,7 +122,7 @@ export const checkTemplateCodeUnique = async ( export const renderTemplate = async ( templateContext: string, params: Record -): Promise<{ content: string; success: boolean; error?: string }> => { +): Promise => { return request.post(`${API_PREFIX}/render`, { templateContext, params