import { useIntl } from "react-intl"; import { ProForm, ProFormText } from "@ant-design/pro-components"; import { Alert, type AlertProps } from "antd" import { post } from "../../../request"; import { useState } from "react"; import { get as getUiLang } from "../../../locales"; import { fullUrl } from "../../../utils"; interface IForgotPasswordRequest { email: string; lang: string; dashboard: string; } interface IFormData { email: string; } interface IForgotPasswordResponse { ok: boolean; message: string; data: string; } const Widget = () => { const intl = useIntl(); const [notify, setNotify] = useState( intl.formatMessage({ id: "message.send.reset.email", }) ); const [type, setType] = useState("info"); return ( <> {notify ? : <>} onFinish={async (values: IFormData) => { console.debug(values); const user: IForgotPasswordRequest = { email: values.email, lang: getUiLang(), dashboard: fullUrl(""), }; const url = "/v2/auth/forgot-password"; console.info("forgot password url", url, user); try { const result = await post< IForgotPasswordRequest, IForgotPasswordResponse >(url, user); if (result.ok) { console.debug("token", result.data); setNotify( intl.formatMessage({ id: "message.send.reset.email.successful", }) ); setType("success"); } else { setType("error"); setNotify(result.message); } } catch (error) { setType("error"); setNotify("服务器内部错误"); console.error(error); } }} > ); }; export default Widget;