You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
5.1 KiB
207 lines
5.1 KiB
// pages/user/agreement/index.js |
|
const app = getApp(); |
|
Page({ |
|
|
|
/** |
|
* 页面的初始数据 |
|
*/ |
|
data: { |
|
navTopHeight: app.globalData.menuTop + app.globalData.navTopHeight + 10, |
|
userInfo: null, |
|
canIUse: wx.canIUse('button.open-type.getUserInfo'), |
|
canIUseGetUserProfile: false, |
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面加载 |
|
*/ |
|
onLoad: function (options) { |
|
if (wx.getUserProfile) { |
|
this.setData({ |
|
canIUseGetUserProfile: true |
|
}) |
|
} |
|
wx.login({ |
|
success: res => { |
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId |
|
this.setData({ |
|
code: res.code |
|
}) |
|
} |
|
}) |
|
let pages = getCurrentPages(); |
|
console.log(pages) |
|
app.http('get','userinfo').then((res)=>{ |
|
if(res.data.success){ |
|
wx.setStorageSync('userInfo',res.data.data) |
|
this.setData({ |
|
userInfo: res.data.data |
|
}) |
|
} |
|
}).then(()=>{ |
|
if(pages[pages.length - 2]){ |
|
if(this.data.userInfo.isRecharge && pages[pages.length - 2].route !== 'pages/user/index'){ |
|
setTimeout(()=>{ |
|
wx.reLaunch({ |
|
url: '/pages/user/mine/index', |
|
}) |
|
},3000) |
|
} |
|
if(pages[pages.length - 2].route == 'pages/user/completeData/index'){ |
|
console.log('isRecharge',this.data.userInfo.isRecharge) |
|
if(this.data.userInfo.isRecharge == 1){ |
|
setTimeout(()=>{ |
|
wx.reLaunch({ |
|
url: '/pages/user/mine/index', |
|
}) |
|
},3000) |
|
} |
|
} |
|
} else{ |
|
if(this.data.userInfo.isRecharge){ |
|
setTimeout(()=>{ |
|
wx.reLaunch({ |
|
url: '/pages/user/mine/index', |
|
}) |
|
},2000) |
|
} |
|
} |
|
}) |
|
}, |
|
|
|
getUserProfile(e) { |
|
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 |
|
wx.getUserProfile({ |
|
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 |
|
success: (response) => { |
|
wx.showLoading({ |
|
title: '登陆中...', |
|
}) |
|
let data = { |
|
code: this.data.code, |
|
iv: response.iv, |
|
encryptedData:response.encryptedData, |
|
spread: 0, |
|
login_type: 0 |
|
} |
|
app.http('POST','wxapp/auth',data).then( |
|
result =>{ |
|
if(result.data.success){ |
|
wx.hideLoading() |
|
wx.setStorageSync('token', 'Bearer '+ result.data.data.token); |
|
wx.setStorageSync('userInfo', result.data.data.user); |
|
wx.showModal({ |
|
title: "提示", |
|
content: '登陆成功!点击确定按钮完善信息', |
|
success: res =>{ |
|
if(res.confirm){ |
|
if(result.data.data.user.isRecharge == 0){ |
|
wx.navigateTo({ |
|
url: '../personalData/index', |
|
}) |
|
} else{ |
|
setTimeout(()=>{ |
|
wx.reLaunch({ |
|
url: '/pages/user/index', |
|
}) |
|
},1000) |
|
} |
|
} else{ |
|
if(result.data.data.user.isRecharge == 0){ |
|
wx.navigateTo({ |
|
url: '../personalData/index', |
|
}) |
|
} else{ |
|
setTimeout(()=>{ |
|
wx.reLaunch({ |
|
url: '/pages/user/index', |
|
}) |
|
},1000) |
|
} |
|
} |
|
} |
|
}) |
|
} else{ |
|
wx.showToast({ |
|
title: result.data.msg, |
|
icon : 'none' |
|
}) |
|
} |
|
} |
|
) |
|
|
|
} |
|
}) |
|
}, |
|
getUserInfo(e) { |
|
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 |
|
this.setData({ |
|
userInfo: e.detail.userInfo, |
|
hasUserInfo: true |
|
}) |
|
}, |
|
toPay(){ |
|
wx.navigateTo({ |
|
url: '../personalData/index', |
|
}) |
|
}, |
|
backPage(){ |
|
wx.navigateBack({ |
|
delta: 1, |
|
}) |
|
}, |
|
/** |
|
* 生命周期函数--监听页面初次渲染完成 |
|
*/ |
|
onReady: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面显示 |
|
*/ |
|
getUser(){ |
|
this.setData({ |
|
userInfo: wx.getStorageSync('userInfo') |
|
}) |
|
}, |
|
onShow: function () { |
|
app.getInfo(); |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面隐藏 |
|
*/ |
|
onHide: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面卸载 |
|
*/ |
|
onUnload: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 页面相关事件处理函数--监听用户下拉动作 |
|
*/ |
|
onPullDownRefresh: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 页面上拉触底事件的处理函数 |
|
*/ |
|
onReachBottom: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 用户点击右上角分享 |
|
*/ |
|
onShareAppMessage: function () { |
|
|
|
} |
|
}) |