From 7b389c589fceaaeeef1980eee0289e88a5600c6f Mon Sep 17 00:00:00 2001 From: Tuisku Date: Fri, 27 May 2022 14:30:12 +0800 Subject: [PATCH] =?UTF-8?q?token=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/user/user.js | 4 ---- utils/util.js | 48 +++++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pages/user/user.js b/pages/user/user.js index a5ecfe4..f5476a3 100644 --- a/pages/user/user.js +++ b/pages/user/user.js @@ -63,7 +63,6 @@ Page({ http("/user/login", "post", { code: res.code }).then(res => { - console.log(res) if (res.msg === "未注册!") { this.getUserProfile() } else { @@ -84,7 +83,6 @@ Page({ wx.getStorage({ key: 'token', success (res) { - console.log(res.data) } }) } @@ -104,7 +102,6 @@ Page({ wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (userRes) => { - console.log(userRes) that.setData({ iv: userRes.iv, encryptedData: userRes.encryptedData, @@ -123,7 +120,6 @@ Page({ phone: false }) let that = this - console.log(that.data.iv) let param = { userinfo: { iv: this.data.iv, diff --git a/utils/util.js b/utils/util.js index 2795518..658c946 100644 --- a/utils/util.js +++ b/utils/util.js @@ -25,22 +25,33 @@ const http = (url, method, data, isLoading = true) => { }); } return new Promise(function (resolve, reject) { - let token = getApp().globalData.token - // wx.getStorage({ - // key: 'token', - // success (res) { - // // console.log(res.data) - // let token = res.data - // }, - // fail (res) { - // console.log(res) - // wx.hideLoading(); - // } - // }) - let header = { - 'token': token + if ( url === '/user/login' || url === '/user/register') { + var header = {} + } else { + wx.getStorage({ + key: 'token', + success (res) { + // console.log(res.data) + let token = res.data + }, + fail(res) { + if (res.errMsg === "getStorage:fail data not found"){ + wx.showToast({ + title: '未登录\r\n点击个人中心头像登录', + icon: 'none', + duration: 2000 + }) + } + wx.hideLoading(); + }, + complete (res) { + console.log(res) + } + }) + var header = { + 'token': token + } } - if (token) { wx.request({ url: host + url, data: data, @@ -66,13 +77,6 @@ const http = (url, method, data, isLoading = true) => { wx.hideLoading(); } }) - } else { - wx.showToast({ - title: '未登录\r\n点击个人中心头像登录', - icon: 'none', - duration: 2000 - }) - } }) }