diff --git a/back/api/auth.ts b/back/api/auth.ts index 21bf5484..ef5bb9c7 100644 --- a/back/api/auth.ts +++ b/back/api/auth.ts @@ -204,8 +204,8 @@ export default (app: Router) => { const logger: Logger = Container.get('logger'); try { const authService = Container.get(AuthService); - const data = await authService.updateNotificationMode(req.body); - res.send({ code: 200, data }); + const result = await authService.updateNotificationMode(req.body); + res.send(result); } catch (e) { logger.error('🔥 error: %o', e); return next(e); diff --git a/back/services/auth.ts b/back/services/auth.ts index 5fc04897..1b7f4012 100644 --- a/back/services/auth.ts +++ b/back/services/auth.ts @@ -272,7 +272,7 @@ export default class AuthService { return new Promise((resolve) => { this.authDb.update( { type: AuthDataType.notification }, - payload, + { ...payload }, { upsert: true, returnUpdatedDocs: true }, (err, num, doc: any) => { if (err) { diff --git a/back/services/notify.ts b/back/services/notify.ts index 9acd4d4a..398189f1 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -60,6 +60,7 @@ export default class NotificationService { const notificationModeAction = this.modeMap.get(type); return await notificationModeAction?.call(this); } + return true; } private async goCqHttpBot() { diff --git a/src/pages/setting/notification.tsx b/src/pages/setting/notification.tsx index d62dfbb1..289b804d 100644 --- a/src/pages/setting/notification.tsx +++ b/src/pages/setting/notification.tsx @@ -7,22 +7,25 @@ const { Option } = Select; const NotificationSetting = ({ data }: any) => { const [loading, setLoading] = useState(false); - const [notificationMode, setNotificationMode] = useState(''); + const [notificationMode, setNotificationMode] = useState('closed'); const [fields, setFields] = useState([]); const [form] = Form.useForm(); const handleOk = (values: any) => { + if (values.type == 'closed') { + values.type = ''; + } request .put(`${config.apiPrefix}user/notification`, { data: { ...values, }, }) - .then((data: any) => { - if (data && data.code === 200) { - message.success('通知发送成功'); + .then((_data: any) => { + if (_data && _data.code === 200) { + message.success(values.type ? '通知发送成功' : '通知关闭成功'); } else { - message.error(data.data); + message.error(_data.data); } }) .catch((error: any) => { @@ -33,7 +36,7 @@ const NotificationSetting = ({ data }: any) => { const notificationModeChange = (value: string) => { setNotificationMode(value); const _fields = (config.notificationModeMap as any)[value]; - setFields(_fields); + setFields(_fields || []); }; useEffect(() => { @@ -70,11 +73,9 @@ const NotificationSetting = ({ data }: any) => { ))} - {notificationMode !== '' && ( - - )} + ); diff --git a/src/utils/config.ts b/src/utils/config.ts index 085866d0..7060ae79 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -74,7 +74,7 @@ export default { { value: 'iGot', label: 'IGot' }, { value: 'pushPlus', label: 'PushPlus' }, { value: 'email', label: '邮箱' }, - { value: '', label: '已关闭' }, + { value: 'closed', label: '已关闭' }, ], notificationModeMap: { goCqHttpBot: [