chen.lin
2 天以前 9140aee230de0ef41de9682a9353fbd372e2bcaa
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
85
86
87
88
89
90
91
import React from "react";
import {
    CreateBase,
    useTranslate,
    TextInput,
    NumberInput,
    SaveButton,
    SelectInput,
    Toolbar,
    Form,
    required,
    useNotify,
} from 'react-admin';
import { Dialog, DialogContent, DialogTitle, Grid, Box } from '@mui/material';
import DialogCloseButton from "@/page/components/DialogCloseButton";
 
const OpenApiAppCreate = (props) => {
    const { open, setOpen } = props;
    const notify = useNotify();
 
    const handleClose = (event, reason) => {
        if (reason !== "backdropClick") setOpen(false);
    };
 
    const handleSuccess = () => {
        setOpen(false);
        notify('新增成功');
    };
 
    const handleError = (error) => {
        notify(error?.message || '新增失败', { type: 'error' });
    };
 
    return (
        <CreateBase
            resource="openApiApp"
            record={{}}
            mutationOptions={{ onSuccess: handleSuccess, onError: handleError }}
        >
            <Dialog
                open={open}
                onClose={handleClose}
                fullWidth
                disableRestoreFocus
                maxWidth="sm"
            >
                <Form>
                    <DialogTitle sx={{ position: 'sticky', top: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
                        新增应用
                        <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={12}>
                                <TextInput label="应用ID" source="id" validate={required()} fullWidth />
                            </Grid>
                            <Grid item xs={12}>
                                <TextInput label="应用密钥" source="screct" validate={required()} fullWidth />
                            </Grid>
                            <Grid item xs={12}>
                                <TextInput label="应用名称" source="name" fullWidth />
                            </Grid>
                            <Grid item xs={12}>
                                <TextInput label="应用URL" source="url" fullWidth />
                            </Grid>
                            <Grid item xs={12}>
                                <SelectInput
                                    label="启用状态"
                                    source="enable"
                                    choices={[
                                        { id: 1, name: '启用' },
                                        { id: 0, name: '未启用' },
                                    ]}
                                    defaultValue={1}
                                    fullWidth
                                />
                            </Grid>
                        </Grid>
                    </DialogContent>
                    <Box sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000, p: 2, display: 'flex', justifyContent: 'flex-end' }}>
                        <Toolbar><SaveButton /></Toolbar>
                    </Box>
                </Form>
            </Dialog>
        </CreateBase>
    );
};
 
export default OpenApiAppCreate;