diff --git a/pages/user/index.js b/pages/user/index.js index 3d0cd0b..fc47da9 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -13,10 +13,10 @@ Page({ /** * 页面的初始数据 */ - data: { + data: { messageTotal: Number, canIUse: wx.canIUse('button.open-type.getUserInfo'), - authType:0 + authType: 0 }, /** @@ -26,19 +26,19 @@ Page({ this.getUserInfo() this.isAuthUserInfo() }, - isAuthUserInfo(){ + isAuthUserInfo () { let that = this wx.showLoading() console.log('未授权') - return new Promise(resolve =>{ - + return new Promise(resolve => { + that.setData({ authType: 1 }, () => { wx.hideLoading() }) wx.getSetting({ - success(res) { + success (res) { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ @@ -48,10 +48,10 @@ Page({ let nickName = res.userInfo.nickName let avatarUrl = res.userInfo.avatarUrl console.log(nickName, avatarUrl) - if(nickName && avatarUrl){ + if (nickName && avatarUrl) { that.setData({ authType: 2 - },()=>{ + }, () => { wx.hideLoading() }) } @@ -62,9 +62,9 @@ Page({ }) }) }, - bindGetUserInfo(e) { + bindGetUserInfo (e) { console.log(e.detail.userInfo) - + let avatarUrl = e.detail.userInfo.avatarUrl let city = e.detail.userInfo.city let country = e.detail.userInfo.country @@ -74,22 +74,22 @@ Page({ this.updateUserInfo(avatarUrl, city, country, gender, nickName, province) this.isAuthUserInfo() }, - hasBindUserInfo(){ + hasBindUserInfo () { return store.hasBindUserInfo(); }, - updateUserInfo(avatarUrl, city, country, gender, nickName, province){ - userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province,res=>{ + updateUserInfo (avatarUrl, city, country, gender, nickName, province) { + userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province, res => { console.log(res) }) }, - getUserInfo(){ - userModel.getUserInfo(res=>{ + getUserInfo () { + userModel.getUserInfo(res => { console.log(res) }) }, - getMsgStatus(){ - userModel.getMyMessageTotal(res=>{ + getMsgStatus () { + userModel.getMyMessageTotal(res => { console.log(res.result.total) this.setData({ messageTotal: Number(res.result.total) @@ -97,7 +97,7 @@ Page({ }) }, onTapItem (e) { - const {type} = e.currentTarget.dataset + const { type } = e.currentTarget.dataset console.log(type) wx.navigateTo({ url: `/pages/user/${type}/index`, @@ -108,52 +108,4 @@ Page({ // }) // } }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { - - } }) \ No newline at end of file diff --git a/utils/http.js b/utils/http.js index bc23d7f..c52761d 100644 --- a/utils/http.js +++ b/utils/http.js @@ -1,5 +1,5 @@ import { config } from '../config.js' -import {store} from './store.js' +import { store } from './store.js' const Method = { GET: 'GET', @@ -48,14 +48,14 @@ class HTTP { // token 无效 this.fetchAuthToken(res => { // 请求Token后,重新请求URL - if(res.code == 200) { + if (res.code == 200) { this.request(params) } }) } else { console.log('数据请求失败') wx.showToast({ - title: res.data.message, + title: res.data.message || '服务器错误,请稍后重试', icon: 'none' }) } @@ -70,7 +70,7 @@ class HTTP { }, fail: function (res) { wx.showToast({ - title: '网络连接错误,请求失败!', + title: '网络连接错误,请求稍后重试!', icon: 'none' }) params.fail && params.fail(res) @@ -78,7 +78,7 @@ class HTTP { }) } // 获取 Token - fetchAuthToken(success) { + fetchAuthToken (success) { // 获取token this._fetchWXCode().then(res => { console.log('啦啦啦啦凉啊') @@ -102,10 +102,10 @@ class HTTP { }) } // 获取微信code - _fetchWXCode() { + _fetchWXCode () { return new Promise(resolve => { wx.login({ - success(res) { + success (res) { console.log('获取Code成功 ' + res.code) resolve(res.code) }