//app.js // import {Http} from "/utils/http-p.js" import { promisifyAll } from './utils/wx-promise-pro' import { Request } from './utils/http' import { updateManager } from './utils/appExtends' import {webSocket, socketReconnect} from './utils/websocket' let livePlayer = requirePlugin('live-player-plugin'); // promisify all wx‘s api promisifyAll(); App({ onLaunch: async function (options) { console.log('小程序onLaunch事件', options); this.isFirstOpenApp = true; var FromUserId = this.getFromUserId(options); this.globalData.FromOpenId = options.query.FromOpenId || ''; // this.globalData.ReferrerOpenId = options.query.ReferrerOpenId || ''; this.globalData.FromUserId = FromUserId || ''; this.globalData.tempFromUserId = this.globalData.FromUserId; console.log('FromOpenId是', this.globalData.FromOpenId); console.log('FromUserId是', this.globalData.FromUserId); console.log('ReferrerOpenId是', this.globalData.FromOpenId); var HttpHost = wx.getExtConfigSync().HttpHost; console.log('HttpHost',HttpHost); this.globalData.cartIndex = wx.getExtConfigSync().FooterNumPosition; HttpHost.indexOf('https://') > -1 ? HttpHost : (HttpHost = 'https://' + HttpHost); var WssHost = wx.getExtConfigSync().WssHost; WssHost.indexOf('wss://') > -1 ? WssHost : (WssHost = 'wss://' + WssHost); console.log('HttpHost',HttpHost); console.log('WssHost',WssHost); this.globalData.socketHost = WssHost; this.globalData.reqBase = HttpHost; // 版本管理 updateManager(this); wx.$http = new Request(this); // 获取状态栏高度 wx.getSystemInfo({ success: e => { //状态栏 let statusBarHeight= e.statusBarHeight; // 右上角胶囊 let menuButton = wx.getMenuButtonBoundingClientRect(); //胶囊宽度加上左右边距的新宽度【即自定义导航栏时,左边元素的margin-right的值】 menuButton.extendWidth=menuButton.width+2*(e.windowWidth-menuButton.right); menuButton.marginRight=e.windowWidth-menuButton.right;//胶囊的右边距。用于设置返回的左边距。对称 // 保存 this.globalData.statusBarHeight =statusBarHeight this.globalData.menuButton = menuButton; this.globalData.customNavBarHeight= menuButton.bottom + menuButton.top - statusBarHeight; console.log(statusBarHeight,menuButton,this.globalData.customNavBarHeight) // console.log('系统信息。。。。。',wx.getSystemInfo()) } }) //第一次登陆 this.getSessionID(); //获取sessionid并定时刷新 // if(this.globalData.openID==''){ // this.getSession(); // } // let abc = await this.wxLogin(); // console.log('wxLogin code.....',abc) // this.getSession().then((res)=>{ // console.log('this.globalData.FromOpenId.........',this.globalData.FromOpenId) // // this.saveReferrerReward(); // if (this.globalData.FromOpenId!=''&&this.globalData.FromOpenId!=this.globalData.openID){ // this.saveReferrerReward(); // } // return this.getSettings() // }) // await this.appOnLoad(); let login = await this.getSession(); console.log('this.globalData.FromOpenId.........',this.globalData.FromOpenId) // this.saveReferrerReward(); if (this.globalData.FromOpenId!=undefined&&this.globalData.FromOpenId!=''&&this.globalData.FromOpenId!=this.globalData.openID){ this.saveReferrerReward(); } this.appOnLoad(); this.refresh(); console.log('小程序初次打开onLaunch事件执行完毕'); }, appOnLoad(){ this.getSettings().then((res) => { console.log('res.data.isPullUserInfo......', res.data.isPullUserInfo); if(res.data.isPullUserInfo){ console.log(res); this.getUserInfo(res); } this.getFromUserIdForRequest().then((res) => { console.log('获取名片用户数据UserData完成'); this.globalData.getCardCallback(res); // 发送websocket this.websocketReconnect(); }); this.userInfoReadyCallback(res); this.getShareMsg(); //判断用户是否授权 获取用户信息 wx.getSetting({ success: res => { console.log('getSetting成功数据', res); if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 //this.globalData.isAuthorize = true; // console.log(res) // this.globalData.userInfo = res.authSetting['scope.userInfo'] wx.getUserInfo({ success: res => { console.log('用户信息是', res.userInfo); this.globalData.userInfo = res.userInfo; wx.setStorageSync("userInfo", res.userInfo); this.globalData.messageCallback(res); // 发送websocket // this.webSocket(); // this.listeningSocket() // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 // if (this.userInfoReadyCallback) { // this.userInfoReadyCallback(res); // } } }); } else { //this.globalData.isAuthorize = false; } } }); this.globalData.indexCallback(res); this.globalData.classifyCallback(res); this.globalData.idcardCallback(res); }); }, //第一次获取FromUserId,目的是小程序启动时FromUserId为空值时拿到后台传来的默认参数 getFromUserIdForRequest() { let utils = require('./utils/util'); return new Promise((resolve, reject) => { wx.request({ url: utils.getUrl('/wx/getCardUserInfo.do'), // url: this.globalData.reqBase + '/wx/getCardUserInfo.do', header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, // data: { // FromUserId: this.globalData.FromUserId, // AppId: this.globalData.AppId, // wx: 3 // }, success: res => { if(!utils.requestError(res)){ return false; } console.log('第一次getFromUserIdForRequest。。。', res.data); this.globalData.FromUserId = res.data.UserId || ''; // this.globalData.URID = res.data.URID || ''; // 第一次更新 this.globalData.tempFromUserId = res.data.UserId || ''; this.globalData.cardUserData = res.data; resolve(res); }, fail: function (errmsg) { console.log('/wx/getCardUserInfo.do', errmsg); utils.requestFail(errmsg, '/wx/getCardUserInfo.do'); reject(errmsg); } }); }); }, //获取设置数据 getSettings() { let utils = require('./utils/util'); return new Promise((resolve, reject) => { wx.request({ url: utils.getUrl( '/shopping/getSettingEntity.do'), // data: { // FromUserId: this.globalData.FromUserId, // AppId: this.globalData.AppId, // wx: 3 // }, header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, success: res => { if(!utils.requestError(res)){ return false; } console.log('设置数据获取完毕。。。',res) // console.log(777) this.globalData.generateOrderProcess = res.data.generateOrderProcess || 0; this.globalData.shoppingGroupName = res.data.shoppingGroupName || ''; this.globalData.RewardStatus = res.data.RewardStatus; this.globalData.CouponStatus = res.data.CouponStatus; this.globalData.VoucherStatus = res.data.VoucherStatus; this.globalData.isAllowRecharge = res.data.isAllowRecharge; this.globalData.isAllowWithdraw = res.data.isAllowWithdraw; this.globalData.isShowMatCode = res.data.isShowMatCode; this.globalData.isShowMatName = res.data.isShowMatName; this.globalData.isShowPrice = res.data.isShowPrice; this.globalData.isShowSpecial = res.data.isShowSpecial; this.globalData.isStartupLeagueShopCcCode = res.data.isStartupLeagueShopCcCode; this.globalData.cardStyle = res.data.cardStyle; this.globalData.aiMessageDefaultTemplateId = res.data.aiMessageDefaultTemplateId; this.globalData.couponsBuyReminderTemplateIdForMiniApp = res.data.couponsBuyReminderTemplateIdForMiniApp; this.globalData.orderNoticeTemplateIdList = res.data.orderNoticeTemplateIdList[120230]; this.globalData.shopName = res.data.name || ''; this.globalData.logoUrl = res.data.logoUrl || ''; this.globalData.isShowPoster = res.data.isShowPoster || ''; this.globalData.parallelNumberForInnerMenuOnHomePage = res.data.parallelNumberForInnerMenuOnHomePage || 4; this.globalData.ProductListStyle = res.data.productListStyle || 0; this.globalData.isShowPostcode = res.data.isShowPostcode || 0; this.globalData.categoryListStyle = res.data.categoryListStyle||0; this.globalData.withdrawType = res.data.withdrawType; this.globalData.isAllowSelectDeliveryMethod = res.data.isAllowSelectDeliveryMethod||false; this.globalData.deliveryMethod = res.data.deliveryMethod||''; this.globalData.isShowBannerPhotoOnHomePageForLiveUser = res.data.isShowBannerPhotoOnHomePageForLiveUser||false; resolve(res); }, fail: function(errmsg) { utils.requestFail(errmsg, '/shopping/getSettingEntity.do'); reject(errmsg); } }) }); }, saveReferrerReward(){ let utils = require('./utils/util'); wx.request({ url: utils.getUrl('/shopping/pay/saveReferrerReward.do'), data: { FromOpenId: this.globalData.FromOpenId, // FromUserId: this.globalData.FromUserId, // AppId: this.globalData.AppId, // wx: 3 }, header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, success: res => { if(!utils.requestError(res)){ return false; } }, fail: function(errmsg) { utils.requestFail(errmsg,'/shopping/pay/saveReferrerReward'); } }) }, async wxLogin(){ return new Promise((resolve,reject)=>{ wx.login({ success: (res) => { resolve(res) }, fail:(err)=>{ reject(err) } }) }) }, //获取session async getSession() { var that = this; // var utils = require('./utils/util') let doLogin = (res)=>{ return new Promise((resolve,reject)=>{ wx.request({ url: that.globalData.reqBase + '/wx/miniapp/user/login.do', header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, data: { FromUserId: that.globalData.FromUserId, code: res.code, AppId: that.globalData.AppId, wx: 3 }, success: function (res) { if (res.data['error'] && res.data['error']['warning']) { wx.showModal({ title: '提示', content: res.data['error']['warning'], showCancel: false }); return false; } let data = res.data; console.log('login.do获取到数据', res); wx.setStorageSync('shopName', res.data.shopccname); wx.setStorageSync("sessionID", data.JSESSIONID); // wx.setStorageSync("openID", data.OpenId || ''); //o6Df10LmkJZnWPFY3jiLrVY_3mb8 that.globalData.openID = data.OpenId || ''; if (res.data && res.data.UserId){ that.globalData.FromUserId = res.data.UserId; } else { that.globalData.FromUserId = ''; } that.globalData.SessionKey = res.data.SessionKey || ''; that.globalData.isShopGuide = res.data.isShopGuide || false; that.globalData.ReferralsName = res.data.ReferralsName || ''; that.globalData.UserName = res.data.UserName; that.globalData.avatarUrl = res.data.avatarUrl; that.globalData.nickName = res.data.nickName; that.globalData.tabBarList = res.data.tabBarList; // that.globalData.shopccname = res.data.shopccname; console.log('that.globalData.isShopGuide',that.globalData.isShopGuide) resolve(res); }, fail: function (errmsg) { console.log('/wx/miniapp/user/login.do', errmsg); wx.showModal({ title: '/wx/miniapp/user/login.do', content: errmsg.errMsg, showCancel: false }); reject(errmsg); } }); }) } let wxLoginRes = await this.wxLogin(); let doLoginRes = await doLogin(wxLoginRes); return doLoginRes; // return this.wxLogin().then((res)=>{ // return doLogin(res); // }) return new Promise(function (resolve, reject) { wx.login({ success: res => { if (res.code) { console.log('code.....', res); //发起网络请求 wx.request({ url: that.globalData.reqBase + '/wx/miniapp/user/login.do', header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, data: { FromUserId: that.globalData.FromUserId, code: res.code, AppId: that.globalData.AppId, wx: 3 }, success: function (res) { if (res.data['error'] && res.data['error']['warning']) { wx.showModal({ title: '提示', content: res.data['error']['warning'], showCancel: false }); return false; } let data = res.data; console.log('login.do获取到数据', res); wx.setStorageSync('shopName', res.data.shopccname); wx.setStorageSync("sessionID", data.JSESSIONID); wx.setStorageSync("openID", data.OpenId || ''); //o6Df10LmkJZnWPFY3jiLrVY_3mb8 that.globalData.openID = data.OpenId || ''; if (res.data && res.data.UserId){ that.globalData.FromUserId = res.data.UserId; } else { that.globalData.FromUserId = ''; } that.globalData.SessionKey = res.data.SessionKey || ''; that.globalData.isShopGuide = res.data.isShopGuide || false; that.globalData.ReferralsName = res.data.ReferralsName || ''; that.globalData.UserName = res.data.UserName; that.globalData.nickName = res.data.nickName; that.globalData.tabBarList = res.data.tabBarList; // that.globalData.shopccname = res.data.shopccname; console.log('that.globalData.isShopGuide',that.globalData.isShopGuide) resolve(res); }, fail: function (errmsg) { console.log('/wx/miniapp/user/login.do', errmsg); wx.showModal({ title: '/wx/miniapp/user/login.do', content: errmsg.errMsg, showCancel: false }); } }); } else { console.log('登录失败!' + res.errMsg); reject('error'); } } }); }); }, // 每20分钟刷新sessionid refresh: function () { setInterval(() => { this.getSession(); }, 20 * 60 * 1000); }, // 第一次登录 getSessionID: function () { // let utils = require('./utils/util') wx.request({ url: this.globalData.reqBase + '/wx/miniapp/user/getSessionId.do', header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, data: { AppId: this.globalData.AppId, wx: 3 }, success: res => { if (res.data['error'] && res.data['error']['warning']) { wx.showModal({ title: '提示', content: res.data['error']['warning'], showCancel: false }); return false; } let data = res.data; console.log('第一次登录sessionID', res); wx.setStorageSync("sessionID", data.JSESSIONID); }, fail: function (errmsg) { console.log('/wx/miniapp/user/getSessionId.do', errmsg); wx.showModal({ title: '/wx/miniapp/user/getSessionId.do', content: errmsg.errMsg, showCancel: false }); } }); }, getShareMsg(){ wx.request({ url: this.globalData.reqBase + '/shopping/share.do?m=getShareHitMessageForMiniApp', header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, data: { AppId: this.globalData.AppId, wx: 3 }, success: res => { if (res.data['error'] && res.data['error']['warning']) { wx.showModal({ title: '提示', content: res.data['error']['warning'], showCancel: false }); return false; } console.log('分享标题。。。', res.data); this.globalData.shareTitles = res.data.List; }, fail: function (errmsg) { console.log('/wx/miniapp/user/getSessionId.do', errmsg); wx.showModal({ title: '/wx/miniapp/user/getSessionId.do', content: errmsg.errMsg, showCancel: false }); } }); }, // 用户信息获取之后 userInfoReadyCallback: function (res) { wx.request({ url: this.globalData.reqBase + '/shopping/account.do?m=accountInfo', header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, data: { FromUserId: this.globalData.FromUserId, AppId: this.globalData.AppId, wx: 3 }, success: res => { if (res.data['error'] && res.data['error']['warning']) { wx.showModal({ title: '提示', content: res.data['error']['warning'], showCancel: false }); return false; } // console.log('cltcode', res.data.UserInfo.CltCode); console.log('// 用户信息获取之后'); this.globalData.Cltcode = res.data.UserInfo.CltCode }, fail: function (errmsg) { console.log('/shopping/account.do', errmsg); wx.showModal({ title: '/shopping/account.do', content: errmsg.errMsg, showCancel: false }); } }); // Request.request() // wx.request({ // url: utils.getUrl('/shopping/account.do?m=accountInfo'), // header: { // "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') // }, // success: res => { // // utils.requestError(res); // if(res.data['error']){ // if(res.data['error']['warning']){ // this.showModal(res.data['error']['warning'],'提示',false); // }else{ // for (let key in res.data['error']) { // this.showModal(res.data['error'][key],'提示',false); // } // } // } // // console.log(res) // this.setData({ // userData: res.data.UserInfo // }) // // }, }, // getUserInfo(res){ // 必须是在用户已经授权的情况下调用 wx.getUserInfo({ success: res => { console.log('getUserInfo',res); // 把用户信息发送到后台 wx.request({ url: this.globalData.reqBase + '/wx/miniapp/user/info.do', header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, data: { FromUserId: this.globalData.FromUserId, AppId: this.globalData.AppId, wx: 3, signature: res.signature, rawData: res.rawData, encryptedData: res.encryptedData, iv: res.iv, SessionKey: this.globalData.SessionKey }, success: (res) => { if (res.data['error'] && res.data['error']['warning']) { wx.showModal({ title: '提示', content: res.data['error']['warning'], showCancel: false }); return false; } }, fail: function (errmsg) { this.requestFail(errmsg, '/wx/miniapp/user/info.do'); } }) } }) }, // 解析启动时的url getUrlkey(url) { var params = {}; // var arr = url.split("="); console.log('3_遍历 arr 并分割后赋值给a:', arr) var arr = url.split("&"); for (var i = 0, l = arr.length; i < l; i++) { var a = arr[i].split("="); params[a[0]] = a[1]; } console.log('scene处理后的结果:', params); return params; }, webSocket: function(){ webSocket(this); }, socketReconnect:function(){ socketReconnect(this) }, // 获取scene内的参数 getFromUserId(options) { let FromUserId; // 从url直接取值 // if ((!FromUserId || FromUserId == '') && options.scene) { // FromUserId = this.getUrlkey(decodeURIComponent(options.scene))['FromUserId']; // } // 从小程序码进入 if (options.scene == 1047||options.scene == 1048||options.scene == 1049) { let params = this.getUrlkey(decodeURIComponent(options.query.scene)); FromUserId = params.FromUserId || options.query.FromUserId; let roomid = params.roomid || options.query.roomid; console.log('扫码进入小程序, 地址上的FromUserId为',FromUserId ); if (roomid) { console.log('扫码进入小程序直播间, 地址上的roomid为',roomid,',FromUserId为',FromUserId ); let customParams = encodeURIComponent(JSON.stringify({ FromUserId: FromUserId })) console.log(`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomid}&custom_params=${customParams}`) wx.reLaunch({ url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomid}&custom_params=${customParams}` }) } // // 直播二维码 // if(options.path.includes('/pages/live-player-plugin')){ // FromUserId = JSON.parse(decodeURIComponent(options.query.custom_params)).FromUserId; // // let URID = JSON.parse(decodeURIComponent(options.query.custom_params)).RowId; // // console.log('扫码进入小程序直播间, 地址上的URID为',URID ); // // await this.getFromUserIdForRequest(); // // FromUserId = this.globalData.FromUserId; // // if (URID!=this.globalData.URID) { // // this.globalData.URID = URID; // // this.getFromUserIdForRequest().then(()=>{ // // this.websocketReconnect(); // // this.getSession(); // // this.getSettings(); // // }); // // } // console.log('扫码进入小程序直播间, 地址上的FromUserId为',FromUserId ); // } // // 普通二维码 // else{ // } } if(!FromUserId){ FromUserId = options.query.FromUserId; } return FromUserId; }, // 获取scene内的参数 getPathUrl(options) { let pathUrl; // 通过扫码进入 if (options.scene == 1047||options.scene == 1048||options.scene == 1049) { // 直播二维码 if(options.path.includes('/pages/live-player-plugin')){ pathUrl = `${options.path}?`; for (const key in options.query) { if (options.query.hasOwnProperty(key)) { const element = options.query[key]; pathUrl+=`${key}=${element}&` } } console.log('扫码进入小程序直播间, 二维码地址为', pathUrl); } // 普通二维码 else{ pathUrl = `/${options.path}?${decodeURIComponent(options.query.scene)}`; } } if (!pathUrl) { pathUrl = `/${options.path}?`; for (const key in options.query) { if (options.query.hasOwnProperty(key)) { const element = options.query[key]; pathUrl+=`${key}=${element}&` } } } return pathUrl; }, // 小程序显示时 async onShow(options) { // wx.redirectTo({ // url:'/pages/index/index', // }) console.log('发生了小程序app onShow事件', options); if (!this.isFirstOpenApp) { this.getSession(); console.log('小程序非初次加载进入onShow,重新login一次'); // return; } // let pathUrl = this.getPathUrl(options); // 分享卡片入口进入小程序 // 直播间 if((options.scene == 1007 || options.scene == 1008 || options.scene == 1044)&&options.path.includes('/pages/live-player-plugin')){ console.log('通过直播分享卡片进入小程序', options); livePlayer.getShareParams() .then((res)=>{ console.log('获取直播 room id', res.room_id); // 房间号 console.log('获取直播 openid', res.openid); // 用户openid console.log('获取直播 share openid', res.share_openid); // 分享者openid,分享卡片进入场景才有 console.log('获取 custom params', res.custom_params); // 开发者在跳转进入直播间页面时,页面路径上携带的自定义参数,这里传回给开发者 let FromUserId = res.custom_params.FromUserId || ''; this.handleFromUserIdChange(FromUserId); }).catch(err => { console.log('获取直播 share params', err) }) } // 不是初次打开 else if(!this.isFirstOpenApp){ let FromUserId = this.getFromUserId(options); this.handleFromUserIdChange(FromUserId); } }, handleFromUserIdChange(FromUserId){ console.log('原来的this.globalData.FromUserId.........',this.globalData.FromUserId) console.log('链接中的FromUserId.......', FromUserId) this.globalData.tempFromUserId = FromUserId || this.globalData.tempFromUserId; // this.globalData.FromUserId = FromUserId; console.log('切前台事件后tempFromUserId值为', this.globalData.tempFromUserId); if((this.globalData.FromUserId!=''&&this.globalData.FromUserId!=undefined)&&(FromUserId!=''&&FromUserId!=undefined)&&this.globalData.FromUserId != FromUserId){ this.globalData.openID = ''; this.globalData.FromUserId = this.globalData.tempFromUserId; console.log('小程序app onshow 事件发生时 两个FromUserId不相等', this.globalData.FromUserId); this.getSession().then(()=>{ // this.websocketReconnect(); // this.getFromUserIdForRequest(); // this.getSettings(); this.appOnLoad(); }); } }, // } // // 通过二维码进入小程序 // else if (options.scene == 1017||options.scene == 1047||options.scene == 1048||options.scene == 1049) { // // 直播二维码 // if(options.path.includes('/pages/live-player-plugin')){ // let url = `${options.path}?`; // // if(!url.includes('plugin-private://wx2b03c6e691cd7370')){ // // url = `plugin-private://wx2b03c6e691cd7370${options.path}?`; // // } // for (const key in options.query) { // if (options.query.hasOwnProperty(key)) { // const element = options.query[key]; // url+=`${key}=${element}&` // } // } // this.globalData.FromUserId = FromUserId; // this.handleFromUserId(FromUserId); // wx.redirectTo({ // url:url, // }) // } // // 普通二维码 // else{ // let url = `/${options.path}?${decodeURIComponent(options.query.scene)}`; // this.handleFromUserId(this.getFromUserId(options)); // console.log('扫码进入小程序, 二维码地址为', url); // if (this.isTabbar(options.path)) { // wx.switchTab({ // url:`/${options.path}`, // }) // } else{ // wx.redirectTo({ // url, // }) // } // } // } // else{ // this.handleFromUserId(this.getFromUserId(options)); // } // // var FromUserId = this.getScene(options); // var OpenFrom = options.query.OpenFrom; //decodeURIComponent(options.query.OpenFrom); // console.log(OpenFrom); // if (OpenFrom == 'TemplateMsg' || OpenFrom == 'fromShare') { // this.globalData.isRedirectTo = true; // } // }, websocketReconnect(){ // // 扫码时小程序会重启 重启会使用启动时拿到的FromOpenId // // 在从分享连接打开时,小程序不会重启 // this.globalData.tempFromUserId = FromUserId || this.globalData.tempFromUserId; // // this.globalData.FromUserId = options.query.FromUserId || this.globalData.FromUserId; // console.log('切前台事件后tempFromUserId值为', this.globalData.tempFromUserId); // console.log('切前台事件后FromUserId值为', this.globalData.FromUserId); // // 判断临时变量tempFromUserId与原FromUserId是否相等 // // 不相等说明用户切换了客服,需要重获名片数据并重连websocket,相等则不处理 // // tempFromUserId最初与FromUserId相等,会在选择名片夹时与切后台后显示时更新 // if (this.globalData.tempFromUserId !== this.globalData.FromUserId) { // this.globalData.FromUserId = this.globalData.tempFromUserId; // this.globalData.SocketTask.close({ // success: (res) => { // console.log('主动关闭 WebSocket 连接。', res); // } // }); // // 把上个联系人的消息清空并重连 // this.globalData.allContentList = []; // this.globalData.unreadMsgNum = 0; // this.socketReconnect(); // } if (this.globalData.SocketTask) { this.globalData.SocketTask.close({ success: (res) => { console.log('主动关闭 WebSocket 连接。', res); } }); // 把上个联系人的消息清空并重连 this.globalData.allContentList = []; this.globalData.unreadMsgNum = 0; this.socketReconnect(); } else { this.webSocket(); } }, isTabbar(url){ console.log('url......',url) console.log('tabBarList......',this.globalData.tabBarList) if (this.globalData.tabBarList instanceof Array) { // return this.globalData.tabBarList.forEach((item,index)=>{ // console.log(item); // console.log('tabBarList是否包含参数url',item.includes(url)); // if(item.includes(url)){ // return true; // } // }) for (let i = 0; i < this.globalData.tabBarList.length; i++) { const item = this.globalData.tabBarList[i]; if(item.includes(url)){ return true; } } } return false; }, globalData: { URID:'', ReferrerOpenId: '', SessionKey: '', titleName: '', categoryListStyle: 0, isAuthorize: false, //是否授权 userInfo: {}, openID: '', // ||'o6Df10LmkJZnWPFY3jiLrVY_3mb8', //用户openid,固定不变 //wx.getStorageSync("openID") FromOpenId: '', //'', //wx.getStorageSync('FromOpenId'), //'' || 'o6Df10LmkJZnWPFY3jiLrVY_3mb8', FromUserId: '', // nickName: '', Cltcode: '', // 用户是否用手机号登录 cardUserData: {}, //名片信息 tempFromUserId: '', //存储临时FromUserId,最初与FromUserId相等,会在选择名片时与切后台后显示时更新 AppId: wx.getExtConfigSync().AppId, TengXunMapLocationServiceKey: wx.getExtConfigSync().TengXunMapLocationServiceKey, cartNum: 0, //购物车商品数 cartIndex: 2, //购物车页面在tabbar的index值 reqBase: '', //"https://mp.onbus.cn", // socketMethod: "wss://", socketHost: '', //"wss://mp.onbus.cn", SocketTask: '', //websocket任务 socketOpen: false, //是否已连接 allContentList: [], //所有消息 errorList: [], //错误消息 dbid: 0, //数据源 groupId: '', // newMsg: '', //最新消息 msgCallback: function () { }, //()=> {} //接收消息后处理消息的回调函数 newMsgCallback: function () { }, //()=> {} //接收最新消息后处理消息的回调函数 //errorMsgCallback: function() { }, //()=> {} //接收错误消息后处理消息的回调函数 unreadMsgNum: 0, //未读消息数量 indexCallback: function () { }, //()=> {} //login.do成功后的回调函数,在首页调用 classifyCallback: function () { }, //()=> {} //login.do成功后的回调函数,在分类页调用 idcardCallback: function () { }, //()=> {} //login.do成功后的回调函数,在名片页调用 messageCallback: function () { }, //()=> {} //login.do成功后的回调函数,在消息页调用 getCardCallback: function () { }, //()=> {} //login.do成功后的回调函数,在名片页调用 isReconnect: false, //websocket是否重连过 isRedirectTo: false, //是否有重定向 normalSearchKey: '', ChooseFloorId: '', //自定义导航相关的 statusBarHeight:0,//状态栏高度 menuButton:{},//胶囊相关数据 @obj,{width,height,top,left,right,bottom} customNavBarHeight:0,//自定义导航栏的高度【导航栏包括了状态栏】 }, // 页面onshow时FromUserId改变 // fromUserIdOnChange(callback){ // if((this.globalData.FromUserId!=''&&this.globalData.FromUserId!=undefined)&&(this.globalData.tempFromUserId!=''&&this.globalData.tempFromUserId!=undefined)&&this.globalData.FromUserId !== this.globalData.tempFromUserId){ // this.globalData.FromUserId = this.globalData.tempFromUserId; // console.log('两个FromUserId不相等,页面onshow事件发生', this.globalData.FromUserId); // if(this.globalData.isStartupLeagueShopCcCode){ // typeof callback === 'function'&& callback(); // } // } // }, // unionFromUserIdChangeOnShow(){ // }, // onShow : function(){ // var num = wx.getStorageSync("cartNum"); // wx.setTabBarBadge({ // index: 2, // text: num.toString() // }) // } onHide () { // Do something when hide. // wx.reLaunch({ // url: '/pages/logs/logs', // }) this.isFirstOpenApp = false; }, });