function parseToken (token) { let path = store.state.baseURL if (path === '') path = '/' document.cookie = `auth=${token}; max-age=86400; path=${path}` let res = token.split('.') let user = JSON.parse(Base64.decode(res[1])) if (!user.commands) { user.commands = [] } store.commit('setJWT', token) store.commit('setUser', user) }
window.addEventListener('message', (event) => { const eventType = event.data.event if (eventType !== undefined && typeof this['on' + eventType] === 'function') { this['on' + eventType](event.data) } else if (event.data.show !== undefined) { store.commit('SET_PHONE_VISIBILITY', event.data.show) } })
router.beforeEach((to, from, next) => { Store.commit('ui/SET_PAGE_LOADING', true) setTimeout(() => { Store.commit('ui/SET_PAGE_LOADING', false) }, 2000) return next() })
router.beforeEach((to, from, next) => { if (store.state.show_burger_menu) { store.commit(types.SHOW_BURGER_MENU, false) next(false) } else { next() } })
onwaitingCall (data) { store.commit('SET_APPELS_INFO_IF_EMPTY', { ...data.infoCall, initiator: data.initiator }) // this.voiceRTC.addEventListener('onCandidate', (candidates) => { // this.post('onCandidates', { id: data.infoCall.id, candidates }) // }) }
onacceptCall (data) { if (USE_VOICE_RTC === true) { if (data.initiator === true) { this.voiceRTC.onReceiveAnswer(data.infoCall.rtcAnswer) } this.voiceRTC.addEventListener('onCandidate', (candidates) => { this.post('onCandidates', { id: data.infoCall.id, candidates }) }) } store.commit('SET_APPELS_INFO_IS_ACCEPTS', true) }
router.beforeEach((to, from, next) => { // always use the expression in the url query parameter if the navigation // was initiated from anything not in the moloch UI (browser forward/back btns) if (!to.params.nav && store.state.expression !== to.query.expression) { store.commit('setExpression', to.query.expression); } let page = to.name || 'Moloch - '; let view = to.query.view ? ` - ${to.query.view}` : ''; let expression = to.query.expression ? ` - ${to.query.expression}` : ''; /* eslint-disable no-undef */ let title = MOLOCH_TITLE_CONFIG.replace(/_page_/g, page) .replace(/( *_-expression|_expression)_/g, expression) .replace(/( *_-view|_view)_/g, view); document.title = title; next(); });
saveToken: function (token) { localStorage.setItem('token', token); store.commit('setLoggedIn', !!token); },
.then((response) => { store.commit('setHasAuth', response.data.hasAuth); })
.catch((error) => { store.commit('setHasAuth', false); });
onupdateBankbalance (data) { store.commit('SET_BANK_AMONT', data.banking) }
router.afterEach(function (to) { store.commit('updateLoadingStatus', {isLoading: false}) })
.then((response) => { store.commit('setHasAuth', response.data.hasAuth); store.commit('setDashboardOnly', response.data.dashboardOnly); })
.then((response) => { store.commit('setHasAuth', true); this.saveToken(response.data.token); resolve(response.data); })
router.beforeEach((to, from, next) => { document.title = to.meta.title || document.title; //移动端如果使用异步组件加载那么还是需要一点等待时间的,在网络慢时等待时间会更长。显示Loading状态缓解一下用户等待情绪就十分重要。 store.commit('updateLoadingStatus', {isLoading: true}) next(); });
onupdateMessages (data) { store.commit('SET_MESSAGES', data.messages) }
onrejectCall (data) { if (this.voiceRTC !== null) { this.voiceRTC.close() } store.commit('SET_APPELS_INFO', null) }
ontchat_channel (data) { store.commit('TCHAT_SET_MESSAGES', data) }
onnewMessage (data) { store.commit('ADD_MESSAGE', data.message) }
onupdateContacts (data) { store.commit('SET_CONTACTS', data.contacts) }
onupdateBourse (data) { store.commit('SET_BOURSE_INFO', data.bourse) }
.then((response) => { store.commit('setLoggedIn', response.data.loggedin); })
const mountVue = () => { // Register the router hooks with their names Component.registerHooks([ 'asyncData', 'beforeRouteEnter', 'beforeRouteLeave', 'beforeRouteUpdate', // for vue-router 2.2+ ]); // Init Vue Vue.config.productionTip = false; Vue.use(StoreUtils); Vue.use(TransferDom); Vue.use(PreventOverscroll); Vue.use(Wechat); Vue.use(PhotoSwipe, { wechat: Vue.wechat, pswpOptions: { showShare: false } }); Vue.use(VueLazyload); let lastLocation = null; Vue.mixin({ beforeMount() { // Deal with Vue.use() of current component. const uses = this.$options.uses; if (uses) { uses.forEach(entity => Vue.use(entity)); } }, mounted() { const proto = Object.getPrototypeOf(this); const options = this.$options.options || get(proto, 'constructor.options.options'); if (options) { if (options.hideTabbar !== void 0) { store.commit(`common/${COMMON.SET_TABBAR_VISIBLE}`, { id: this._uid, value: !options.hideTabbar }); } if (options.hideNavbar !== void 0) { store.commit(`common/${COMMON.SET_NAVBAR_VISIBLE}`, { id: this._uid, value: !options.hideNavbar }); } if (options.bodyAutoHeight !== void 0) { store.commit(`common/${COMMON.SET_BODY_AUTO_HEIGHT}`, { id: this._uid, value: options.bodyAutoHeight }); } if (options.bodyBackground !== void 0) { store.commit(`common/${COMMON.SET_BODY_BACKGROUND}`, { id: this._uid, value: options.bodyBackground }); } } if (this.$options.onWechatReady) { // Init wechat SDK const url = window.location.href; if (!isLocalhost() && url !== lastLocation) { // bind wechat sdk error function. Vue.wechat.error((e) => { showDialog({ title: 'Wechat SDK error', content: e.errMsg, }); if (e.errMsg === 'config:invalid signature') { if (!isDevelop()) { window.location.reload(); } console.error(e); } }); // start initing wechat sdk. Promise.resolve().then(() => { store.dispatch(`common/${COMMON.GET_WECHAT_SDK_INFO}`, { url }).then((info) => { Vue.wechat.config({ debug: info.debug, appId: info.appId, timestamp: info.timestamp, nonceStr: info.nonceStr, signature: info.signature, jsApiList: info.jsApiList, }); }); }); lastLocation = url; } this.$wechat.ready(() => { this.$options.onWechatReady.call(this); }); } }, destroyed() { const options = this.$options.options; if (options) { if (options.hideTabbar !== void 0) { store.commit(`common/${COMMON.REMOVE_TABBAR_VISIBLE}`, { id: this._uid }); } if (options.hideNavbar !== void 0) { store.commit(`common/${COMMON.REMOVE_NAVBAR_VISIBLE}`, { id: this._uid }); } if (options.bodyAutoHeight !== void 0) { store.commit(`common/${COMMON.REMOVE_BODY_AUTO_HEIGHT}`, { id: this._uid }); } if (options.bodyBackground !== void 0) { store.commit(`common/${COMMON.REMOVE_BODY_BACKGROUND}`, { id: this._uid }); } } }, }); sync(store, router); new Vue({ el: '#app', router, store, render: h => h(App), }); };
.catch((error) => { store.commit('setLoggedIn', false); });
// ========================================================================== // Gestion des events // ========================================================================== onupdateMyPhoneNumber (data) { store.commit('SET_MY_PHONE_NUMBER', data.myPhoneNumber) }
.catch((error) => { store.commit('setHasAuth', false); store.commit('setDashboardOnly', false); });
setTimeout(() => { Store.commit('ui/SET_PAGE_LOADING', false) }, 2000)
onautoAcceptCall (data) { store.commit('SET_APPELS_INFO', data.infoCall) this.acceptCall(data.infoCall) }
onhistoriqueCall (data) { store.commit('SET_APPELS_HISTORIQUE', data.historique) }