Yansen 2 anni fa
parent
commit
7c8ba53e35
2 ha cambiato i file con 48 aggiunte e 40 eliminazioni
  1. 45
    39
      src/layouts/AuthLayout/components/Header/User.jsx
  2. 3
    1
      vite.config.js

+ 45
- 39
src/layouts/AuthLayout/components/Header/User.jsx Vedi File

@@ -1,6 +1,8 @@
1 1
 import React, { useState, forwardRef, useRef, useImperativeHandle } from 'react';
2
-import { Avatar, Button, Dropdown, Menu, Form, Input, Modal } from 'antd';
2
+import { Avatar, Dropdown } from 'antd';
3
+import { ModalForm, ProFormText, ProFormDependency } from '@ant-design/pro-components';
3 4
 import md5 from 'md5';
5
+import { changePassword } from '@/service/login';
4 6
 
5 7
 const DefaultAvatar = ({ color = '#1296db' }) => (
6 8
   <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
@@ -14,8 +16,15 @@ const DefaultAvatar = ({ color = '#1296db' }) => (
14 16
 const ChangePassword = forwardRef((props, ref) => {
15 17
   const [visible, setVisible] = useState(false);
16 18
 
17
-  const onFinish = (values) => {
18
-    console.log('Success:', values);
19
+  const onFinish = async (values) => {
20
+    const data = {
21
+      originPassword: md5(values.password),
22
+      newPassword: md5(values.newPassword),
23
+    }
24
+
25
+    await changePassword(data);
26
+
27
+    return true;
19 28
   };
20 29
 
21 30
   useImperativeHandle(ref, () => {
@@ -25,44 +34,41 @@ const ChangePassword = forwardRef((props, ref) => {
25 34
   });
26 35
 
27 36
   return (
28
-    <Modal title="修改密码" open={visible} onCancel={() => setVisible(false)}>
29
-      <Form
30
-        labelCol={{ span: 8 }}
31
-        wrapperCol={{ span: 16 }}
32
-        onFinish={onFinish}
33
-        autoComplete="off"
34
-      >
35
-        <Form.Item
36
-          label="原始密码"
37
-          name="password"
38
-          rules={[{ required: true, message: '请输入原始密码!' }]}
39
-        >
40
-          <Input.Password />
41
-        </Form.Item>
42
-
43
-        <Form.Item
44
-          label="新密码"
45
-          name="newPassword"
46
-          rules={[{ required: true, message: '请输入新密码!' }]}
47
-        >
48
-          <Input.Password />
49
-        </Form.Item>
37
+    <ModalForm title="修改密码" width="480px" open={visible} onOpenChange={setVisible} onFinish={onFinish}>
38
+      <ProFormText.Password
39
+        label="原始密码"
40
+        name="password"
41
+        rules={[{ required: true, message: '请输入原始密码!' }]}
42
+      />
43
+      <ProFormText.Password
44
+        label="新密码"
45
+        name="newPassword"
46
+        rules={[{ required: true, message: '请输入新密码!' }]}
47
+      />
50 48
 
51
-        <Form.Item
52
-          label="确认新密码"
53
-          name="newPassword2"
54
-          rules={[{ required: true, message: '请输入新密码!' }]}
55
-        >
56
-          <Input.Password />
57
-        </Form.Item>
49
+      <ProFormDependency name={['newPassword']}>
50
+      {
51
+        ({newPassword}) => (
52
+          <ProFormText.Password
53
+            label="确认新密码"
54
+            name="newPassword2"
55
+            rules={[
56
+              { required: true, message: '请输入新密码!' },
57
+              () => ({
58
+                validator(_, value) {
59
+                  if (!value || value == newPassword) {
60
+                    return Promise.resolve();
61
+                  }
58 62
 
59
-        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
60
-          <Button type="primary" htmlType="submit">
61
-            提交
62
-          </Button>
63
-        </Form.Item>
64
-      </Form>
65
-    </Modal>
63
+                  return Promise.reject('两次输入密码不一致');
64
+                }
65
+              })
66
+            ]}
67
+          />
68
+        )
69
+      }
70
+      </ProFormDependency>
71
+    </ModalForm>
66 72
   )
67 73
 });
68 74
 

+ 3
- 1
vite.config.js Vedi File

@@ -6,9 +6,11 @@ import react from '@vitejs/plugin-react'
6 6
 export default defineConfig({
7 7
   server: {
8 8
     port: 3001,
9
+    host: '0.0.0.0',
9 10
     proxy: {
10 11
       '/api': {
11
-        target: 'http://t.njyz.tech',
12
+        target: 'http://127.0.0.1:9087',
13
+        // target: 'http://t.njyz.tech',
12 14
         changeOrigin: true,
13 15
       },
14 16
     }