增加代码编辑器表单组件

This commit is contained in:
dengqichen 2025-11-12 21:54:42 +08:00
parent 160917c074
commit 87d3a55c17
4 changed files with 17 additions and 7 deletions

1
frontend/WARP.md Symbolic link
View File

@ -0,0 +1 @@
CLAUDE.md

View File

@ -300,7 +300,6 @@ export const TemplateEditor: React.FC<TemplateEditorProps> = ({
}} }}
showSubmit={false} showSubmit={false}
showCancel={false} showCancel={false}
readonly={false}
/> />
</div> </div>
</ScrollArea> </ScrollArea>

View File

@ -5,6 +5,7 @@ import React, { useState, useEffect } from 'react';
import { Alert, AlertDescription } from '@/components/ui/alert'; import { Alert, AlertDescription } from '@/components/ui/alert';
import { Loader2, AlertCircle } from 'lucide-react'; import { Loader2, AlertCircle } from 'lucide-react';
import { NotificationChannelType } from '../../../NotificationChannel/List/types'; import { NotificationChannelType } from '../../../NotificationChannel/List/types';
import { renderTemplate } from '../service';
interface TemplateRenderProps { interface TemplateRenderProps {
template: string; template: string;
@ -37,10 +38,19 @@ export const TemplateRender: React.FC<TemplateRenderProps> = ({
setError(null); setError(null);
try { try {
// 不调用render接口直接使用模板内容 // 调用后端 render API 进行 FreeMarker 模板渲染
setPreviewContent(template); // 后端返回格式: { success: true, data: "渲染后的内容", message: "操作成功", code: 200 }
// request 工具会自动解析并返回 data 字段
const renderedContent = await renderTemplate(
template, // templateContext
formData || {} // params
);
setPreviewContent(renderedContent);
setError(null);
} catch (error: any) { } catch (error: any) {
setError('渲染失败'); console.error('Template render error:', error);
setError(error.response?.data?.message || error.message || '渲染失败');
setPreviewContent(''); setPreviewContent('');
} finally { } finally {
setLoading(false); setLoading(false);

View File

@ -122,7 +122,7 @@ export const checkTemplateCodeUnique = async (
export const renderTemplate = async ( export const renderTemplate = async (
templateContext: string, templateContext: string,
params: Record<string, any> params: Record<string, any>
): Promise<{ content: string; success: boolean; error?: string }> => { ): Promise<string> => {
return request.post(`${API_PREFIX}/render`, { return request.post(`${API_PREFIX}/render`, {
templateContext, templateContext,
params params