zhou zhou
12 小时以前 287a666e1b2bb155e86aa88ebace201d1e8a51f6
rsf-admin/src/page/system/aiPrompt/AiPromptList.jsx
@@ -10,6 +10,7 @@
    useListContext,
    useNotify,
    useRefresh,
    useTranslate,
} from "react-admin";
import {
    Box,
@@ -35,11 +36,11 @@
const filters = [
    <SearchInput source="condition" alwaysOn />,
    <TextInput source="code" label="编码" />,
    <TextInput source="scene" label="场景" />,
    <TextInput source="code" label="ai.prompt.fields.code" />,
    <TextInput source="scene" label="ai.prompt.fields.scene" />,
    <SelectInput
        source="status"
        label="状态"
        label="common.field.status"
        choices={[
            { id: "1", name: "common.enums.statusTrue" },
            { id: "0", name: "common.enums.statusFalse" },
@@ -61,6 +62,7 @@
};
const AiPromptCards = ({ onView, onEdit, onDelete, deleting }) => {
    const translate = useTranslate();
    const { data, isLoading } = useListContext();
    const records = useMemo(() => (Array.isArray(data) ? data : []), [data]);
@@ -76,9 +78,9 @@
        return (
            <Box px={2} py={6}>
                <Card variant="outlined" sx={{ p: 3, textAlign: "center", borderStyle: "dashed" }}>
                    <Typography variant="subtitle1">暂无 Prompt 配置</Typography>
                    <Typography variant="subtitle1">{translate("ai.prompt.list.emptyTitle")}</Typography>
                    <Typography variant="body2" color="text.secondary" mt={1}>
                        新建一张 Prompt 卡片后,AI 对话会动态加载这里的内容。
                        {translate("ai.prompt.list.emptyDescription")}
                    </Typography>
                </Card>
            </Box>
@@ -111,29 +113,27 @@
                                    <Chip
                                        size="small"
                                        color={record.statusBool ? "success" : "default"}
                                        label={record.statusBool ? "启用" : "停用"}
                                        label={translate(record.statusBool ? "ai.common.enabled" : "ai.common.disabled")}
                                    />
                                </Stack>
                                <Stack direction="row" spacing={1} flexWrap="wrap" useFlexGap mt={1.5}>
                                    <Chip size="small" variant="outlined" label={`Scene: ${record.scene || "--"}`} />
                                    <Chip size="small" variant="outlined" label={translate("ai.prompt.list.sceneValue", { value: record.scene || "--" })} />
                                </Stack>
                                <Divider sx={{ my: 1.5 }} />
                                <Typography variant="caption" color="text.secondary">System Prompt</Typography>
                                <Typography variant="caption" color="text.secondary">{translate("ai.prompt.fields.systemPrompt")}</Typography>
                                <Typography variant="body2" sx={{ mt: 0.5 }}>
                                    {truncateText(record.systemPrompt)}
                                </Typography>
                                <Typography variant="caption" color="text.secondary" display="block" mt={1.5}>
                                    User Prompt Template
                                </Typography>
                                <Typography variant="caption" color="text.secondary" display="block" mt={1.5}>{translate("ai.prompt.fields.userPromptTemplate")}</Typography>
                                <Typography variant="body2">{truncateText(record.userPromptTemplate, 100)}</Typography>
                            </CardContent>
                            <CardActions sx={{ px: 2, pb: 2, pt: 0, justifyContent: "space-between" }}>
                                <Stack direction="row" spacing={1}>
                                    <Button size="small" startIcon={<VisibilityOutlinedIcon />} onClick={() => onView(record.id)}>
                                        详情
                                        {translate("ai.common.detail")}
                                    </Button>
                                    <Button size="small" startIcon={<EditOutlinedIcon />} onClick={() => onEdit(record.id)}>
                                        编辑
                                        {translate("common.button.edit")}
                                    </Button>
                                </Stack>
                                <Button
@@ -143,7 +143,7 @@
                                    onClick={() => onDelete(record)}
                                    disabled={deleting}
                                >
                                    删除
                                    {translate("ai.common.delete")}
                                </Button>
                            </CardActions>
                        </Card>
@@ -155,6 +155,7 @@
};
const AiPromptList = () => {
    const translate = useTranslate();
    const notify = useNotify();
    const refresh = useRefresh();
    const [deleteOne, { isPending: deleting }] = useDelete();
@@ -164,7 +165,7 @@
    const closeDialog = () => setDialogState({ open: false, mode: "create", recordId: null });
    const handleDelete = (record) => {
        if (!record?.id || !window.confirm(`确认删除“${record.name}”吗?`)) {
        if (!record?.id || !window.confirm(translate("ai.common.confirmDelete", { name: record.name }))) {
            return;
        }
        deleteOne(
@@ -172,20 +173,20 @@
            { id: record.id },
            {
                onSuccess: () => {
                    notify("删除成功");
                    notify(translate("ai.common.deleteSuccess"));
                    refresh();
                },
                onError: (error) => {
                    notify(error?.message || "删除失败", { type: "error" });
                    notify(error?.message || translate("ai.common.deleteFailed"), { type: "error" });
                },
            }
        );
    };
    const dialogTitle = {
        create: "新建 Prompt",
        edit: "编辑 Prompt",
        show: "查看 Prompt 详情",
        create: translate("ai.prompt.dialog.create"),
        edit: translate("ai.prompt.dialog.edit"),
        show: translate("ai.prompt.dialog.show"),
    }[dialogState.mode];
    return (
@@ -198,7 +199,7 @@
                    <TopToolbar>
                        <FilterButton />
                        <Button variant="contained" startIcon={<AddRoundedIcon />} onClick={() => openDialog("create")}>
                            新建
                            {translate("ai.common.new")}
                        </Button>
                        <MyExportButton />
                    </TopToolbar>