|  |  |  | 
|---|
|  |  |  | AutocompleteInput, | 
|---|
|  |  |  | Toolbar, | 
|---|
|  |  |  | required, | 
|---|
|  |  |  | useDataProvider, | 
|---|
|  |  |  | PasswordInput, | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | Form, | 
|---|
|  |  |  | useCreateController, | 
|---|
|  |  |  | email, | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | Dialog, | 
|---|
|  |  |  | 
|---|
|  |  |  | import DialogCloseButton from "../components/DialogCloseButton"; | 
|---|
|  |  |  | import StatusSelectInput from "../components/StatusSelectInput"; | 
|---|
|  |  |  | import MemoInput from "../components/MemoInput"; | 
|---|
|  |  |  | import TreeSelectInput from "../components/TreeSelectInput"; | 
|---|
|  |  |  | import RolesSelect from './RolesSelect' | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const UserCreate = (props) => { | 
|---|
|  |  |  | const { open, setOpen } = props; | 
|---|
|  |  |  | 
|---|
|  |  |  | notify('common.response.success'); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleError = async (data) => { | 
|---|
|  |  |  | notify('common.response.fail'); | 
|---|
|  |  |  | const handleError = async (error) => { | 
|---|
|  |  |  | notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } }); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | 
|---|
|  |  |  | disableRestoreFocus | 
|---|
|  |  |  | maxWidth="md"   // 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <Form> | 
|---|
|  |  |  | <Form validate={values => { | 
|---|
|  |  |  | const errors = {}; | 
|---|
|  |  |  | if (!values.username) { | 
|---|
|  |  |  | errors.username = 'ra.validation.required'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!values.nickname) { | 
|---|
|  |  |  | errors.nickname = 'ra.validation.required'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!values.roleIds) { | 
|---|
|  |  |  | errors.roleIds = 'ra.validation.required'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!values.email) { | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | const error = email()(values.email); | 
|---|
|  |  |  | if (error) { | 
|---|
|  |  |  | errors.email = error; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (values.password && values.password !== values.confirmPassword) { | 
|---|
|  |  |  | errors.confirmPassword = 'validate.pwdMisMatch'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return errors; | 
|---|
|  |  |  | }}> | 
|---|
|  |  |  | <DialogTitle id="form-dialog-title" sx={{ | 
|---|
|  |  |  | position: 'sticky', | 
|---|
|  |  |  | top: 0, | 
|---|
|  |  |  | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.password" | 
|---|
|  |  |  | source="password" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.nickname" | 
|---|
|  |  |  | source="nickname" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.avatar" | 
|---|
|  |  |  | source="avatar" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | <TreeSelectInput | 
|---|
|  |  |  | resource="dept" | 
|---|
|  |  |  | label="table.field.user.deptId" | 
|---|
|  |  |  | source="deptId" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.code" | 
|---|
|  |  |  | source="code" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | <RolesSelect | 
|---|
|  |  |  | label="table.field.user.role" | 
|---|
|  |  |  | source="roleIds" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <PasswordInput | 
|---|
|  |  |  | label="table.field.user.password" | 
|---|
|  |  |  | source="password" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <PasswordInput | 
|---|
|  |  |  | label="table.field.user.confirmPwd" | 
|---|
|  |  |  | source="confirmPassword" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | 
|---|
|  |  |  | { id: 1, name: '男' }, | 
|---|
|  |  |  | { id: 2, name: '女' }, | 
|---|
|  |  |  | ]} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.code" | 
|---|
|  |  |  | source="code" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <SelectInput | 
|---|
|  |  |  | label="table.field.user.emailVerified" | 
|---|
|  |  |  | source="emailVerified" | 
|---|
|  |  |  | choices={[ | 
|---|
|  |  |  | { id: 0, name: '否' }, | 
|---|
|  |  |  | { id: 1, name: '是' }, | 
|---|
|  |  |  | ]} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <ReferenceInput | 
|---|
|  |  |  | source="deptId" | 
|---|
|  |  |  | reference="dept" | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <AutocompleteInput | 
|---|
|  |  |  | label="table.field.user.deptId" | 
|---|
|  |  |  | optionText="name" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.realName" | 
|---|
|  |  |  | source="realName" | 
|---|
|  |  |  | 
|---|
|  |  |  | source="idCard" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.birthday" | 
|---|
|  |  |  | source="birthday" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.user.introduction" | 
|---|
|  |  |  | source="introduction" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <StatusSelectInput /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={12} display="flex" gap={1}> | 
|---|
|  |  |  | <Stack direction="column" spacing={1} width={'100%'}> | 
|---|