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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import Vue from 'vue'
import store from "@/store"
import common from '../util/common'
import Router from 'vue-router'
import sa from'sa-sdk-javascript';
import {getUserDetailApi} from "../service/api";
Vue.use(Router);
let browser = {
versions: function () {
let u = navigator.userAgent, app = navigator.appVersion;
return { //移动终端浏览器版本信息
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') === -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
};
let ua = window.navigator.userAgent.toLowerCase();
const router =new Router({
routes: [
{
path: '/',
name: 'index',
component: e=>require(['@/components/index'],e),//
meta:{
deep:0,
title:'唱唱启蒙'
}
}, {
path: '/exChange',
name: 'exChange',
component: e=>require(['@/components/exChange'],e),//
meta:{
deep:0,
noNew:true,
}
}, {
path: '/newLesson',
name: 'newLesson',
component: e=>require(['@/components/newLesson'],e),//
meta:{
deep:0
}
}, {
path: '/star',
name: 'star',
component: e=>require(['@/components/star'],e),//
meta:{
deep:0,
noNew:true,
}
},
{
path: '/shareGoods',
name: 'shareGoods',
component: e=>require(['@/components/newLesson/shareGoods'],e),//
meta:{
deep:0,
noNew:true
}
},{
path: '/myGoodsList',
name: 'myGoodsList',
component: e=>require(['@/components/myGoodsList'],e),
meta:{
deep:1
}
},{
path: '/mine',
name: 'mine',
component: e=>require(['@/components/mine'],e),
meta:{
deep:1
}
},{
path: '/order',
name: 'order',
component: e=>require(['@/components/order'],e),
meta:{
deep:2
}
},{
path: '/share',
name: 'share',
component: e=>require(['@/components/share'],e),
meta:{
deep:2
}
},
{
path: '/author',
name: 'author',
component: e=>require(['@/components/author'],e),
meta:{
deep:100,
noNew:true
}
},{
path: '/buyDetail',
name: 'buyDetail',
component: e=>require(['@/components/buy/index'],e),
meta:{
skip_login:false,
noNew:true,
deep:10
}
}, {
path: '/buy',
name: 'buy',
component: e=>require(['@/components/buy/buy'],e),
meta:{
noNew:true,
deep:11
}
}, {
path: '/success',
name: 'success',
component: e=>require(['@/components/buy/success'],e),
meta:{
noNew:true,
deep:12
}
},{
path: '/buySuccess',
name: 'buySuccess',
component: e=>require(['@/components/buy/buySuccess'],e),
meta:{
noNew:true,
deep:12
}
}, {
path: '/map',
name: 'map',
component: e=>require(['@/components/map/index'],e),
meta:{
deep:3
}
},
{
path: '/saleSuccess',
name: 'saleSuccess',
component: e=>require(['@/components/buy/saleSuccess'],e),
meta:{
deep:4
}
}, {
path: '/bindMobile',
name: 'bindMobile',
component: e=>require(['@/components/bindMobile'],e),
meta:{
deep:0
}
},
{
path: '/activity',
name: 'activity',
component: e=>require(['@/components/buy/activity'],e),
meta:{
skip_login:true,
noNew:true,
}
},
{
path: '/activityInvite',
name: 'activityInvite',
component: e=>require(['@/components/buy/activityInvite'],e),
meta:{
skip_login:true,
noNew:true,
}
},
{
path: '/inviteList',
name: 'inviteList',
component: e=>require(['@/components/buy/inviteList'],e),
meta:{
skip_login:true,
noNew:true,
}
},
{
path: '/collection',
name: 'collection',
component: e=>require(['@/components/collection'],e),
meta:{
skip_login:true
}
},
{
path: '/noWechat',
name: 'noWechat',
component: e=>require(['@/components/noWechat'],e),
meta:{
skip_login:false
}
},
{
path: '/mpShop',
name: 'mpShop',
component: e=>require(['@/components/buy/mpShop'],e),
meta:{
skip_login:false,
noNew:true,
}
},
{
path:'*',
component: e=>require(['@/components/error'],e),
},
]
});
router.beforeEach((to,from,next)=> {
// 神策路由埋点
Vue.nextTick(() => {
sa.quick("autoTrackSinglePage");
});
// 判断是否是微信环境 排除本地
if(ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_'){
if(to.name == 'noWechat'){
if(to.query.url){
next(decodeURIComponent(to.query.url))
}else{
next({name:'index'});
}
}
}else{
if(to.name !== 'noWechat' && process.env.NODE_ENV === 'production') {
next({name:'noWechat',query:{url:encodeURIComponent(to.fullPath)}});
}
}
// 移动端判断
store.dispatch('isMobile',browser.versions.mobile);
// 默认title
document.title = '唱唱启蒙英语';
let goOn=function(){
if(localStorage.getItem('retUrl') && localStorage.getItem('retUrl') !== null && localStorage.getItem('retUrl') !== ''){
let retUrl = localStorage.getItem('retUrl').toString();
localStorage.removeItem('retUrl');
next(retUrl);
}else{
next()
}
};
if(to.name === 'author' || to.name === 'bindMobile' || to.name === 'noWechat'){
next()
}else if(window.location.href.indexOf('token')>-1 && to.name === 'index'){
let token = common.getUrlParam().token || to.query.token;
store.dispatch('setToken',token);
getUserDetailApi().then(res=>{
localStorage.setItem('userDesc',JSON.stringify(res));
sa.login(res.user_id);
goOn()
}).catch(()=>{
if(localStorage.getItem('userDesc')){
goOn()
}
});
}else if(localStorage.getItem('cc_token')) {
store.dispatch('setToken', localStorage.getItem('cc_token'));
if(localStorage.getItem('userDesc')){
sa.login(JSON.parse(localStorage.getItem('userDesc')).user_id);
goOn()
}else{
getUserDetailApi().then(res=>{
localStorage.setItem('userDesc',JSON.stringify(res));
sa.login(res.user_id);
goOn()
}).catch(()=>{
if(localStorage.getItem('userDesc')){
goOn()
}
});
}
// 无需token登录页面
}else{
let query = {retUrl:to.fullPath};
if(to.meta.noNew){
query.is_new_user_url = 1
}
next({name:'author',query:query})
}
// if(to.meta.skip_login){
// next();
// }
});
export default router;