const ajax = require("../../common/ajax.js")
const tips = require("../../common/tips.js")
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this;
},
getUserInfoAction(res){
let that = this;
const encryptedData = res.detail.encryptedData;
const iv = res.detail.iv;
if (encryptedData && iv){
// console.log("允许")
that.login().then((login)=>{
const params = {
"code": login.code,
"encryptedData": encryptedData,
"iv": iv,
"type": "small_wechat"
}
ajax.posts(params, "api/passport/thirdSign").then((res) => {
let userinfo = {
avatar: res.data.data.avatar,
nickname: res.data.data.nickname,
token: res.data.data.token,
user_id: res.data.data.user_id
}
wx.setStorageSync("userinfo", userinfo);
// console.log(wx.getStorageSync("userinfo"));
if (wx.getStorageSync("userinfo")){
wx.redirectTo({
url: '/page/index/index'
})
}
}).catch((errMsg) => {
tips.showToast("网络连接失败", "none")
console.log(errMsg)
})
}).catch((errMsg) => {
console.log("登录:" + errMsg)
})
}else{
// console.log("拒绝")
tips.showToast("请授权公开信息,登录小程序", "none")
}
},
login(){
// 登录
let promise = new Promise((resolve, reject) => {
wx.login({
success: function (res) {
if (res.code) {
resolve(res)
} else {
tips.showToast("登录失败", "none")
}
},
fail: function (err) {
reject(err)
}
})
})
return promise;
}
})
const tips = require("../../common/tips.js")
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this;
if (!wx.getStorageSync("userinfo")) {
//是否登录
that.isloginindex()
}
},
isloginindex() {
//是否进入首页
if (wx.getStorageSync("userinfo")) {
console.log("登录")
} else {
//无信息
console.log("否登录")
wx.redirectTo({
url: '/page/login/login'
})
}
}
})