141 lines
3.1 KiB
JavaScript
141 lines
3.1 KiB
JavaScript
// pages/login/login.js
|
||
const App = getApp();
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
loginState:0,
|
||
openId:0,
|
||
title:"",
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad: function (options) {
|
||
wx.setStorageSync('yiyan', "");
|
||
this.setData({
|
||
navH: App.globalData.navHeight
|
||
})
|
||
this.getyiyian();
|
||
this.login();
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage: function () {
|
||
|
||
},
|
||
getyiyian:function(){ //获取一言
|
||
var that=this;
|
||
wx.request({
|
||
url: 'https://v1.hitokoto.cn/',
|
||
success: function (res) {
|
||
if(res.data.hitokoto.length>30){ //如果长度大于30就重新获取
|
||
that.getyiyian();
|
||
}else{
|
||
console.log(res.data);
|
||
wx.setStorageSync('yiyan', res.data);
|
||
}
|
||
}
|
||
})
|
||
},
|
||
login: function(){
|
||
wx.showLoading({
|
||
title: '登录中',
|
||
})
|
||
var that = this;
|
||
wx.login({
|
||
success: function (res) {
|
||
if (res.code) {
|
||
wx.request({
|
||
url: 'https://powerrain.cn/qrcode/api/login.php',
|
||
data: {
|
||
code: res.code
|
||
},
|
||
success: function (oiRes) { //openId
|
||
that.data.loginState = 1;
|
||
that.data.openId = oiRes.data;
|
||
wx.setStorageSync('openId', oiRes.data);
|
||
wx.hideLoading();
|
||
wx.request({
|
||
url: 'https://powerrain.cn/qrcode/api/wxselect.php',
|
||
data: {
|
||
openId: oiRes.data
|
||
},
|
||
success: function (infoRes) { //如果该id未合并过二维码,此处为[](空数组)
|
||
console.log(infoRes);
|
||
if (infoRes.data.length != 0) {
|
||
wx.setStorageSync('qrinfo', infoRes.data); //将已经存在的二维码存放起来,然后下一个界面做成卡片。
|
||
wx.switchTab({
|
||
url: '../index/index'
|
||
})
|
||
} else {
|
||
wx.setStorageSync('qrinfo', "");
|
||
wx.switchTab({
|
||
url: '../index/index'
|
||
})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
fail: function () {
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title: "登录失败",
|
||
icon: "none"
|
||
})
|
||
}
|
||
})
|
||
} else {
|
||
console.log('获取失败' + res.errMsg)
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}) |