//app.js App({ globalData: { // ip: 'https://zhuchangtong.matripe.com.cn',//正式 ip: 'https://zhuchangtong.ibocai.com.cn',//正式 // ip: "http://b.renminshitang.com.cn:8002", //测试 // ip: 'http://localhost:8002', userInfo: null, test:'a', sessionId: "", offlineManage: false, userId: {}, header: { "content-type": "application/x-www-form-urlencoded", Cookie: "", }, header2: { "content-type": "multipart/form-data", Cookie: "", }, headers: { "content-type": "application/x-www-form-urlencoded", Cookie: "", }, remoteHeaders:{ "content-type": "application/x-www-form-urlencoded", Cookie: "", }, userLoginTokenInfo: { tel: "", //用户电话 token: "", //用户token }, isLogin: false, //是否登录 loginUserInfo: { id: "", userName: "", tel: "", imgSrc: "", }, hasAva:false, lng: "", lat: "", autoLoginTag: 0, //是否是自动登录,0否、1是 hasUserInfo: 0, //是否有用户授权信息 agencyStatus: 0, //是否是代理 openId: "", unionId: '', user: {}, //用户信息 version: null, }, onLaunch: function (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: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' }) }) } }) this.globalData.firstPath = options.path; this.globalData.firstQuery = options.query; // 展示本地存储能力 const { statusBarHeight, platform } = wx.getSystemInfoSync(); const { top, height } = wx.getMenuButtonBoundingClientRect(); console.log(statusBarHeight); console.log(wx.getMenuButtonBoundingClientRect()); console.log(top, height); // 状态栏高度 wx.setStorageSync("statusBarHeight", statusBarHeight); // 胶囊按钮高度 一般是32 如果获取不到就使用32 wx.setStorageSync("menuButtonHeight", height ? height : 32); // 胶囊按钮信息 wx.setStorageSync("menuButtonInfo", wx.getMenuButtonBoundingClientRect()); // 判断胶囊按钮信息是否成功获取 if (top && top !== 0 && height && height !== 0) { const navigationBarHeight = (top - statusBarHeight) * 2 + height; // 导航栏高度 wx.setStorageSync("navigationBarHeight", navigationBarHeight); } else { wx.setStorageSync("navigationBarHeight", platform === "android" ? 48 : 40); } var logs = wx.getStorageSync("logs") || []; logs.unshift(Date.now()); wx.setStorageSync("logs", logs); const miniProgram = wx.getAccountInfoSync(); console.log(miniProgram); this.globalData.version = miniProgram.miniProgram.version || "1.0.100"; // this.userWechatAuth(999); this.getLoginUserTokenInfo(); console.log(this.__proto__ == wx.__proto__); console.log(wx.__proto__); }, userWechatAuth: function (type) { return; /*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']) {//未授权, console.log("1122relaunch333"); if(type - 999 != 0 || that.isNotEmptyCheck(wx.getStorageSync('comeFromPage'))) {//只拉去用户信息,不跳转到授权页面 wx.navigateTo({ url: '/pages/wechatAuthNew/index?type=' + type, }) } } else { wx.getUserInfo({ success: function (res) { console.log(res); wx.request({ url: that.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) { that.globalData.isLogin = true; that.globalData.sessionId = res.data.data.sessionId; that.globalData.header.Cookie = 'JSESSIONID=' + res.data.data.sessionId; that.globalData.header2.Cookie = 'JSESSIONID=' + res.data.data.sessionId; that.globalData.userInfo = res.data.data.userInfo; that.globalData.userId = res.data.data.userId; that.globalData.offlineManage = res.data.data.offlineManage; that.globalData.user = res.data.data.user; //登录成功,执行回调 if (that.userLoginCallback) { that.userLoginCallback(res) } } else if(res.data.status == 222) {//重复提交的,不做任何响应 } else { that.dialog('提示', res.data.msg, '确定'); } console.log("login====result=======1"); console.log(that.globalData); console.log("login====result=======2"); } }) } }) } } }) } })*/ }, getLoginUserTokenInfo: function () { var that = this; try { var value = wx.getStorageSync("loginUserTokenInfo"); if (value) { that.globalData.userLoginTokenInfo = value; // console.log(that.isNotEmptyCheck(that.globalData.userLoginTokenInfo.token)); if (that.isNotEmptyCheck(that.globalData.userLoginTokenInfo.token)) { let token = that.globalData.userLoginTokenInfo.token; that.globalData.header.Authorization = "Bearer " + token; that.globalData.header2.Authorization = "Bearer " + token; that.globalData.headers.Authorization = "Bearer " + token; wx.request({ url: that.globalData.ip + '/checkToken', method: "GET", header: that.globalData.headers, success: function (res) { console.log(res); if(res.data.status == 200) { that.globalData.isLogin = true; that.globalData.test = 'b'; that.globalData.user = res.data.data.user; that.globalData.sessionId = res.data.data.sessionId; // 41项目客服 132项目经理 142跟单客服 135客户经理 146项目拓展 144询单客服 that.globalData.roleOf41 = res.data.data.roleOf41; that.globalData.roleOf142 = res.data.data.roleOf142; that.globalData.roleOf132 = res.data.data.roleOf132; that.globalData.managerRoleClassify = res.data.data.managerRoleClassify; if(!that.isEmptyCheck(res.data.data.imgSrc)){ if(res.data.data.imgSrc != '' && res.data.data.imgSrc.startsWith('https://file.matripe.com') ){ that.globalData.hasAva = true }else{ that.globalData.hasAva = false } } wx.setStorageSync("loginUser", that.globalData); if (that.userLoginCallback) { that.userLoginCallback(res); } } else {//已过期 that.globalData.autoLoginTag = 1; // that.appLoginByTel(); // that.globalData.isLogin = false; return new Promise(function (resolve, reject) { try { that.appLoginByTel(resolve, reject); } catch (e) { console.log("设置登录信息错误"); console.log(e); reject(); } }); } } }) // console.log(that.globalData.isLogin); }else 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(); } }); } } else { if (that.userLoginCallback) { that.userLoginCallback(); } } console.log("获取用户登录信息---------------start"); console.log(that.globalData.test); // that.globalData.isLogin = true setTimeout(()=>{ console.log(that.globalData.isLogin); },1000) 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; wx.request({ url: that.globalData.ip + "/appLoginByTel", data: { tel: that.globalData.userLoginTokenInfo.tel, autoLoginTag: that.globalData.autoLoginTag, openId: that.globalData.openId, unionid: that.globalData.unionId, }, 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; // 41项目客服 132项目经理 142跟单客服 that.globalData.roleOf41 = res.data.data.roleOf41; that.globalData.roleOf132 = res.data.data.roleOf132; that.globalData.roleOf142 = res.data.data.roleOf142; that.globalData.managerRoleClassify = res.data.data.managerRoleClassify; that.globalData.header.Cookie = "JSESSIONID=" + res.data.data.sessionId; that.globalData.header2.Cookie = "JSESSIONID=" + res.data.data.sessionId; that.globalData.headers.Cookie = "JSESSIONID=" + res.data.data.sessionId; // that.globalData.header.Authorization = "Bearer " + res.data.data.token; // that.globalData.header2.Authorization = "Bearer " + res.data.data.token; // that.globalData.headers.Authorization = "Bearer " + res.data.data.token; that.globalData.remoteHeaders.Cookie = "JSESSIONID=" + res.data.data.remoteSessionId; that.globalData.isLogin = true; that.globalData.read = res.data.data.read; that.globalData.userLoginTokenInfo.tel = res.data.data.tel; that.globalData.userLoginTokenInfo.token = res.data.data.token; wx.setStorageSync("loginUserTokenInfo", that.globalData.userLoginTokenInfo); wx.setStorageSync("loginUser", that.globalData); console.log(that.globalData.read); console.log("↑↑↑↑↑app.js↑↑↑↑↑"); // wx.showTabBarRedDot({ // index:2 // }) if (that.globalData.read == 2) { wx.showTabBarRedDot({ index: 2, }); } // else { // wx.hideTabBarRedDot({ // index: 2, // }); // } 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); that.globalData.userInfo = res.data.data.user; that.globalData.userId = res.data.data.id; that.globalData.offlineManage = res.data.data.offlineManage; if (that.userLoginCallback) { that.userLoginCallback(res); } resolve(); } else { that.dialog("提示", res.data.msg, "确定"); if (that.userLoginCallback) { that.userLoginCallback(res); } reject(); } console.log("login====result=======1"); console.log(that.globalData.user); console.log(that.globalData.user.imgSrc); console.log("login====result=======2"); if(!that.isEmptyCheck(that.globalData.user.imgSrc)){ if(that.globalData.user.imgSrc != '' && that.globalData.user.imgSrc.startsWith('https://file.matripe.com') ){ that.globalData.hasAva = true }else{ that.globalData.hasAva = false } } if (that.userLoginCallback) { that.userLoginCallback(res); } if (that.globalData.autoLoginTag - 1 != 0) { wx.showToast({ title: "登录成功", icon: "success", duration: 2000, }); } }, fail: function (res) { console.log(res); } }); }, logout: function () { var that = this; return new Promise(function (reslove, reject) { try { wx.removeStorageSync("loginUserTokenInfo"); that.globalData.autoLoginTag = 0; that.globalData.sessionId = ""; that.globalData.header.Cookie = ""; that.globalData.header2.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: "#027AFF", 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); }, getUserInfoBtn: function(_that) { let that = this; wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) //发起网络请求 wx.request({ url: that.globalData.ip + '/updateUserWechatInfo', data: { nickName: res.userInfo.nickName, avatarUrl: res.userInfo.avatarUrl, gender: res.userInfo.gender, country: res.userInfo.country, province: res.userInfo.province, city: res.userInfo.city, }, method: "POST", header: that.globalData.header, success: function(res) { console.log(res); that.globalData.hasUserInfo = 1; that.globalData.user.imgSrc = res.data.data; that.globalData.hasAva = true _that.setData({ hasUserInfo: 1, topTips:false, user:that.globalData.user }) // that.goMyinfo(); }, fail: function(res) { } }) }, fail: (res) => { console.log(res) } }) }, load: function (text) { wx.showLoading({ title: text, mask: true, }); }, hideLoad: function () { wx.hideLoading(); }, isEmptyCheck: function (str) { if (str == null || str === "" || str == "null" || str == "undefined" || typeof str == "undefined"|| str == "-") { return true; } return false; }, isNotEmptyCheck: function (str) { return !this.isEmptyCheck(str); }, showTips: function (_that, msg) { _that.setData({ popErrorMsg: msg, pop: 1, }); setTimeout(() => { _that.setData({ popErrorMsg: "", pop: 0, }); return; }, 1500); }, });