From 05148eeef860d33232874a640dbd67ba43ac5686 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期四, 19 三月 2026 12:51:49 +0800
Subject: [PATCH] #AI.配置中心可运营化

---
 rsf-admin/src/page/system/aiPrompt/AiPromptForm.jsx |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/rsf-admin/src/page/system/aiPrompt/AiPromptForm.jsx b/rsf-admin/src/page/system/aiPrompt/AiPromptForm.jsx
index 5920bd5..5c6ad35 100644
--- a/rsf-admin/src/page/system/aiPrompt/AiPromptForm.jsx
+++ b/rsf-admin/src/page/system/aiPrompt/AiPromptForm.jsx
@@ -1,9 +1,106 @@
-import React from "react";
+import React, { useState } from "react";
 import {
+    FormDataConsumer,
     TextInput,
+    useNotify,
 } from "react-admin";
-import { Grid, Typography } from "@mui/material";
+import { Alert, Button, Grid, Stack, TextField, Typography } from "@mui/material";
 import StatusSelectInput from "@/page/components/StatusSelectInput";
+import { renderAiPromptPreview } from "@/api/ai/configCenter";
+
+const AiPromptPreviewSection = ({ formData }) => {
+    const notify = useNotify();
+    const [input, setInput] = useState("璇峰府鎴戞�荤粨褰撳墠椤甸潰鑳藉仛浠�涔�");
+    const [metadataText, setMetadataText] = useState("{\"path\":\"/system/aiPrompt\"}");
+    const [preview, setPreview] = useState(null);
+    const [loading, setLoading] = useState(false);
+
+    const handlePreview = async () => {
+        setLoading(true);
+        try {
+            const metadata = metadataText ? JSON.parse(metadataText) : {};
+            const data = await renderAiPromptPreview({
+                ...formData,
+                input,
+                metadata,
+            });
+            setPreview(data);
+            notify("Prompt 棰勮瀹屾垚");
+        } catch (error) {
+            setPreview(null);
+            notify(error?.message || "Prompt 棰勮澶辫触", { type: "error" });
+        } finally {
+            setLoading(false);
+        }
+    };
+
+    return (
+        <>
+            <Grid item xs={12}>
+                <Typography variant="h6">Prompt 棰勮</Typography>
+            </Grid>
+            <Grid item xs={12}>
+                <TextField
+                    label="绀轰緥杈撳叆"
+                    value={input}
+                    onChange={(event) => setInput(event.target.value)}
+                    fullWidth
+                    multiline
+                    minRows={3}
+                />
+            </Grid>
+            <Grid item xs={12}>
+                <TextField
+                    label="绀轰緥鍏冩暟鎹� JSON"
+                    value={metadataText}
+                    onChange={(event) => setMetadataText(event.target.value)}
+                    fullWidth
+                    multiline
+                    minRows={3}
+                />
+            </Grid>
+            <Grid item xs={12}>
+                <Stack direction="row" spacing={1} alignItems="center">
+                    <Button variant="outlined" onClick={handlePreview} disabled={loading}>
+                        {loading ? "棰勮涓�..." : "棰勮娓叉煋"}
+                    </Button>
+                    <Typography variant="body2" color="text.secondary">
+                        鐢ㄥ綋鍓嶈〃鍗曞唴瀹规覆鏌� System Prompt 鍜� User Prompt銆�
+                    </Typography>
+                </Stack>
+            </Grid>
+            {preview && (
+                <>
+                    <Grid item xs={12}>
+                        <Alert severity="success">
+                            宸茶В鏋愬彉閲忥細{(preview.resolvedVariables || []).join(", ") || "鏃�"}
+                        </Alert>
+                    </Grid>
+                    <Grid item xs={12}>
+                        <TextField
+                            label="娓叉煋鍚庣殑 System Prompt"
+                            value={preview.renderedSystemPrompt || ""}
+                            fullWidth
+                            multiline
+                            minRows={5}
+                            InputProps={{ readOnly: true }}
+                        />
+                    </Grid>
+                    <Grid item xs={12}>
+                        <TextField
+                            label="娓叉煋鍚庣殑 User Prompt"
+                            value={preview.renderedUserPrompt || ""}
+                            fullWidth
+                            multiline
+                            minRows={5}
+                            InputProps={{ readOnly: true }}
+                        />
+                    </Grid>
+                </>
+            )}
+        </>
+    );
+};
 
 const AiPromptForm = ({ readOnly = false }) => (
     <Grid container spacing={2} width={{ xs: "100%", xl: "80%" }}>
@@ -31,6 +128,18 @@
         <Grid item xs={12}>
             <TextInput source="memo" label="澶囨敞" fullWidth multiline minRows={3} disabled={readOnly} />
         </Grid>
+        <FormDataConsumer>
+            {({ formData }) => <AiPromptPreviewSection formData={formData} />}
+        </FormDataConsumer>
+        <Grid item xs={12}>
+            <Typography variant="h6">杩愯涓庡璁′俊鎭�</Typography>
+        </Grid>
+        <Grid item xs={12} md={6}>
+            <TextInput source="updateBy" label="鏈�杩戞洿鏂颁汉" fullWidth disabled />
+        </Grid>
+        <Grid item xs={12} md={6}>
+            <TextInput source="updateTime$" label="鏈�杩戞洿鏂版椂闂�" fullWidth disabled />
+        </Grid>
     </Grid>
 );
 

--
Gitblit v1.9.1