init project
This commit is contained in:
162
pages/login/index.js
Normal file
162
pages/login/index.js
Normal file
@@ -0,0 +1,162 @@
|
||||
// pages/login/index.js
|
||||
const app = getApp();
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
showUnclickMask: false,
|
||||
isGoHome: false,
|
||||
isLogin: false,
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function(options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function() {
|
||||
let pages = getCurrentPages();
|
||||
this.setData({
|
||||
isGoHome: pages.length == 1
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function() {
|
||||
if (this.data.isLogin) {
|
||||
this.pushRoute()
|
||||
return;
|
||||
}
|
||||
let that = this;
|
||||
this.setData({
|
||||
showUnclickMask: false
|
||||
})
|
||||
},
|
||||
|
||||
pushRoute() {
|
||||
let route = wx.getStorageSync('history');
|
||||
wx.removeStorageSync('history');
|
||||
if (!route || route == '/pages/login/index') {
|
||||
return wx.redirectTo({
|
||||
url: '/pages/mine/index',
|
||||
})
|
||||
}
|
||||
wx.redirectTo({
|
||||
url: route,
|
||||
})
|
||||
},
|
||||
|
||||
changeLoginStatus() {
|
||||
this.setData({
|
||||
isLogin: true
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function() {
|
||||
return {
|
||||
title: '智慧云馆'
|
||||
}
|
||||
},
|
||||
|
||||
// 登录
|
||||
loginClick() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/loginIndex/index',
|
||||
})
|
||||
},
|
||||
|
||||
// 注册
|
||||
registerClick(e) {
|
||||
wx.redirectTo({
|
||||
url: '/pages/register/index?codeType=' + 2,
|
||||
})
|
||||
},
|
||||
|
||||
// 微信登录
|
||||
wxLogin(e) {
|
||||
if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
showUnclickMask: true
|
||||
})
|
||||
let that = this;
|
||||
wx.login({
|
||||
success: function(res) {
|
||||
app.$api.memberLoginWX({
|
||||
avatar: e.detail.userInfo.avatarUrl,
|
||||
code: res.code,
|
||||
nickname: e.detail.userInfo.nickName
|
||||
}).then(res => {
|
||||
wx.setStorageSync('information', res.information);
|
||||
if (!res.authorization) {
|
||||
wx.redirectTo({
|
||||
url: '/pages/register/index?codeType=' + 1,
|
||||
})
|
||||
return;
|
||||
}
|
||||
wx.setStorageSync('accessToken', res.authorization.accessToken);
|
||||
let route = wx.getStorageSync('history');
|
||||
wx.removeStorageSync('history');
|
||||
if (!route || route == '/pages/login/index') {
|
||||
return wx.redirectTo({
|
||||
url: '/pages/mine/index',
|
||||
})
|
||||
}
|
||||
wx.redirectTo({
|
||||
url: route,
|
||||
})
|
||||
}, err => {
|
||||
that.setData({
|
||||
showUnclickMask: false
|
||||
})
|
||||
});
|
||||
},
|
||||
fail: function(res) {
|
||||
that.setData({
|
||||
showUnclickMask: false
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user