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.
 

180 lines
3.5 KiB

import until from "../../utils/common";
let common = getApp().globalData.commonFun;
let util = getApp().globalData.utilFun;
Page({
/**
* 页面的初始数据
*/
data: {
tel:"",//手机号
password:"",// 密码
isRead:false,
privateStatus:false,
showPrivate:false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
showTips(){
until.showTimeToast('请先阅读隐私协议');
},
clickPrivate(){
this.setData({
isRead:!this.data.isRead
});
console.log(this.data.isRead)
},
showPrivate(){
wx.openPrivacyContract({});
},
// 手机号
tel (e) {
this.setData({
tel:e.detail.value
})
},
// 密码
passwords (e) {
this.setData({
password: e.detail.value
})
},
// 登录
sign () {
wx.showLoading({
title: '登录中...',
mask: true
})
if (this.data.tel == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.data.tel))) {
wx.showToast({
title: '请输入正确的手机号码',
icon: 'none',
duration: 2000
})
} else if (this.data.password == '') {
wx.showToast({
title: '请输入密码',
icon: 'none',
duration: 2000
})
} else {
let url = 'api/login'
let data = {
phone: this.data.tel,
password: this.data.password
}
util.httpRequest(url, data, 'post').then((res) => {
console.log(res)
wx.hideLoading()
if (res.code == '200') {
wx.setStorageSync("token", res.data.token.token);
wx.setStorageSync("refresh_token", res.data.token.refresh_token);
wx.setStorageSync("userInfo", res.data);
// wx.setStorageSync("time", parseInt(res.data.token.exp / 1000));
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 2000,
mask: true
})
setTimeout(() => {
wx.switchTab({
url: '../index/index'
})
}, 2000)
} else {
wx.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
}
},
// 微信登录
bindGetUserInfo() {
wx.getUserInfo({
success: function(res) {
console.log(res.userInfo)
}
})
},
handleAgreePrivacyAuthorization() {
this.setData({
privateStatus: false,
showPrivate: false,
});
},
showPrivatePopup() {
this.setData({
showPrivate: true,
});
},
handleDisagree() {
this.setData({showPrivate: false});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
wx.getPrivacySetting({
success: res => {
console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)
this.setData({privateStatus:res.needAuthorization})
},
fail: () => {
},
complete: () => {},
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})