| | |
| | | Toolbar, |
| | | useNotify, |
| | | useRefresh, |
| | | useTranslate, |
| | | } from "react-admin"; |
| | | import { |
| | | Button, |
| | |
| | | DialogTitle, |
| | | } from "@mui/material"; |
| | | |
| | | const DialogFormToolbar = ({ onClose }) => ( |
| | | const DialogFormToolbar = ({ onClose, translate }) => ( |
| | | <Toolbar sx={{ justifyContent: "space-between", px: 0 }}> |
| | | <Button onClick={onClose}>取消</Button> |
| | | <Button onClick={onClose}>{translate("ai.common.cancel")}</Button> |
| | | <SaveButton /> |
| | | </Toolbar> |
| | | ); |
| | |
| | | }) => { |
| | | const notify = useNotify(); |
| | | const refresh = useRefresh(); |
| | | const translate = useTranslate(); |
| | | |
| | | if (!open) { |
| | | return null; |
| | | } |
| | | |
| | | const handleSuccess = () => { |
| | | notify(mode === "create" ? "保存成功" : "更新成功"); |
| | | notify(translate(mode === "create" ? "ai.common.saveSuccess" : "ai.common.updateSuccess")); |
| | | refresh(); |
| | | onClose(); |
| | | }; |
| | | |
| | | const handleError = (error) => { |
| | | notify(error?.message || "操作失败", { type: "error" }); |
| | | notify(error?.message || translate("ai.common.operationFailed"), { type: "error" }); |
| | | }; |
| | | |
| | | const formContent = ( |
| | | <SimpleForm |
| | | defaultValues={mode === "create" ? defaultValues : undefined} |
| | | toolbar={mode === "show" ? false : <DialogFormToolbar onClose={onClose} />} |
| | | toolbar={mode === "show" ? false : <DialogFormToolbar onClose={onClose} translate={translate} />} |
| | | sx={{ |
| | | "& .RaSimpleForm-form": { |
| | | maxWidth: "100%", |
| | |
| | | </DialogContent> |
| | | {mode === "show" && ( |
| | | <DialogActions> |
| | | <Button onClick={onClose}>关闭</Button> |
| | | <Button onClick={onClose}>{translate("ai.common.close")}</Button> |
| | | </DialogActions> |
| | | )} |
| | | </Dialog> |