You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.4 KiB
JavaScript

2 years ago
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
haveScopeUserInfo: false,
type:0,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
isIos: app.globalData.isIos,
currStatusBarHeight: app.globalData.currStatusBarHeight,
});
if(app.isNotEmptyCheck(options.type)) {
this.setData({
type : app.isNotEmptyCheck(options.type) ? options.type : '',
});
}
console.log(options.type);
},
onShow: function() {
var that = this;
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.userInfo']) {
that.setData({
haveScopeUserInfo: true,
});
}
}
})
},
bindInfo: function (e) {
var that = this;
console.log("-----------11--------------");
if (e.detail.userInfo) {
var url = '';
console.log('授权通过')
app.globalData.userInfo = e.detail.userInfo;
try {
app.load("授权中...");
/*if(app.isNotEmptyCheck(that.data.type)) {
if(that.data.type - 1 == 0) {
url = '/pages/intvRecord/index';
} else if(that.data.type - 2 == 0) {
url = '/pages/realNameAuth/registerAuth/authName/index';
} else if(that.data.type - 3 == 0) {
url = '/pages/user/healthCard/index';
} else if(that.data.type - 4 == 0) {
url = '/pages/bindBank/bindBankCardOne/index';
} else if(that.data.type - 5 == 0) {
url = '/pages/myWorkingJobList/index';
}
}*/
that.login(url);
} catch (e) {
app.userWechatAuth(999);
// wx.removeStorageSync('comeFromPage');
wx.switchTab({
url: '/pages/stationReach/index',
})
} finally {
// wx.removeStorageSync('comeFromPage');
}
} else {
console.log('拒绝授权')
/*wx.reLaunch({
url: '/pages/wechatAuthNew/index?type=2',
})*/
}
},
login: function(url) {
console.log("==========执行登录方法==========");
var code;
var that = this;
// 登录
wx.login({
//获取code
success: function (res) {
code = res.code //返回code
console.log("code : " + code);
wx.getSetting({
success: (res) => {
if (!res.authSetting['scope.userInfo']) {//未授权, <button open-type="getUserInfo"></button>
wx.reLaunch({
url: '/pages/wechatAuthNew/index?type=' + type,
})
} else {
wx.getUserInfo({
success: function (res) {
console.log(res);
wx.request({
url: app.globalData.ip + '/appLogin',
data: {
code: code,
encryptedData: res.encryptedData,
iv: res.iv,
},
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res);
if (res.data.status == 200) {
app.globalData.isLogin = true;
app.globalData.sessionId = res.data.data.sessionId;
app.globalData.header.Cookie = 'JSESSIONID=' + res.data.data.sessionId;
app.globalData.header2.Cookie = 'JSESSIONID=' + res.data.data.sessionId;
app.globalData.userInfo = res.data.data.userInfo;
app.globalData.userId = res.data.data.userId;
app.hideLoad();
if (app.isNotEmptyCheck(res.data.data.userInfo) && app.isNotEmptyCheck(res.data.data.userInfo.tel)) {
console.log(url);
wx.switchTab({
url: app.isNotEmptyCheck(url) ? url : '/pages/stationReach/index',
})
// wx.reLaunch({
// url: '/pages/index/index',
// })
} else {
wx.switchTab({
url: '/pages/stationReach/index',
})
}
//登录成功,执行回调
if (that.userLoginCallback) {
that.userLoginCallback(res)
}
} else {
that.dialog('提示', res.data.msg, '确定');
}
// console.log("login====result=======1");
// console.log(app.globalData);
// console.log("login====result=======2");
}
})
}
})
}
}
})
}
})
},
toRegister: function() {
wx.switchTab({
url: '/pages/stationReach/index',
})
}
})