|  |  |  | 
|---|
|  |  |  | DeleteButton, | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | useRedirect, | 
|---|
|  |  |  | useEditContext, | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import { useWatch, useFormContext } from "react-hook-form"; | 
|---|
|  |  |  | import { Stack, Grid, Box, Typography } from '@mui/material'; | 
|---|
|  |  |  | import * as Common from '@/utils/common'; | 
|---|
|  |  |  | import { EDIT_MODE, REFERENCE_INPUT_PAGESIZE } from '@/config/setting'; | 
|---|
|  |  |  | import EditBaseAside from "../../../components/EditBaseAside"; | 
|---|
|  |  |  | import CustomerTopToolBar from "../../../components/EditTopToolBar"; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const FormToolbar = () => { | 
|---|
|  |  |  | const form = useFormContext(); | 
|---|
|  |  |  | const { record, isPending } = useEditContext(); | 
|---|
|  |  |  | const redirect = useRedirect(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const onSuccess = (data) => { | 
|---|
|  |  |  | const { dictTypeId, dictTypeCode } = data | 
|---|
|  |  |  | notify(`修改成功!`); | 
|---|
|  |  |  | redirect(`/dictData?dictTypeId=${dictTypeId}&code=${dictTypeCode}`); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Toolbar sx={{ justifyContent: 'space-between' }}> | 
|---|
|  |  |  | <SaveButton type="button" mutationOptions={{ onSuccess }} /> | 
|---|
|  |  |  | <Toolbar sx={{ justifyContent: 'end' }}> | 
|---|
|  |  |  | <SaveButton type="button" mutationOptions={{onSuccess:() => { | 
|---|
|  |  |  | redirect('/dictType/' + record?.dictTypeId) | 
|---|
|  |  |  | } }}/> | 
|---|
|  |  |  | <DeleteButton mutationMode="optimistic" /> | 
|---|
|  |  |  | </Toolbar> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | 
|---|
|  |  |  | const DictDataEdit = () => { | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Edit | 
|---|
|  |  |  | redirect="list" | 
|---|
|  |  |  | resource="dictData" | 
|---|
|  |  |  | mutationMode={EDIT_MODE} | 
|---|
|  |  |  | actions={<CustomerTopToolBar backPrevious={true} />} | 
|---|
|  |  |  | aside={<EditBaseAside />} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <SimpleForm | 
|---|
|  |  |  | shouldUnregister | 
|---|
|  |  |  | warnWhenUnsavedChanges | 
|---|
|  |  |  | toolbar={<FormToolbar />} | 
|---|
|  |  |  | mode="onTouched" | 
|---|
|  |  |  | defaultValues={{}} | 
|---|
|  |  |  | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.dictData.dictTypeId" | 
|---|
|  |  |  | source="dictTypeId" | 
|---|
|  |  |  | readOnly | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | autoFocus | 
|---|
|  |  |  | validate={required()} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Stack> | 
|---|
|  |  |  | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.dictData.dictTypeCode" | 
|---|
|  |  |  | source="dictTypeCode" | 
|---|
|  |  |  | readOnly | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | validate={required()} | 
|---|
|  |  |  | /> | 
|---|