wap-app.js
1.49 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
import Vue from 'vue';
import iView from 'iview';
import cookie from 'vue-cookie';
import Router from 'vue-router';
import App from './pages/wap/app';
import store from 'yoho-store';
import WapRouters from './pages/wap';
import './filters';
import './directives';
import 'iview/dist/styles/iview.css';
import 'wap-common.scss';
import * as service from 'service.wap';
Vue.use(Router);
Vue.use(iView);
Vue.use(cookie);
Vue.$store = store;
Vue.prototype.$store = store;
let routerOpt;
if (typeof __PROD__ !== 'undefined') {
routerOpt = {
mode: 'history'
};
}
let routerExe = new Router(Object.assign({
routes: WapRouters,
scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 };
}
}, routerOpt));
let uname = cookie.get('u_');
let loginTypePromise = service.get(`rs/auth/getUserType?username=${uname}`);
routerExe.beforeEach((to, from, next) => {
if(cookie.get('u_') && to.name !== 'login' && to.name !== 'bind' && to.name !== 'offline-detail') {
const u = cookie.get('u_');
if (u !== uname) {
loginTypePromise = service.get(`rs/auth/getUserType?username=${u}`);
uname = u;
}
return loginTypePromise.then(result => {
if (result.data * 1 === 2) {
return next('/rs/offline_detail.html');
} else {
return next();
}
});
}
next();
});
new Vue({
el: '#app',
router: routerExe,
template: '<App/>',
components: {App}
});