| | |
| | | import React from "react"; |
| | | import { |
| | | CreateBase, |
| | | useTranslate, |
| | | TextInput, |
| | | NumberInput, |
| | | SaveButton, |
| | | SelectInput, |
| | | Toolbar, |
| | | useNotify, |
| | | Form, |
| | | } from 'react-admin'; |
| | | import { |
| | | Dialog, |
| | | DialogActions, |
| | | DialogContent, |
| | | DialogTitle, |
| | | Stack, |
| | | Grid, |
| | | Box, |
| | | } from '@mui/material'; |
| | | import DialogCloseButton from "@/page/components/DialogCloseButton"; |
| | | import StatusSelectInput from "@/page/components/StatusSelectInput"; |
| | | import MemoInput from "@/page/components/MemoInput"; |
| | | import { Create, SimpleForm } from "react-admin"; |
| | | import AiPromptForm from "./AiPromptForm"; |
| | | |
| | | const sceneChoices = [ |
| | | { id: 'general_chat', name: '通用对话' }, |
| | | { id: 'system_diagnose', name: '系统诊断' }, |
| | | ]; |
| | | |
| | | const AiPromptCreate = (props) => { |
| | | const { open, setOpen } = props; |
| | | const translate = useTranslate(); |
| | | const notify = useNotify(); |
| | | |
| | | const handleClose = (event, reason) => { |
| | | if (reason !== "backdropClick") { |
| | | setOpen(false); |
| | | } |
| | | }; |
| | | |
| | | const handleSuccess = async () => { |
| | | setOpen(false); |
| | | notify('common.response.success'); |
| | | }; |
| | | |
| | | const handleError = async (error) => { |
| | | notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } }); |
| | | }; |
| | | |
| | | return ( |
| | | <CreateBase |
| | | record={{ sceneCode: 'system_diagnose', status: 1, publishedFlag: 0 }} |
| | | mutationOptions={{ onSuccess: handleSuccess, onError: handleError }} |
| | | > |
| | | <Dialog open={open} onClose={handleClose} fullWidth disableRestoreFocus maxWidth="md"> |
| | | <Form> |
| | | <DialogTitle sx={{ position: 'sticky', top: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> |
| | | {translate('create.title')} |
| | | <Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}> |
| | | <DialogCloseButton onClose={handleClose} /> |
| | | </Box> |
| | | </DialogTitle> |
| | | <DialogContent sx={{ mt: 2 }}> |
| | | <Grid container rowSpacing={2} columnSpacing={2}> |
| | | <Grid item xs={6}><SelectInput source="sceneCode" label="场景" choices={sceneChoices} fullWidth /></Grid> |
| | | <Grid item xs={6}><TextInput source="templateName" label="模板名称" fullWidth /></Grid> |
| | | <Grid item xs={12}><TextInput source="basePrompt" label="基础提示词" fullWidth multiline minRows={4} /></Grid> |
| | | <Grid item xs={12}><TextInput source="toolPrompt" label="工具提示词" fullWidth multiline minRows={4} /></Grid> |
| | | <Grid item xs={12}><TextInput source="outputPrompt" label="输出提示词" fullWidth multiline minRows={4} /></Grid> |
| | | <Grid item xs={6}><NumberInput source="versionNo" label="版本号" fullWidth /></Grid> |
| | | <Grid item xs={6}><StatusSelectInput fullWidth /></Grid> |
| | | <Grid item xs={12}><Stack direction="column" spacing={1} width={'100%'}><MemoInput /></Stack></Grid> |
| | | </Grid> |
| | | </DialogContent> |
| | | <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> |
| | | <Toolbar sx={{ width: '100%', justifyContent: 'space-between' }}> |
| | | <SaveButton /> |
| | | </Toolbar> |
| | | </DialogActions> |
| | | </Form> |
| | | </Dialog> |
| | | </CreateBase> |
| | | ) |
| | | } |
| | | const AiPromptCreate = () => ( |
| | | <Create redirect="list"> |
| | | <SimpleForm defaultValues={{ code: "home.default", scene: "home", status: 1 }}> |
| | | <AiPromptForm /> |
| | | </SimpleForm> |
| | | </Create> |
| | | ); |
| | | |
| | | export default AiPromptCreate; |