增加代码编辑器表单组件
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);
|
setFormData(data);
|
||||||
}}
|
}}
|
||||||
showSubmit={false}
|
showSubmit={false}
|
||||||
showCancel={false}
|
showCancel={false}
|
||||||
readonly={false}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user