app.js
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import Vue from 'vue';
import {get} from 'lodash';
import App from './app.vue';
import {createRouter} from './router';
import {createStore} from './store';
import 'filters';
import 'directives';
import titleMixin from './mixins/title';
import pluginCore from './plugins/core';
import lazyload from 'vue-lazyload';
import reportError from 'report-error';
import ReportApp from './common/report-app';
Vue.use(lazyload, {
preLoad: 2
});
Vue.use(pluginCore);
Vue.mixin(titleMixin);
export function createApp(context) {
const router = createRouter();
const store = createStore(context);
const reportApp = new ReportApp(store.$context.env);
const app = new Vue({
router,
store,
errorCaptured(error) {
reportError(context, 'server')(error);
return false;
},
methods: {
getAnalyticAppData() {
return new Promise(resolve => {
if (this._updated) {
return resolve();
}
this.$yoho.getAnalyticAppData('', data => {
this._updated = true;
reportApp.updateDeviceInfo(data);
resolve();
});
setTimeout(function() {
resolve();
}, 500);
});
},
async reportApp(type, pn, params = {}, pt) {
let user = await this.$sdk.getUser();
await this.getAnalyticAppData();
if (!params.mst) {
params.mst = get(this.$router, 'history.current.name', '');
}
reportApp.report(type, pt || 'BUSINESS', pn, params, get(user, 'uid'));
},
reportAppStart() {
this.reportApp('', 'BUSINESS_PLAN_A_ENTER', {locfun: 'mounted'});
}
},
render: h => h(App)
});
return {app, router, store};
}