Blame view

src/entry-client.js 2.25 KB
李奇 authored
1
import 'babel-polyfill';
陈峰 authored
2
import Vue from 'vue';
陈峰 authored
3
import {
陈峰 authored
4 5
    ROUTE_CHANGE,
    PAGE_INIT_VISIBLE,
陈峰 authored
6
    REPORT_YAS,
陈峰 authored
7
    YOHO_PAGE_VISIBLE,
陈峰 authored
8
} from 'store/yoho/types';
陈峰 authored
9
import FastClick from 'fastclick';
陈峰 authored
10
import {createApp} from './app';
陈峰 authored
11 12
import {createApi} from 'create-api';
import {createYoRouter} from 'common/router.js';
陈峰 authored
13
import yoho from '../public/js/yoho';
陈峰 authored
14
import message from 'components/message';
陈峰 authored
15
import 'statics/scss/common.scss';
陈峰 authored
16
import 'statics/scss/animation.scss';
陈峰 authored
17 18
import 'statics/font/iconfont.css';
import 'statics/scss/font.scss';
陈峰 authored
19
陈峰 authored
20 21
FastClick.attach(document.body);
陈峰 authored
22
const {app, router, store} = createApp();
陈峰 authored
23
陈峰 authored
24 25
window.newBlk = true;
陈峰 authored
26 27 28
if (window.__INITIAL_STATE__) {
    store.replaceState(window.__INITIAL_STATE__);
}
陈峰 authored
29
Vue.prop('yoho', yoho);
李奇 authored
30
Vue.prop('message', message);
陈峰 authored
31 32 33
Vue.prop('bus', new Vue());
Vue.prop('api', createApi());
Vue.prop('yoRouter', createYoRouter(router, store));
陈峰 authored
34
陈峰 authored
35 36 37 38 39 40

document.addEventListener('visibilitychange', function() {
    if (document.visibilityState === 'visible') {
        store.commit(PAGE_INIT_VISIBLE, {visible: false});
        setTimeout(() => {
            store.commit(PAGE_INIT_VISIBLE, {visible: true});
李奇 authored
41
        }, 500);
陈峰 authored
42 43
    }
});
陈峰 authored
44 45 46
window.blkPageSwtich = (visible) => {
    store.commit(YOHO_PAGE_VISIBLE, {visible});
};
陈峰 authored
47
陈峰 authored
48
router.onReady(() => {
陈峰 authored
49
    router.beforeResolve((to, from, next) => {
陈峰 authored
50 51 52
        const matched = router.getMatchedComponents(to);

        store.commit(ROUTE_CHANGE, to);
陈峰 authored
53
陈峰 authored
54 55 56
        if (window._hmt) {
            window._hmt.push(['_trackPageview', to.fullPath]);
        }
陈峰 authored
57 58 59 60 61 62 63 64 65 66
        store.dispatch(REPORT_YAS, {
            params: {
                appop: 'YB_H5_PAGE_OPEN_L',
                param: {
                    F_URL: `${location.origin}${to.fullPath}`,
                    PAGE_URL: `${location.origin}${from.fullPath}`,
                    PAGE_NAME: from.name
                }
            }
        });
陈峰 authored
67
陈峰 authored
68 69
        Promise.all(matched.map(({asyncData}) =>
            asyncData && asyncData({store, router: to})))
陈峰 authored
70
            .then(() => {
陈峰 authored
71
                if (!yoho.isAndroid || store.state.yoho.visible) {
陈峰 authored
72
                    return next();
陈峰 authored
73 74
                } else {
                    history.pushState({}, '', from.fullPath);
陈峰 authored
75 76
                }
            })
陈峰 authored
77 78
            .catch(next);
    });
陈峰 authored
79 80 81 82
    app.$mount('#app');
});