Просмотр исходного кода

添加更新消息提醒设置。

tianyunperfect 4 лет назад
Родитель
Сommit
3fe1246546
2 измененных файлов с 54 добавлено и 2 удалено
  1. 52 2
      src/pages/Setting/index.tsx
  2. 2 0
      src/pages/Setting/service.ts

+ 52 - 2
src/pages/Setting/index.tsx

@@ -1,5 +1,5 @@
 import {Button, Card, Form, Input, message} from 'antd';
-import React, {useState} from 'react';
+import React, {useEffect, useState} from 'react';
 import {PageHeaderWrapper} from '@ant-design/pro-layout';
 import service from './service';
 
@@ -8,6 +8,11 @@ interface PasswordChange {
   oldPassword: string;
 }
 
+interface PushChange {
+  userId: number;
+  noteUrl: string;
+}
+
 enum InputState {
   default = '',
   success = 'success',
@@ -47,6 +52,7 @@ const TableList: React.FC<{}> = () => {
   const [success, setSuccess] = useState<InputState>(InputState.default);
 
   const [form2] = Form.useForm();
+  const [noteForm] = Form.useForm();
 
   const nameExist = async () => {
     const userName = form2.getFieldValue("userName");
@@ -72,6 +78,17 @@ const TableList: React.FC<{}> = () => {
   const onFinish = (values: any) => {
     handleUpdate(values);
   };
+
+  const updatePushUrl = (values: PushChange) => {
+    values["noteUrl"] = encodeURI(values["noteUrl"]);
+    service.updatePushUrl(values).then(res => {
+      if (res.success) {
+        message.success("更新成功");
+      } else {
+        message.error('获取url失败!');
+      }
+    });
+  };
   /**
    * 用户名更新
    * @param value
@@ -86,6 +103,16 @@ const TableList: React.FC<{}> = () => {
     }
   }
 
+  useEffect(() => {
+    service.queryPushUrl({}).then(res => {
+      if (res.success) {
+        noteForm.setFieldsValue({"noteUrl": decodeURI(res.data)});
+      } else {
+        message.error('获取url失败!');
+      }
+    })
+  }, [])
+
   // const onFinishFailed = errorInfo => {
   //   console.log('Failed:', errorInfo);
   // };
@@ -155,13 +182,36 @@ const TableList: React.FC<{}> = () => {
           </Form.Item>
         </Form>
       </Card>
+      <Card title="消息提醒地址" style={{width: '100%'}}>
+        <Form
+          {...layout}
+          name="basic"
+          initialValues={{}}
+          onFinish={updatePushUrl}
+          form={noteForm}
+          // onFinishFailed={onFinishFailed}
+        >
+          <Form.Item
+            label="提醒地址"
+            name="noteUrl"
+          >
+            <Input/>
+          </Form.Item>
+
+          <Form.Item {...tailLayout}>
+            <Button type="primary" htmlType="submit">
+              提交
+            </Button>
+          </Form.Item>
+        </Form>
+      </Card>
       <Card title="刷新页面" style={{width: '100%'}}>
         <Form
           {...layout}
           name="basic"
         >
           <Form.Item {...tailLayout}>
-            <Button type="primary" htmlType="button" onClick={()=>{
+            <Button type="primary" htmlType="button" onClick={() => {
               window.location.reload();
             }}>
               刷新页面

+ 2 - 0
src/pages/Setting/service.ts

@@ -6,4 +6,6 @@ export default {
   updatePassword: api.get('/api/user/resetPassword'),
   nameExist: api.get('/api/user/nameExist'),
   updateAccountName: api.get('/api/user/updateAccountName'),
+  queryPushUrl: api.post('/api/push/getPushUrl'),
+  updatePushUrl: api.post('/api/push/updatePushUrl'),
 };