#
zhou zhou
1 天以前 2ce6327ec49e7fe73cc1cd3bcc2b63b28d89d38f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;