const req = require('../utils/request.js'); const h5util = require('../utils/h5util.js'); export default { data() { return { appId: '', token: '' }; }, async onLoad(options) { // 同步appId和AUTH_TOKEN this.appId = req.getStorage('appId'); this.token = req.getStorage('AUTH_TOKEN'); let updata = false if (options.token && this.token != options.token) { req.setStorage('AUTH_TOKEN', options.token); updata = true } if (options.appId && this.appId != options.appId) { req.setStorage('appId', options.appId); updata = true } this.getLoginState() await this.getwxConfig(); if (updata) window.location.reload(); h5util.postMsg({ type: 'function', //function 直接调用方法(此时eventName必传) msg 传递参数 eventName: 'setPageTitle', data: { title: document.title } }) }, onShow() { }, onHide() { }, onUnload() { }, methods: { // 获取登陆状态 async getLoginState(){ let isLogin = await req.isAuthFn(false) if(isLogin){ // 登陆了获取用户信息缓存 req.getRequest('/api/user/info', {}, data => { req.setStorage('userInfo', data); }); }else{ //未登录移除用户信息缓存 req.removeStorage('userInfo') } }, getwxConfig() { return new Promise((resolve, reject) => { req.getwxConfig(data => { resolve(); }); }); }, postShareMessage(title,imageUrl,path,sendBehaviorObj){ if(path.indexOf('/share/home/index')>-1){ }else{ path = '/pages/webView/webView?url=' + encodeURIComponent(window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + path) } h5util.postMsg({ type: 'function', //function 直接调用方法(此时eventName必传) msg 传递参数 eventName: 'setShareDate', data: { title: title?title:'', imageUrl: imageUrl?imageUrl:'', path: path?path:'', sendBehaviorObj:sendBehaviorObj } }) } } };