App({ globalData: { // ip: 'http://bl7.matripe.com.cn:8001', ip: "https://daotian.matripe.com.cn", //ip: 'http://localhost:8001', sessionId: '', headers2: { "content-type": "multipart/form-data", 'Cookie': '' }, headers: { "content-type": "application/x-www-form-urlencoded", 'Cookie': '' }, userLoginTokenInfo: { tel: '',//用户电话 token: '',//用户token }, isLogin: false,//是否登录 loginUserInfo: { id: '', userName: '', tel: '', imgSrc: '', }, lng: '', lat: '', autoLoginTag: 0,//是否是自动登录,0否、1是 isScanQRCodes: 0,//是否是扫码进来的,0否、1是 hasUserInfo: 0,//是否有用户授权信息 agencyStatus: 0,//是否是代理 openId: '', isCommission: 0,//是否计算佣金,0否、1是 user: {},//用户信息 }, onLaunch(options) { const updateManager = wx.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { console.log("onCheckForUpdate====", res); // 请求完新版本信息的回调 if (res.hasUpdate) { console.log("res.hasUpdate===="); updateManager.onUpdateReady(function () { wx.showModal({ title: "更新提示", content: "新版本已经准备好,是否重启应用?", success: function (res) { console.log("success====", res); // res: {errMsg: "showModal: ok", cancel: false, confirm: true} if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate(); } }, }); }); updateManager.onUpdateFailed(function () { // 新的版本下载失败 wx.showModal({ title: "已经有新版本了哟~", content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~", }); }); } }); // 第一次打开 // options.query == {number:1} console.info("App onLaunch"); try { console.log('options==============================3'); var obj = wx.getLaunchOptionsSync(); console.log(obj); console.log('——启动小程序的路径:', obj.path) console.log('——启动小程序的场景值:', obj.scene) console.log('——启动小程序的 query 参数:', obj.query) console.log('——来源信息:', obj.shareTicket) console.log('——来源信息参数appId:', obj.referrerInfo.appId) console.log('——来源信息传过来的数据:', obj.referrerInfo.extraData) console.log('options==============================4'); if (obj.scene == 1011 || obj.scene == 1012 || obj.scene == 1013 || obj.scene == 1047 || obj.scene == 1048 || obj.scene == 1049) { this.globalData.isScanQRCodes = 1; } else {//不是扫码登录的直接走缓存登录方法 this.getLoginUserTokenInfo(); } } catch (e) { console.log("启动小程序参数错误:", e); this.getLoginUserTokenInfo(); } // this.getLoginUserTokenInfo(); }, onShow(options) { // 从后台被 scheme 重新打开 // options.query == {number:1} }, isEmptyCheck: function(str) { if ( str == null || str == "" || str == "null" || str == "undefined" || typeof str == "undefined" ) { return true; } return false; }, isNotEmptyCheck: function(str) { return !this.isEmptyCheck(str); }, getLoginUserTokenInfo: function() { var that = this; try { var value = wx.getStorageSync('loginUserTokenInfo'); if (value) { that.globalData.userLoginTokenInfo = value; if (that.isNotEmptyCheck(that.globalData.userLoginTokenInfo.tel)) { that.globalData.autoLoginTag = 1; // that.appLoginByTel(); return new Promise(function(resolve, reject) { try { that.appLoginByTel(resolve, reject); } catch (e) { console.log('设置登录信息错误'); console.log(e); reject(); } }); } } console.log('获取用户登录信息---------------start'); console.log(value); console.log('获取用户登录信息---------------end'); } catch (e) { console.log('获取登录信息错误'); console.log(e); } }, setLoginUserTokenInfo: function(tel, token) { var that = this; return new Promise(function(resolve, reject) { try { that.globalData.userLoginTokenInfo.tel = tel; that.globalData.userLoginTokenInfo.token = token; wx.setStorageSync('loginUserTokenInfo', that.globalData.userLoginTokenInfo); that.appLoginByTel(resolve, reject); } catch (e) { console.log('设置登录信息错误'); console.log(e); reject(); } }); }, appLoginByTel: function(resolve, reject) { var that = this; var channelContactId = ''; try { var value = wx.getStorageSync('fromQrCodeChannelContactId') if (value) { console.log("fromQrCodeChannelContactId:======", value); channelContactId = value; } } catch (e) { console.log("获取缓存设置的参数错误:", e); } var agencyUserId = ''; try { var value = wx.getStorageSync('storageSyncAgencyUserId') if (value) { console.log("storageSyncAgencyUserId======", value); agencyUserId = value; } } catch (e) { console.log("获取缓存设置的参数错误:", e); } wx.request({ url: that.globalData.ip + '/appLoginByTel', data: { tel: that.globalData.userLoginTokenInfo.tel, autoLoginTag: that.globalData.autoLoginTag, isScanQRCodes: that.globalData.isScanQRCodes, channelContactId: channelContactId, agencyUserId: agencyUserId, openId: that.globalData.openId, }, header: { 'content-type': 'application/json' }, success: function (res) { console.log(res); if (res.data.status == 200) { that.globalData.user = res.data.data.user; that.globalData.sessionId = res.data.data.sessionId; that.globalData.headers.Cookie = 'JSESSIONID=' + res.data.data.sessionId; that.globalData.headers2.Cookie = 'JSESSIONID=' + res.data.data.sessionId; that.globalData.isLogin = true; that.globalData.agencyStatus = res.data.data.agencyStatus; that.globalData.hasUserInfo = res.data.data.imgSrc != '' && res.data.data.imgSrc != null && res.data.data.imgSrc != undefined && res.data.data.nickName != '' && res.data.data.nickName != null && res.data.data.nickName != undefined ? 1 : 0, that.globalData.loginUserInfo = res.data.data; resolve(); } else { that.dialog('提示', res.data.msg, '确定'); reject(); } if (that.userLoginCallback) { that.userLoginCallback(res) } console.log("login====result=======1"); console.log(that.globalData); console.log("login====result=======2"); wx.showToast({ title: '登录成功', icon: 'success', duration: 2000 }) } }) }, logout: function() { var that = this; return new Promise(function(reslove, reject) { try { wx.removeStorageSync('loginUserTokenInfo'); that.globalData.autoLoginTag = 0; that.globalData.sessionId = ''; that.globalData.headers.Cookie = ''; that.globalData.headers2.Cookie = ''; that.globalData.isLogin = false; that.globalData.hasUserInfo = 0; that.globalData.loginUserInfo = {}; reslove(); } catch (e) { console.log("退出登录失败"); console.log(e); reject(); } }); }, dialog: function (title, content, btxt) { wx.showModal({ title: title, content: content, showCancel: false, confirmColor: "#e60012", confirmText: btxt, success: function (res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) }, showTips: function (_that, msg) { /*_that.setData({ popErrorMsg: msg, pop: 1, }); setTimeout(() => { _that.setData({ popErrorMsg: '', pop: 0, }); return; }, 2000)*/ wx.showToast({ icon: "none", title: msg, duration: 3000 }); }, load: function (text) { wx.showLoading({ title: text, mask: true }) }, hideLoad:function(){ wx.hideLoading(); }, success: function (text) { wx.showToast({ title: text, icon: 'success', duration: 2000 }) }, })