170 lines
3.0 KiB
JavaScript
170 lines
3.0 KiB
JavaScript
// pages/login/index.js
|
|
const app = getApp();
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
username: 'admin',
|
|
password: 'Daofu123456',
|
|
showLogin: true,
|
|
},
|
|
|
|
/**
|
|
* 切换登录/注册
|
|
*/
|
|
changeWay: function (e) {
|
|
this.data.showLogin = e.currentTarget.dataset.type;
|
|
this.setData(this.data)
|
|
},
|
|
|
|
/**
|
|
* 绑定内容
|
|
*/
|
|
inputMethed: function (e) {
|
|
const type = e.currentTarget.dataset.type;
|
|
let value = e.detail.value;
|
|
this.data[type] = value;
|
|
this.setData(this.data)
|
|
},
|
|
|
|
/**
|
|
* 普通登录
|
|
*/
|
|
login: function (params) {
|
|
const type = params.currentTarget.dataset.type;
|
|
this.data.type = type;
|
|
if (type == 1) {
|
|
if (!this.data.username) {
|
|
wx.showToast({
|
|
title: '请输入用户名',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
if (!this.data.password) {
|
|
wx.showToast({
|
|
title: '请输入密码',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
wx.showLoading({
|
|
title: '登录中...',
|
|
})
|
|
this.handleLogin(this.data);
|
|
} else {
|
|
wx.showLoading({
|
|
title: '登录中...',
|
|
})
|
|
wx.login({
|
|
success: (res) => {
|
|
this.data.code = res.code;
|
|
this.handleLogin(this.data);
|
|
},
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 实际登录
|
|
*/
|
|
handleLogin: function (params) {
|
|
app.axios('POST', 'app', '/login/wxLogin', params, false).then(res => {
|
|
wx.hideLoading()
|
|
if (res.code == 1) {
|
|
app.globalData.userInfo = res.data;
|
|
wx.setStorage({
|
|
key: 'userInfo',
|
|
data: res.data,
|
|
})
|
|
wx.reLaunch({
|
|
// url: '/pages/index/index',
|
|
url: '/pages/the-masses/index/index',
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: res.message,
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 绑定弹窗
|
|
*/
|
|
handlePop: function (params) {
|
|
this.data.showPop = !this.data.showPop;
|
|
this.setData(this.data);
|
|
if (app.globalData.userInfo.userId) {
|
|
wx.reLaunch({
|
|
// url: '/pages/index/index',
|
|
url: '/pages/the-masses/index/index',
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
if (app.globalData.userInfo.userId) {
|
|
wx.reLaunch({
|
|
// url: '/pages/index/index',
|
|
url: '/pages/the-masses/index/index',
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |