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: {
messageTotal: Number,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
authType:0
authType: 0
},
/**
@ -26,11 +26,11 @@ 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
@ -38,7 +38,7 @@ Page({
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,7 +62,7 @@ Page({
})
})
},
bindGetUserInfo(e) {
bindGetUserInfo (e) {
console.log(e.detail.userInfo)
let avatarUrl = e.detail.userInfo.avatarUrl
@ -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 () {
}
})

14
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)
}

Loading…
Cancel
Save