Browse Source

个人信息修改

sunshine1130 4 years ago
parent
commit
2f2463675e
2 changed files with 11 additions and 12 deletions
  1. 1 0
      api/user.js
  2. 10 12
      pages/personinfo/personinfo.js

+ 1 - 0
api/user.js

@@ -18,6 +18,7 @@ class store extends request{
 
     static async updateUserInfo(name,birthday,avatar,sex){
         const res = await this.postRequest(`${this.BASE_URL}User/editUser?name=${name}&birthday=${birthday}&avatar=${avatar}&sex=${sex}`)
+        return res.data
     }
     static async getUserById(userId){
         const res = await this.getRequest(`${this.BASE_URL}User/read?id=${userId}`)

+ 10 - 12
pages/personinfo/personinfo.js

@@ -46,7 +46,7 @@ Page({
     birth = birth == "" ? '1970-01-01' : birth;
     console.log(user)
     this.setData({
-      sex: userInfo.gender,
+      sex: userInfo.sex,
       imgUrl: user.info.avatar,
       userName: user.info.name,
       birth: birth
@@ -92,27 +92,25 @@ Page({
     var birthDay = this.data.birth;
     var avatar = this.data.imgUrl;
     var sex = this.data.sex;
-    
-    await userApi.updateUserInfo(name, birthDay, avatar, sex);
+
+    let userinfo = await userApi.updateUserInfo(name, birthDay, avatar, sex);
     var userInfo = await app.getWxUserInfo();
-    userInfo.name = name;
-    userInfo.birthday = birthDay;
-    userInfo.avatar = avatar;
-    userInfo.sex = sex;
-    wx.setStorage({
-      data: userInfo,
-      key: 'userInfo',
-    })
+
     wx.showToast({
       title: '修改成功',
       icon: 'success',
       success: function () {
+        userInfo.name = userinfo.info.name;
+        userInfo.birthday = userinfo.info.birthDay;
+        userInfo.avatar = userinfo.info.avatar;
+        userInfo.sex = userinfo.info.sex;
+        app.setUserInfo(userInfo)
         setTimeout(() => {
           wx.switchTab({
             url: '/pages/person/person',
           })
         }, 1000);
-        
+
       }
     })