|
|
|
@ -16,16 +16,17 @@
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
import { Container } from '@/components/Container';
|
|
|
|
|
import { SMS_PROVIDER } from '@/constant';
|
|
|
|
|
import { EMAIL_PROVIDER } from '@/constant';
|
|
|
|
|
import { disableMailProvider, getMailProviderConfig, saveMailProvider } from '../../service';
|
|
|
|
|
import { EyeInvisibleOutlined, EyeTwoTone, WarningOutlined } from '@ant-design/icons';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
ProCard,
|
|
|
|
|
ProForm,
|
|
|
|
|
ProFormDependency,
|
|
|
|
|
ProFormDigit,
|
|
|
|
|
ProFormRadio,
|
|
|
|
|
ProFormSelect,
|
|
|
|
|
ProFormSegmented,
|
|
|
|
|
ProFormSwitch,
|
|
|
|
|
ProFormText,
|
|
|
|
|
} from '@ant-design/pro-components';
|
|
|
|
@ -63,12 +64,11 @@ const tailFormItemLayout = {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
const defaultProvider = 'customize';
|
|
|
|
|
|
|
|
|
|
export default (props: { visible: boolean }) => {
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
const { message, modal } = App.useApp();
|
|
|
|
|
const { visible } = props;
|
|
|
|
|
const [provider, setProvider] = useState<string>(defaultProvider);
|
|
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
|
|
const [enabled, setEnabled] = useState<boolean>(false);
|
|
|
|
|
const intl = useIntl();
|
|
|
|
@ -79,12 +79,9 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
const { success, result } = await getMailProviderConfig();
|
|
|
|
|
if (success && result && result.enabled) {
|
|
|
|
|
setEnabled(result.enabled);
|
|
|
|
|
setProvider(result.provider);
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
...result,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
form.setFieldsValue({ provider: provider });
|
|
|
|
|
}
|
|
|
|
|
setLoading(false);
|
|
|
|
|
return;
|
|
|
|
@ -126,11 +123,7 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
if (success) {
|
|
|
|
|
setEnabled(checked);
|
|
|
|
|
message.success(intl.formatMessage({ id: 'app.operation_success' }));
|
|
|
|
|
setProvider(defaultProvider);
|
|
|
|
|
form.resetFields();
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
provider: defaultProvider,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -148,16 +141,15 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
<ProForm
|
|
|
|
|
form={form}
|
|
|
|
|
scrollToFirstError
|
|
|
|
|
initialValues={{ safetyType: 'ssl', provider: defaultProvider }}
|
|
|
|
|
initialValues={{ safetyType: 'ssl', provider: 'customize' }}
|
|
|
|
|
onReset={() => {
|
|
|
|
|
form.resetFields();
|
|
|
|
|
form.setFieldsValue({ provider });
|
|
|
|
|
}}
|
|
|
|
|
{...layout}
|
|
|
|
|
layout={'horizontal'}
|
|
|
|
|
labelAlign={'right'}
|
|
|
|
|
submitter={{
|
|
|
|
|
render: (p, dom) => {
|
|
|
|
|
render: (_p, dom) => {
|
|
|
|
|
return (
|
|
|
|
|
<Form.Item {...tailFormItemLayout}>
|
|
|
|
|
<Space>{dom}</Space>
|
|
|
|
@ -194,56 +186,61 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<ProFormSelect
|
|
|
|
|
<ProFormSegmented
|
|
|
|
|
name="provider"
|
|
|
|
|
label={intl.formatMessage({ id: 'pages.setting.message.mail_provider.provider' })}
|
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
|
fieldProps={{
|
|
|
|
|
onChange: async (value: string) => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
setProvider(value);
|
|
|
|
|
form.resetFields();
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
provider: value,
|
|
|
|
|
});
|
|
|
|
|
const { success, result } = await getMailProviderConfig();
|
|
|
|
|
if (success && result && result.enabled && value === result.provider) {
|
|
|
|
|
setEnabled(result.enabled);
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
...result,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setLoading(false);
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
options={[
|
|
|
|
|
request={async () => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
value: 'customize',
|
|
|
|
|
value: EMAIL_PROVIDER.CUSTOMIZE,
|
|
|
|
|
label: intl.formatMessage({
|
|
|
|
|
id: 'pages.setting.message.mail_provider.provider.customize',
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: SMS_PROVIDER.ALIYUN,
|
|
|
|
|
value: EMAIL_PROVIDER.ALIYUN,
|
|
|
|
|
label: intl.formatMessage({
|
|
|
|
|
id: 'pages.setting.message.mail_provider.provider.aliyun',
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: SMS_PROVIDER.TENCENT,
|
|
|
|
|
value: EMAIL_PROVIDER.TENCENT,
|
|
|
|
|
label: intl.formatMessage({
|
|
|
|
|
id: 'pages.setting.message.mail_provider.provider.tencent',
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: SMS_PROVIDER.NET_EASE,
|
|
|
|
|
value: EMAIL_PROVIDER.NET_EASE,
|
|
|
|
|
label: intl.formatMessage({
|
|
|
|
|
id: 'pages.setting.message.mail_provider.provider.net_ease',
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
];
|
|
|
|
|
}}
|
|
|
|
|
fieldProps={{
|
|
|
|
|
onChange: async (value) => {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
form.resetFields();
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
provider: value,
|
|
|
|
|
});
|
|
|
|
|
const { success, result } = await getMailProviderConfig();
|
|
|
|
|
if (success && result && result.enabled && value === result.provider) {
|
|
|
|
|
setEnabled(result.enabled);
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
...result,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setLoading(false);
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{provider === 'customize' && (
|
|
|
|
|
<ProFormDependency name={['provider']}>
|
|
|
|
|
{({ provider }) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{provider === EMAIL_PROVIDER.CUSTOMIZE && (
|
|
|
|
|
<>
|
|
|
|
|
<ProFormText
|
|
|
|
|
name="smtpUrl"
|
|
|
|
@ -304,7 +301,7 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
<ProFormText
|
|
|
|
|
name="username"
|
|
|
|
|
label={
|
|
|
|
|
provider === defaultProvider
|
|
|
|
|
provider === EMAIL_PROVIDER.CUSTOMIZE
|
|
|
|
|
? intl.formatMessage({
|
|
|
|
|
id: 'pages.setting.message.mail_provider.provider.username',
|
|
|
|
|
})
|
|
|
|
@ -313,7 +310,7 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
placeholder={
|
|
|
|
|
provider === defaultProvider
|
|
|
|
|
provider === EMAIL_PROVIDER.CUSTOMIZE
|
|
|
|
|
? intl.formatMessage({
|
|
|
|
|
id: 'pages.setting.message.mail_provider.provider.username.placeholder',
|
|
|
|
|
})
|
|
|
|
@ -322,7 +319,7 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
rules={
|
|
|
|
|
provider === defaultProvider
|
|
|
|
|
provider === EMAIL_PROVIDER.CUSTOMIZE
|
|
|
|
|
? [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
@ -348,6 +345,10 @@ export default (props: { visible: boolean }) => {
|
|
|
|
|
}
|
|
|
|
|
fieldProps={{ autoComplete: 'off' }}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</ProFormDependency>
|
|
|
|
|
<ProFormText.Password
|
|
|
|
|
name="secret"
|
|
|
|
|
label={intl.formatMessage({
|
|
|
|
|