优化消息配置

pull/82/head^2
awenes 8 months ago
parent 4f86c9700d
commit 289da3e46a

@ -51,6 +51,15 @@ export enum GEO_IP_PROVIDER {
DEFAULT = 'default',
}
export enum EMAIL_PROVIDER {
CUSTOMIZE = 'customize',
ALIYUN = 'aliyun',
TENCENT = 'tencent',
NET_EASE = 'netease',
}
/**
*
*/
@ -65,12 +74,9 @@ export enum AppType {
* App Protocol
*/
export enum AppProtocolType {
saml2 = 'saml2',
oidc = 'oidc',
cas = 'cas',
jwt = 'jwt',
form = 'form',
oauth2 = 'oauth2',
}
export enum PolicyEffectType {

@ -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,14 +186,41 @@ export default (props: { visible: boolean }) => {
}
}}
>
<ProFormSelect
<ProFormSegmented
name="provider"
label={intl.formatMessage({ id: 'pages.setting.message.mail_provider.provider' })}
rules={[{ required: true }]}
request={async () => {
return [
{
value: EMAIL_PROVIDER.CUSTOMIZE,
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize',
}),
},
{
value: EMAIL_PROVIDER.ALIYUN,
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.aliyun',
}),
},
{
value: EMAIL_PROVIDER.TENCENT,
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.tencent',
}),
},
{
value: EMAIL_PROVIDER.NET_EASE,
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.net_ease',
}),
},
];
}}
fieldProps={{
onChange: async (value: string) => {
onChange: async (value) => {
setLoading(true);
setProvider(value);
form.resetFields();
form.setFieldsValue({
provider: value,
@ -216,138 +235,120 @@ export default (props: { visible: boolean }) => {
setLoading(false);
},
}}
options={[
{
value: 'customize',
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize',
}),
},
{
value: SMS_PROVIDER.ALIYUN,
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.aliyun',
}),
},
{
value: SMS_PROVIDER.TENCENT,
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.tencent',
}),
},
{
value: SMS_PROVIDER.NET_EASE,
label: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.net_ease',
}),
},
]}
/>
{provider === 'customize' && (
<>
<ProFormText
name="smtpUrl"
label={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.smtp_url',
})}
placeholder={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.smtp_url.placeholder',
})}
rules={[
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.smtp_url.placeholder',
}),
},
]}
fieldProps={{ autoComplete: 'off' }}
/>
<ProFormDigit
label={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.port',
})}
name="port"
rules={[
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.port_rule_0.placeholder',
}),
},
]}
fieldProps={{ autoComplete: 'off' }}
min={0}
placeholder={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.port_rule_0.placeholder',
})}
/>
<ProFormRadio.Group
name="safetyType"
label={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.safety_type',
})}
rules={[{ required: true }]}
options={[
{
label: 'None',
value: 'none',
},
{
label: 'SSL',
value: 'ssl',
},
]}
/>
</>
)}
<ProFormText
name="username"
label={
provider === defaultProvider
? intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.username',
})
: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox',
})
}
placeholder={
provider === defaultProvider
? intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.username.placeholder',
})
: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox.placeholder',
})
}
rules={
provider === defaultProvider
? [
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.username.placeholder',
}),
},
]
: [
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox.placeholder',
}),
},
{
type: 'email',
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox.rule.rule.0.message',
}),
},
]
}
fieldProps={{ autoComplete: 'off' }}
/>
<ProFormDependency name={['provider']}>
{({ provider }) => {
return (
<>
{provider === EMAIL_PROVIDER.CUSTOMIZE && (
<>
<ProFormText
name="smtpUrl"
label={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.smtp_url',
})}
placeholder={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.smtp_url.placeholder',
})}
rules={[
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.smtp_url.placeholder',
}),
},
]}
fieldProps={{ autoComplete: 'off' }}
/>
<ProFormDigit
label={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.port',
})}
name="port"
rules={[
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.port_rule_0.placeholder',
}),
},
]}
fieldProps={{ autoComplete: 'off' }}
min={0}
placeholder={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.port_rule_0.placeholder',
})}
/>
<ProFormRadio.Group
name="safetyType"
label={intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.customize.safety_type',
})}
rules={[{ required: true }]}
options={[
{
label: 'None',
value: 'none',
},
{
label: 'SSL',
value: 'ssl',
},
]}
/>
</>
)}
<ProFormText
name="username"
label={
provider === EMAIL_PROVIDER.CUSTOMIZE
? intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.username',
})
: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox',
})
}
placeholder={
provider === EMAIL_PROVIDER.CUSTOMIZE
? intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.username.placeholder',
})
: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox.placeholder',
})
}
rules={
provider === EMAIL_PROVIDER.CUSTOMIZE
? [
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.username.placeholder',
}),
},
]
: [
{
required: true,
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox.placeholder',
}),
},
{
type: 'email',
message: intl.formatMessage({
id: 'pages.setting.message.mail_provider.provider.sender_mailbox.rule.rule.0.message',
}),
},
]
}
fieldProps={{ autoComplete: 'off' }}
/>
</>
);
}}
</ProFormDependency>
<ProFormText.Password
name="secret"
label={intl.formatMessage({

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { SMS_PROVIDER } from '@/constant';
import { Language } from '../../constant';
import { Language } from '@/pages/setting/Storage/constant';
import {
disableSmsProvider,
getSmsProviderConfig,
@ -33,7 +33,7 @@ import {
ModalForm,
ProCard,
ProForm,
ProFormSelect,
ProFormSegmented,
ProFormSwitch,
ProFormText,
} from '@ant-design/pro-components';
@ -84,7 +84,7 @@ const TestModal = (props: {
modalProps={{ onCancel: onCancel, destroyOnClose: true }}
labelAlign={'left'}
labelCol={{ span: 4 }}
wrapperCol={{ span: 19 }}
wrapperCol={{ span: 20 }}
key={data.type}
title={intl.formatMessage({ id: 'pages.setting.message.sms_provider.send_scene.modal.from' })}
initialValues={{ type: data.type, name: data.name, content: data.content }}
@ -376,14 +376,14 @@ export default (props: { visible: boolean }) => {
}
}}
>
<ProFormSelect
<ProFormSegmented
name="provider"
label={intl.formatMessage({ id: 'pages.setting.message.sms_provider.provider' })}
rules={[{ required: true }]}
fieldProps={{
onChange: async (value: string) => {
onChange: async (value) => {
setLoading(true);
setProvider(value);
setProvider(value as string);
//清理
form.resetFields();
form.setFieldsValue({ provider: value });
@ -394,7 +394,7 @@ export default (props: { visible: boolean }) => {
form.setFieldsValue({ ...result.config });
setLanguage(result.language);
//获取模板
await fetchSmsTemplateList(result.language, value);
await fetchSmsTemplateList(result.language, value as string);
result.templates?.forEach((i: { type: any; code: any }) => {
editorFormRef.current?.setFieldsValue({ [i.type]: { code: i.code } });
});
@ -402,31 +402,33 @@ export default (props: { visible: boolean }) => {
//已配置和选中配置不一致,走初始化流程
if (success && result && result.provider !== value) {
setLanguage(Language.ZH);
await fetchSmsTemplateList(Language.ZH, value);
await fetchSmsTemplateList(Language.ZH, value as string);
}
setLoading(false);
},
}}
options={[
{
value: SMS_PROVIDER.ALIYUN,
label: intl.formatMessage({
id: 'pages.setting.message.sms_provider.provider.aliyun',
}),
},
{
value: SMS_PROVIDER.TENCENT,
label: intl.formatMessage({
id: 'pages.setting.message.sms_provider.provider.tencent',
}),
},
{
value: SMS_PROVIDER.QI_NIU,
label: intl.formatMessage({
id: 'pages.setting.message.sms_provider.provider.qi_niu',
}),
},
]}
request={async () => {
return [
{
value: SMS_PROVIDER.ALIYUN,
label: intl.formatMessage({
id: 'pages.setting.message.sms_provider.provider.aliyun',
}),
},
{
value: SMS_PROVIDER.TENCENT,
label: intl.formatMessage({
id: 'pages.setting.message.sms_provider.provider.tencent',
}),
},
{
value: SMS_PROVIDER.QI_NIU,
label: intl.formatMessage({
id: 'pages.setting.message.sms_provider.provider.qi_niu',
}),
},
];
}}
/>
{provider === SMS_PROVIDER.ALIYUN && <AliCloud />}
{provider === SMS_PROVIDER.TENCENT && <Tencent />}

@ -78,6 +78,23 @@ export default {
'请输入阿里云短信签名',
'pages.setting.message.sms_provider.provider.aliyun.sign_name.rule.0.message':
'阿里云短信签名为必填项',
'pages.setting.storage_provider.provider.s3': 'S3',
'pages.setting.storage_provider.provider.s3.endpoint': 'S3域名',
'pages.setting.storage_provider.provider.s3.endpoint.placeholder': '请输入 S3域名',
'pages.setting.storage_provider.provider.s3.endpoint.rule.0.message': 'S3域名为必填项',
'pages.setting.storage_provider.provider.s3.domain': '外链域名',
'pages.setting.storage_provider.provider.s3.domain.placeholder': '请输入S3 外链域名',
'pages.setting.storage_provider.provider.s3.domain.rule.0.message': 'S3 外链域名为必填项',
'pages.setting.storage_provider.provider.s3.access_key_id.placeholder': '请输入S3 AccessKeyId',
'pages.setting.storage_provider.provider.s3.access_key_id.rule.0.message':
'S3 AccessKeyId为必填项',
'pages.setting.storage_provider.provider.s3.secret_access_key.placeholder':
'请输入S3 SecretAccessKey',
'pages.setting.storage_provider.provider.s3.secret_access_key.rule.0.message':
'S3 SecretAccessKey为必填项',
'pages.setting.storage_provider.provider.s3.region.placeholder': '请输入S3 Region',
'pages.setting.storage_provider.provider.s3.bucket.placeholder': '请输入S3 Bucket',
'pages.setting.storage_provider.provider.s3.bucket.rule.0.message': 'S3 Bucket为必填项',
'pages.setting.message.sms_provider.provider.tencent': '腾讯云',
'pages.setting.message.sms_provider.provider.tencent.region': '地域',
'pages.setting.message.sms_provider.provider.tencent.region.placeholder': '请选择地域配置',

Loading…
Cancel
Save