jinx 3 vuotta sitten
vanhempi
commit
3c31688f82
4 muutettua tiedostoa jossa 45 lisäystä ja 32 poistoa
  1. 6 6
      config.js
  2. 24 19
      pages/user/user.js
  3. 1 1
      pages/user/user.wxml
  4. 14 6
      utils/util.js

+ 6 - 6
config.js

@@ -17,12 +17,12 @@ const mal = {
   // socketHost: 'wss://shop.4dkankan.com',
   socketHost: 'wss://rtc-zfb.4dkankan.com/',
   // socketHost: 'wss://192.168.0.79:3031',
-  // requestHost: 'https://plaza-cszfb.4dkankan.com', // 测试环境
-  // viewChildHost: 'https://cszfb.4dkankan.com', //测试环境
-  // viewHost: 'https://cszfb.4dkankan.com'//测试环境
-  requestHost: 'https://plaza.4dkankan.com',
-  viewChildHost: 'https://zfb.4dkankan.com',
-  viewHost: 'https://zfb.4dkankan.com'
+  requestHost: 'https://plaza-cszfb.4dkankan.com', // 测试环境
+  viewChildHost: 'https://cszfb.4dkankan.com', //测试环境
+  viewHost: 'https://cszfb.4dkankan.com'//测试环境
+  // requestHost: 'https://plaza.4dkankan.com',
+  // viewChildHost: 'https://zfb.4dkankan.com',
+  // viewHost: 'https://zfb.4dkankan.com'
 }
 
 

+ 24 - 19
pages/user/user.js

@@ -26,15 +26,20 @@ Page({
    */
   onLoad: function (options) {
     this.getUserInfo()
+
     let userInfo = wx.getStorageSync('userInfo')
-    userInfo.avatar = userInfo.avatarUrl
-    this.sessionKey = userInfo.sessionKey
-    delete userInfo.avatarUrl
-    delete userInfo.sessionKey
+    try {
+      userInfo.avatar = userInfo.avatarUrl
+      this.sessionKey = userInfo.sessionKey
+      delete userInfo.avatarUrl
+      delete userInfo.sessionKey
+      this.setData({
+        ...userInfo
+      })
+    } catch (err) {
+
+    }
 
-    this.setData({
-      ...userInfo
-    })
   },
 
 
@@ -90,18 +95,18 @@ Page({
   },
 
   selectPhoto() {
-    wx.chooseImage({
-      count: 1,
-      sizeType: 'compressed',
-      success: (res) => {
-        const src = res.tempFilePaths[0]
-        // this.file = res.tempFiles[0]
-        wx.navigateTo({
-          url: './imageCropper?image=' + src,
-        })
-        // this.setData({ avatar: src })
-      }
-    })
+    // wx.chooseImage({
+    //   count: 1,
+    //   sizeType: 'compressed',
+    //   success: (res) => {
+    //     const src = res.tempFilePaths[0]
+    //     // this.file = res.tempFiles[0]
+    //     wx.navigateTo({
+    //       url: './imageCropper?image=' + src,
+    //     })
+    //     // this.setData({ avatar: src })
+    //   }
+    // })
   },
   changPhone(e) {
     this.setData({

+ 1 - 1
pages/user/user.wxml

@@ -3,7 +3,7 @@
   <view class="photo">
     <view class="userinfo-avatar" bindtap="selectPhoto" style="background-image: url({{avatar}})">
     </view>
-    <text class="userinfo-nickname">点击修改头像</text>
+    <!-- <text class="userinfo-nickname">点击修改头像</text> -->
     <!-- {{userInfo.nickName}} -->
   </view>
 

+ 14 - 6
utils/util.js

@@ -56,14 +56,21 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
             },
             success: function (res) {
                 // wx.hideLoading();
-           
+
 
                 if (!Object.prototype.hasOwnProperty.call(res.data, 'data')) {
                     res.data.data = res.data.message;
+
+                    for (let key in res.data.message) {
+                        //为了兼容旧接口数据
+                        if (key != 'data') {
+                            res.data[key] = res.data.message[key]
+                        }
+                    }
                 }
 
-                if (!Object.prototype.hasOwnProperty.call(res.data, 'errno')) {        
-                    if(Object.prototype.hasOwnProperty.call(res.data, 'code')){
+                if (!Object.prototype.hasOwnProperty.call(res.data, 'errno')) {
+                    if (Object.prototype.hasOwnProperty.call(res.data, 'code')) {
                         res.data.errno = (res.data.code === 200 || res.data.code === 0) ? 0 : res.data.code;
                     }
                 }
@@ -73,10 +80,10 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
                     let pages = getCurrentPages()
                     let currPage = pages[pages.length - 1].route
                     let notLogins = ['pages/index/index', 'pages/catalog/catalog', 'pages/category/category', 'pages/ucenter/index/index']
-                    console.log('test',res.data.code == 401 && !~notLogins.indexOf(currPage))
-
+                    console.log('test', res.data.code == 401 && !~notLogins.indexOf(currPage))
+                    console.log(res)
                     if (res.data.code == 401 && !~notLogins.indexOf(currPage)) {
-                        
+
                         resolve(res.data);
                         gotoLogin()
                     } else {
@@ -90,6 +97,7 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
                                 }
                             }
                         }
+                        console.error(res.data)
                         jx(res.data)
                         resolve(res.data);
                     }