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.
 

258 lines
6.2 KiB

var app = getApp();
var WXAPI = require('../../utils/server.js');
Page({
data: {
navTab: [{'type':'验证码登录','status':0},{'type':'密码登录','status':1}],
currentIndex: 1,
click: false, //是否显示弹窗内容
option: false, //显示弹窗或关闭弹窗的操作动画
logoimg: '',
loadtitle:'',
thvm:{},
account: '',
password: '',
code: "",
tmplIds: [],
},
//密码登录to验证码登录
switchTab: function(e) {
// this.landing = false
// this.codeLoginBtnStatus = false
// this.phone_codeStatus1 = false
// this.account = ''
// this.password = ''
// this.tabbar_isShow = 1
this.setData({
currentIndex: e.currentTarget.dataset.idx,
tabbar_isShow: e.currentTarget.dataset.item.status,
});
},
// 用户点击显示弹窗
setCloses:function(){
wx.showToast({
title: '没有授权,不能进入小程序个人中心!',
icon: 'none',
duration: 2000
})
this.clickPup()
},
clickPup: function (vm) {
this.setData({
logoimg: app.globalData.logoimg,
loadtitle: app.globalData.title,
thvm: vm ? vm:''
})
let _that = this;
if (!_that.data.click) {
_that.setData({
click: true,
})
}
if (_that.data.option) {
_that.setData({
option: false,
})
// 关闭显示弹窗动画的内容,不设置的话会出现:点击任何地方都会出现弹窗,就不是指定位置点击出现弹窗了
setTimeout(() => {
_that.setData({
click: false,
})
}, 500)
} else {
_that.setData({
option: true
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.reloadData()
},
reloadData() {
var that = this
wx.login({
success: function (res) {
var code = res.code;
that.setData({
code: code,
})
WXAPI.getWXTemplates({
storeId: 239,
storeType: 1,
}).then(res => {
if (res.code == 200) {
var data = res.data
wx.setStorageSync('logmsgId', [data.delivery])
}
})
}
});
},
// wxlogin(){
// var that = this
// WXAPI.wxLogin({
// code: that.data.code,
// storeId: 239,
// storeType: 1,
// }).then(res => {
// if (res.code == 200) {
// var data = res.data
// app.globalData.accessId = data.access_id;
// wx.setStorageSync('accessId', data.access_id)
// wx.setStorageSync('isLogin', true);
// wx.setStorageSync('userInfo', data.user);
// wx.navigateBack()
// }
// })
// },
//授权微信手机号
bindPhoneNumber: function(e) {
var that = this;
if (e.detail.errMsg == "getPhoneNumber:ok") {
//用户按了确认按钮
that.tapWeixinLogin(e);
} else {
//用户按了拒绝按钮
wx.showModal({
title:'警告',
content:'您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!',
showCancel:false,
confirmText:'返回授权',
success:function(res){
if (res.confirm) {
console.log('用户点击了“返回授权”')
}
}
})
}
},
//微信一键登录
tapWeixinLogin : function(e) {
var that = this
WXAPI.wxLogin({
code: that.data.code,
storeId: 239,
storeType: 1,
}).then(res => {
if (res.code == 200) {
var data = res.data
app.globalData.accessId = data.access_id;
wx.setStorageSync('accessId', data.access_id)
wx.setStorageSync('isLogin', true);
wx.setStorageSync('userInfo', data.user);
wx.navigateBack()
}
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
accountInput: function(e) {
this.setData({
valueId: "nickname",
account: e.detail.value
})
},
passwordInput: function(e) {
this.setData({
valueId: "nickname",
password: e.detail.value
})
},
forgetAct() {
wx.navigateTo({
url: '/pages/login/register?name=找回密码',
})
},
loginAct: function () {
var that = this;
WXAPI.login({
storeId: 239,
storeType: 1,
phone: that.data.account,
password: that.data.password,
}).then(res => {
if (res.code == 200) {
var data = res.data
app.globalData.accessId = data.access_id;
wx.setStorageSync('accessId', data.access_id)
wx.setStorageSync('isLogin', true);
wx.setStorageSync('userInfo', data.data);
wx.navigateBack()
wx.showToast({
title: '登录成功!',
success: 2000
});
} else {
wx.showToast({
title: res.message,
icon: 'none',
duration: 1500,
})
}
});
},
registerAct() {
wx.navigateTo({
url: '/pages/login/register?name=注册',
})
},
getOP: function (res) {
//提交用户信息 获取用户id
let that = this
let thatplus = this.data.thvm
app.getUserInfo('', '', res, function (){
let userInfo = res;
var user = app.globalData.userInfo;
app.globalData.userInfo['avatarUrl'] = userInfo.avatarUrl; // 头像
app.globalData.userInfo['nickName'] = userInfo.nickName; // 昵称
app.globalData.userInfo['gender'] = userInfo.gender; // 性别
wx.setStorageSync('userInfo', app.globalData.userInfo);
//写入缓存
var nickName = userInfo.nickName;
var avatarUrl = userInfo.avatarUrl;
var gender = userInfo.gender; //性别 0:未知、1:男、2:女
wx.request({
url: app.d.ceshiUrl + '&action=user&m=material',
method: 'post',
data: {
openid: app.globalData.userInfo.openid,
nickName: nickName,
avatarUrl: avatarUrl,
gender: gender
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
wx.showToast({
title: '授权成功!',
success: 2000
});
setTimeout(function () {
that.clickPup()
thatplus.onLoad()
}, 1800);
}
})
})
}
})