#
luxiaotao1123
2024-09-10 9776a87bb29d147da919cedb3e4f897263f2b499
zy-acs-flow/src/page/user/UserEdit.jsx
@@ -19,6 +19,7 @@
    required,
    useRecordContext,
    DeleteButton,
    PasswordInput,
} from 'react-admin';
import { useWatch, useFormContext } from "react-hook-form";
import { Stack, Grid, Box, Typography } from '@mui/material';
@@ -28,6 +29,8 @@
import CustomerTopToolBar from "../components/EditTopToolBar";
import MemoInput from "../components/MemoInput";
import StatusSelectInput from "../components/StatusSelectInput";
import RolesSelect from "./RolesSelect";
import TreeSelectInput from "../components/TreeSelectInput";
const FormToolbar = () => {
    const { getValues } = useFormContext();
@@ -56,7 +59,32 @@
                toolbar={<FormToolbar />}
                mode="onTouched"
                defaultValues={{}}
            // validate={(values) => { }}
                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) {
                        errors.password = 'ra.validation.required';
                    }
                    if (values.password && values.password !== values.confirmPassword) {
                        errors.confirmPassword = 'validate.pwdMisMatch';
                    }
                    return errors;
                }}
            >
                <Grid container width={{ xs: '100%', xl: '80%' }} rowSpacing={3} columnSpacing={3}>
                    <Grid item xs={12} md={8}>
@@ -71,32 +99,9 @@
                                autoFocus
                                validate={required()}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.password"
                                source="password"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.nickname"
                                source="nickname"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.avatar"
                                source="avatar"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.code"
                                source="code"
                                parse={v => v}
                            />
                        </Stack>
@@ -110,6 +115,11 @@
                                    { id: 2, name: '女' },
                                ]}
                            />
                            <TextInput
                                label="table.field.user.code"
                                source="code"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
@@ -117,8 +127,6 @@
                                source="phone"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.email"
                                source="email"
@@ -126,34 +134,11 @@
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <SelectInput
                                label="table.field.user.emailVerified"
                                source="emailVerified"
                                choices={[
                                    { id: 0, name: '否' },
                                    { id: 1, name: '是' },
                                ]}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <ReferenceInput
                                source="deptId"
                                reference="dept"
                            >
                                <AutocompleteInput
                                    label="table.field.user.deptId"
                                    optionText="name"
                                />
                            </ReferenceInput>
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.realName"
                                source="realName"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.idCard"
                                source="idCard"
@@ -166,21 +151,55 @@
                                source="birthday"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.user.introduction"
                                multiline
                                source="introduction"
                                parse={v => v}
                            />
                        </Stack>
                        <Typography variant="h6" gutterBottom>
                            {translate('common.edit.title.changePwd')}
                        </Typography>
                        <Stack direction='row' gap={2}>
                            <PasswordInput
                                label="table.field.user.password"
                                source="password"
                            />
                            <PasswordInput
                                label="table.field.user.confirmPwd"
                                source="confirmPassword"
                            />
                        </Stack>
                    </Grid>
                    <Grid item xs={12} md={4}>
                        <Typography variant="h6" gutterBottom>
                            {translate('common.edit.title.common')}
                        </Typography>
                        <StatusSelectInput />
                        <Stack direction='row' gap={2}>
                            <TreeSelectInput
                                label="table.field.user.deptId"
                                value={record?.deptId}
                            />
                            <ReferenceInput
                                source="deptId"
                                reference="dept"
                            >
                                <AutocompleteInput
                                    label="table.field.user.deptId"
                                    optionText="name"
                                />
                            </ReferenceInput>
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <RolesSelect
                                label="table.field.user.role"
                                source="roleIds"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <StatusSelectInput />
                        </Stack>
                        <Box mt="2em" />
                        <MemoInput />
                    </Grid>