Browse Source

删除user/index.js无用声明周期;修改请求库中,错误提醒。

master
lqq 6 years ago
parent
commit
3722408864
  1. 78
      pages/user/index.js
  2. 14
      utils/http.js

78
pages/user/index.js

@ -16,7 +16,7 @@ Page({
data: { data: {
messageTotal: Number, messageTotal: Number,
canIUse: wx.canIUse('button.open-type.getUserInfo'), canIUse: wx.canIUse('button.open-type.getUserInfo'),
authType:0 authType: 0
}, },
/** /**
@ -26,11 +26,11 @@ Page({
this.getUserInfo() this.getUserInfo()
this.isAuthUserInfo() this.isAuthUserInfo()
}, },
isAuthUserInfo(){ isAuthUserInfo () {
let that = this let that = this
wx.showLoading() wx.showLoading()
console.log('未授权') console.log('未授权')
return new Promise(resolve =>{ return new Promise(resolve => {
that.setData({ that.setData({
authType: 1 authType: 1
@ -38,7 +38,7 @@ Page({
wx.hideLoading() wx.hideLoading()
}) })
wx.getSetting({ wx.getSetting({
success(res) { success (res) {
if (res.authSetting['scope.userInfo']) { if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称 // 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({ wx.getUserInfo({
@ -48,10 +48,10 @@ Page({
let nickName = res.userInfo.nickName let nickName = res.userInfo.nickName
let avatarUrl = res.userInfo.avatarUrl let avatarUrl = res.userInfo.avatarUrl
console.log(nickName, avatarUrl) console.log(nickName, avatarUrl)
if(nickName && avatarUrl){ if (nickName && avatarUrl) {
that.setData({ that.setData({
authType: 2 authType: 2
},()=>{ }, () => {
wx.hideLoading() wx.hideLoading()
}) })
} }
@ -62,7 +62,7 @@ Page({
}) })
}) })
}, },
bindGetUserInfo(e) { bindGetUserInfo (e) {
console.log(e.detail.userInfo) console.log(e.detail.userInfo)
let avatarUrl = e.detail.userInfo.avatarUrl let avatarUrl = e.detail.userInfo.avatarUrl
@ -74,22 +74,22 @@ Page({
this.updateUserInfo(avatarUrl, city, country, gender, nickName, province) this.updateUserInfo(avatarUrl, city, country, gender, nickName, province)
this.isAuthUserInfo() this.isAuthUserInfo()
}, },
hasBindUserInfo(){ hasBindUserInfo () {
return store.hasBindUserInfo(); return store.hasBindUserInfo();
}, },
updateUserInfo(avatarUrl, city, country, gender, nickName, province){ updateUserInfo (avatarUrl, city, country, gender, nickName, province) {
userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province,res=>{ userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province, res => {
console.log(res) console.log(res)
}) })
}, },
getUserInfo(){ getUserInfo () {
userModel.getUserInfo(res=>{ userModel.getUserInfo(res => {
console.log(res) console.log(res)
}) })
}, },
getMsgStatus(){ getMsgStatus () {
userModel.getMyMessageTotal(res=>{ userModel.getMyMessageTotal(res => {
console.log(res.result.total) console.log(res.result.total)
this.setData({ this.setData({
messageTotal: Number(res.result.total) messageTotal: Number(res.result.total)
@ -97,7 +97,7 @@ Page({
}) })
}, },
onTapItem (e) { onTapItem (e) {
const {type} = e.currentTarget.dataset const { type } = e.currentTarget.dataset
console.log(type) console.log(type)
wx.navigateTo({ wx.navigateTo({
url: `/pages/user/${type}/index`, url: `/pages/user/${type}/index`,
@ -108,52 +108,4 @@ Page({
// }) // })
// } // }
}, },
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
}) })

14
utils/http.js

@ -1,5 +1,5 @@
import { config } from '../config.js' import { config } from '../config.js'
import {store} from './store.js' import { store } from './store.js'
const Method = { const Method = {
GET: 'GET', GET: 'GET',
@ -48,14 +48,14 @@ class HTTP {
// token 无效 // token 无效
this.fetchAuthToken(res => { this.fetchAuthToken(res => {
// 请求Token后,重新请求URL // 请求Token后,重新请求URL
if(res.code == 200) { if (res.code == 200) {
this.request(params) this.request(params)
} }
}) })
} else { } else {
console.log('数据请求失败') console.log('数据请求失败')
wx.showToast({ wx.showToast({
title: res.data.message, title: res.data.message || '服务器错误,请稍后重试',
icon: 'none' icon: 'none'
}) })
} }
@ -70,7 +70,7 @@ class HTTP {
}, },
fail: function (res) { fail: function (res) {
wx.showToast({ wx.showToast({
title: '网络连接错误,请求失败!', title: '网络连接错误,请求稍后重试!',
icon: 'none' icon: 'none'
}) })
params.fail && params.fail(res) params.fail && params.fail(res)
@ -78,7 +78,7 @@ class HTTP {
}) })
} }
// 获取 Token // 获取 Token
fetchAuthToken(success) { fetchAuthToken (success) {
// 获取token // 获取token
this._fetchWXCode().then(res => { this._fetchWXCode().then(res => {
console.log('啦啦啦啦凉啊') console.log('啦啦啦啦凉啊')
@ -102,10 +102,10 @@ class HTTP {
}) })
} }
// 获取微信code // 获取微信code
_fetchWXCode() { _fetchWXCode () {
return new Promise(resolve => { return new Promise(resolve => {
wx.login({ wx.login({
success(res) { success (res) {
console.log('获取Code成功 ' + res.code) console.log('获取Code成功 ' + res.code)
resolve(res.code) resolve(res.code)
} }

Loading…
Cancel
Save