张延森 преди 4 години
родител
ревизия
1f34fa234b
променени са 4 файла, в които са добавени 28 реда и са изтрити 10 реда
  1. 15
    5
      src/components/MainPage/index.vue
  2. 5
    0
      src/store/user/index.js
  3. 1
    1
      src/util/Api/index.js
  4. 7
    4
      src/util/PublicMethod/index.js

+ 15
- 5
src/components/MainPage/index.vue Целия файл

@@ -76,10 +76,12 @@ export default {
76 76
     ...mapUserActions([
77 77
       'WxGetPhoneAuth',
78 78
       'WxLogin',
79
-      'PutUserInfo'
79
+      'PutUserInfo',
80
+      'WxAuthUserInfo',
80 81
     ]),
81 82
     ...mapUserMutations([
82
-      'EditUserInfo'
83
+      'EditUserInfo',
84
+      'UpdateUserInfo',
83 85
     ]),
84 86
     toIndexPage () {
85 87
       Taro.reLaunch({
@@ -126,9 +128,17 @@ export default {
126 128
       }
127 129
     },
128 130
     GetUserIcon (e) {
129
-      if (e.detail.userInfo.avatarUrl) {
130
-        this.PutUserInfo({ data: { data: { avatar: e.detail.userInfo.avatarUrl, personId: this.UserInfo.personId } } }).then(() => {
131
-          this.EditUserInfo({ name: 'avatar', value: e.detail.userInfo.avatarUrl })
131
+      if (e.detail.errMsg === 'getUserInfo:ok') {
132
+        const data = {
133
+          signature: e.detail.signature,
134
+          rawData: e.detail.rawData,
135
+          encryptedData: e.detail.encryptedData,
136
+          iv: e.detail.iv,
137
+          sessionKey: this.UserInfo.sessionKey,
138
+        }
139
+
140
+        this.WxAuthUserInfo({ data: { data }}).then(res => {
141
+          this.UpdateUserInfo(res.data.data)
132 142
           this.ShowUserIconAuthPopup = false
133 143
           if (!this.UserInfo.phone) {
134 144
             this.ShowPhoneAuthPopup = true

+ 5
- 0
src/store/user/index.js Целия файл

@@ -24,6 +24,11 @@ export default {
24 24
         ToolClass.ToolRequest({ url: Api.WxGetPhoneAuth.url, method: Api.WxGetPhoneAuth.method, ...payload, success (res) { resolve(res) }, error (res) { reject(res) } })
25 25
       })
26 26
     },
27
+    WxAuthUserInfo (context, payload) { // 授权头像,昵称
28
+      return new Promise((resolve, reject) => {
29
+        ToolClass.ToolRequest({ url: Api.WxGetUserIconAuth.url, method: Api.WxGetUserIconAuth.method, ...payload, success (res) { resolve(res) }, error (res) { reject(res) } })
30
+      })
31
+    },
27 32
     WxLogin (context, payload) { // 微信登录
28 33
       return new Promise((resolve, reject) => {
29 34
         ToolClass.ToolRequest({ url: Api.WxLogin.url, method: Api.WxLogin.method, ...payload, success (res) { context.commit('UpdateUserInfo', { ...res.data.data.person, sessionKey: res.data.data.sessionKey }); resolve(res) }, error (res) { reject(res) } })

+ 1
- 1
src/util/Api/index.js Целия файл

@@ -7,7 +7,7 @@ const Api = {
7 7
     url: `${prefix}/ma/auth-phone`
8 8
   },
9 9
   WxGetUserIconAuth: { // 微信获取用户头像
10
-    method: 'post',
10
+    method: 'put',
11 11
     url: `${prefix}/ma/auth-user`
12 12
   },
13 13
   WxLogin: { // 微信登录

+ 7
- 4
src/util/PublicMethod/index.js Целия файл

@@ -50,7 +50,7 @@ const ToolClass = {
50 50
     if (queryData) {
51 51
       config.url += '?' + queryData
52 52
     }
53
-    let Header = {}
53
+    let Header = { 'Access-Control-Expose-Headers': 'X-Authorization-JWT' }
54 54
     if (wx.getStorageSync('token') !== '' && wx.getStorageSync('tokentime') !== '' && wx.getStorageSync('tokentime') - 0 + 24 * 60 * 60 * 1000 >= Date.now()) { // 本地获取token
55 55
       Header['X-Authorization-JWT'] = wx.getStorageSync('token')
56 56
     }
@@ -60,7 +60,7 @@ const ToolClass = {
60 60
       ...(config.data || {}),
61 61
       header: { ...Header },
62 62
       success: (res) => {
63
-        const token = res.header['X-Authorization-JWT'] || res.header['X-Authorization-Jwt']
63
+        const token = res.data?.token
64 64
         if (token) { // 更新本地存储token
65 65
           wx.setStorageSync('token', token)
66 66
           wx.setStorageSync('tokentime', Date.now())
@@ -95,9 +95,12 @@ const ToolClass = {
95 95
         }
96 96
       },
97 97
       fail: (res) => {
98
-        if (res.header['X-Authorization-JWT'] !== undefined) { // 更新本地存储token
99
-          wx.setStorageSync('token', res.header['X-Authorization-JWT'])
98
+        const token = res.data?.token
99
+        if (token) { // 更新本地存储token
100
+          wx.setStorageSync('token', token)
101
+          wx.setStorageSync('tokentime', Date.now())
100 102
         }
103
+
101 104
         if (res.data.code - 0 === 1001) { // token失效
102 105
           // wx.navigateTo({ url: '../../pages/SignIn/index' })
103 106
           config.error('登录失效')