增加代码编辑器表单组件
This commit is contained in:
parent
160917c074
commit
87d3a55c17
1
frontend/WARP.md
Symbolic link
1
frontend/WARP.md
Symbolic link
@ -0,0 +1 @@
|
||||
CLAUDE.md
|
||||
@ -299,9 +299,8 @@ export const TemplateEditor: React.FC<TemplateEditorProps> = ({
|
||||
setFormData(data);
|
||||
}}
|
||||
showSubmit={false}
|
||||
showCancel={false}
|
||||
readonly={false}
|
||||
/>
|
||||
showCancel={false}
|
||||
/>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
) : (
|
||||
|
||||
@ -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<TemplateRenderProps> = ({
|
||||
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);
|
||||
|
||||
@ -122,7 +122,7 @@ export const checkTemplateCodeUnique = async (
|
||||
export const renderTemplate = async (
|
||||
templateContext: string,
|
||||
params: Record<string, any>
|
||||
): Promise<{ content: string; success: boolean; error?: string }> => {
|
||||
): Promise<string> => {
|
||||
return request.post(`${API_PREFIX}/render`, {
|
||||
templateContext,
|
||||
params
|
||||
|
||||
Loading…
Reference in New Issue
Block a user