import Icon from '@ant-design/icons' import { hasPermission } from '@/util/auth' import { r_sys_settings_mail_get, r_sys_settings_mail_send, r_sys_settings_mail_update } from '@/services/system' import { SettingsCard } from '@/pages/System/Settings' const Mail = () => { const [modal, contextHolder] = AntdModal.useModal() const [mailForm] = AntdForm.useForm() const mailFormValues = AntdForm.useWatch([], mailForm) const [loading, setLoading] = useState(false) const [mailSendForm] = AntdForm.useForm() const handleOnTest = () => { void modal.confirm({ title: '发送测试邮件', centered: true, maskClosable: true, footer: (_, { OkBtn, CancelBtn }) => ( <> ), content: ( <> { setTimeout(() => { // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access ref?.getFieldInstance('to').focus() }, 50) }} > 将使用服务器已保存的邮件设置进行发送邮件,请保证编辑的内容已保存 ), onOk: () => mailSendForm.validateFields().then( () => { return new Promise((resolve) => { void r_sys_settings_mail_send({ to: mailSendForm.getFieldValue('to') as string }).then((res) => { const response = res.data if (response.success) { void message.success('发送成功') resolve() } else { void message.error('发送失败,请检查配置后重试') resolve() } }) }) }, () => { return new Promise((_, reject) => { reject('输入有误') }) } ) }) } const handleOnReset = () => { getMailSettings() } const handleOnSave = () => { void r_sys_settings_mail_update(mailFormValues).then((res) => { const response = res.data if (response.success) { void message.success('保存设置成功') getMailSettings() } else { void message.error('保存设置失败,请稍后重试') } }) } const getMailSettings = () => { if (loading) { return } setLoading(true) void r_sys_settings_mail_get().then((res) => { const response = res.data if (response.success) { const data = response.data data && mailForm.setFieldsValue(data) setLoading(false) } }) } useEffect(() => { getMailSettings() }, []) return ( <> } > None SSL/TLS StartTls {contextHolder} ) } export default Mail