2019-12-19 14:18:09 +08:00

123 lines
2.1 KiB
JavaScript

// pages/login/login.js
import {request} from "../../utils/bin"
Page({
/**
* 页面的初始数据
*/
data: {
},
getinfo(a){
request({
url:"User/validateOpenid"
}).then((res)=>{
if(res.data.code == 400){
request({
url:"User/register",
data:{
country:"",
gender:0,
nick_name:a.detail.userInfo.nickName,
province:"",
city:"",
head_pic:a.detail.userInfo.avatarUrl,
open_id: wx.getStorageSync("openid"),
}
}).then((res)=>{
if(res.data.code == 200){
wx.switchTab({
url:"/pages/index/index"
})
}
})
}else{
wx.switchTab({
url:"/pages/index/index"
})
}
})
},
login(a){
console.log(a)
let i = this
wx.login({
success (res) {
if (res.code) {
//发起网络请求
request({
url:"User/getopenId",
data:{
js_code:res.code
}
}).then((res)=>{
console.log(res)
wx.setStorageSync("openid",res.data.openid)
i.getinfo(a)
wx.switchTab({
url:"/pages/index/index"
})
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})