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";
|
|
const routeChoices = [
|
{ id: 'general_chat', name: '通用对话' },
|
{ id: 'system_diagnose', name: '系统诊断' },
|
];
|
|
const AiRouteCreate = (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={{ routeCode: 'general_chat', priority: 1, failCount: 0, successCount: 0, status: 1 }}
|
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="routeCode" label="路由编码" choices={routeChoices} fullWidth /></Grid>
|
<Grid item xs={6}><TextInput source="modelCode" label="模型编码" fullWidth /></Grid>
|
<Grid item xs={6}><NumberInput source="priority" 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>
|
)
|
}
|
|
export default AiRouteCreate;
|