1
|
import Vue from 'vue';
|
1
|
import Vue from 'vue';
|
2
|
-import {
|
|
|
3
|
- ROUTE_CHANGE,
|
|
|
4
|
-} from 'store/yoho/types';
|
|
|
5
|
-import {createApp} from './app';
|
|
|
6
|
-import {createApi} from 'create-api';
|
|
|
7
|
-import {Style, Toast, Dialog, DatePicker, ImagePreview} from 'cube-ui'; //eslint-disable-line
|
|
|
8
|
-import {get} from 'lodash';
|
2
|
+import { ROUTE_CHANGE } from 'store/yoho/types';
|
|
|
3
|
+import { createApp } from './app';
|
|
|
4
|
+import { createApi } from 'create-api';
|
|
|
5
|
+import { Style, Toast, Dialog, DatePicker, ImagePreview } from 'cube-ui'; //eslint-disable-line
|
|
|
6
|
+import { get } from 'lodash';
|
9
|
import Lazy from 'vue-lazyload';
|
7
|
import Lazy from 'vue-lazyload';
|
10
|
import cookie from 'yoho-cookie';
|
8
|
import cookie from 'yoho-cookie';
|
11
|
import yoho from 'common/yoho';
|
9
|
import yoho from 'common/yoho';
|
|
@@ -23,7 +21,7 @@ const $app = document.getElementById('app'); |
|
@@ -23,7 +21,7 @@ const $app = document.getElementById('app'); |
23
|
|
21
|
|
24
|
const isDegrade = Boolean(!($app && $app.attributes['data-server-rendered']));
|
22
|
const isDegrade = Boolean(!($app && $app.attributes['data-server-rendered']));
|
25
|
const context = get(window, '__INITIAL_STATE__.yoho.context');
|
23
|
const context = get(window, '__INITIAL_STATE__.yoho.context');
|
26
|
-const {app, router, store} = createApp(context);
|
24
|
+const { app, router, store } = createApp(context);
|
27
|
const api = createApi();
|
25
|
const api = createApi();
|
28
|
|
26
|
|
29
|
if (window.__INITIAL_STATE__) {
|
27
|
if (window.__INITIAL_STATE__) {
|
|
@@ -45,8 +43,7 @@ Vue.use(OrderCouponList); |
|
@@ -45,8 +43,7 @@ Vue.use(OrderCouponList); |
45
|
Vue.use(OrderPromotionList);
|
43
|
Vue.use(OrderPromotionList);
|
46
|
Vue.use(Bind);
|
44
|
Vue.use(Bind);
|
47
|
|
45
|
|
48
|
-
|
|
|
49
|
-yoho.auth = async(loginUrl) => {
|
46
|
+yoho.auth = async loginUrl => {
|
50
|
let user = await sdk.getUser();
|
47
|
let user = await sdk.getUser();
|
51
|
|
48
|
|
52
|
if (user && user.uid) {
|
49
|
if (user && user.uid) {
|
|
@@ -54,15 +51,16 @@ yoho.auth = async(loginUrl) => { |
|
@@ -54,15 +51,16 @@ yoho.auth = async(loginUrl) => { |
54
|
} else {
|
51
|
} else {
|
55
|
cookie.set('third_backurl', location.href, {
|
52
|
cookie.set('third_backurl', location.href, {
|
56
|
domain: '.yohobuy.com',
|
53
|
domain: '.yohobuy.com',
|
57
|
- path: '/'
|
54
|
+ path: '/',
|
58
|
});
|
55
|
});
|
59
|
|
56
|
|
60
|
- location.href = loginUrl || `${location.origin}/xianyu/passport/login/taobao`;
|
57
|
+ location.href =
|
|
|
58
|
+ loginUrl || `${location.origin}/xianyu/passport/login/taobao`;
|
61
|
return;
|
59
|
return;
|
62
|
}
|
60
|
}
|
63
|
-}
|
61
|
+};
|
64
|
|
62
|
|
65
|
-yoho.authRealName = async() => {
|
63
|
+yoho.authRealName = async () => {
|
66
|
if (await yoho.auth()) {
|
64
|
if (await yoho.auth()) {
|
67
|
let res = await api.get('/api/ufo/sellerOrder/entryStatus');
|
65
|
let res = await api.get('/api/ufo/sellerOrder/entryStatus');
|
68
|
|
66
|
|
|
@@ -71,7 +69,7 @@ yoho.authRealName = async() => { |
|
@@ -71,7 +69,7 @@ yoho.authRealName = async() => { |
71
|
|
69
|
|
72
|
if (!get(res.data, 'isZhiMaCertWithPhoto')) {
|
70
|
if (!get(res.data, 'isZhiMaCertWithPhoto')) {
|
73
|
router.push({
|
71
|
router.push({
|
74
|
- name: 'passport.auth'
|
72
|
+ name: 'passport.auth',
|
75
|
});
|
73
|
});
|
76
|
return;
|
74
|
return;
|
77
|
}
|
75
|
}
|
|
@@ -82,19 +80,19 @@ yoho.authRealName = async() => { |
|
@@ -82,19 +80,19 @@ yoho.authRealName = async() => { |
82
|
|
80
|
|
83
|
return {
|
81
|
return {
|
84
|
code: 403,
|
82
|
code: 403,
|
85
|
- message: '未登录'
|
83
|
+ message: '未登录',
|
86
|
};
|
84
|
};
|
87
|
-}
|
85
|
+};
|
88
|
|
86
|
|
89
|
const fetchAsycData = (matched, r) => {
|
87
|
const fetchAsycData = (matched, r) => {
|
90
|
const asyncDataPromises = matched
|
88
|
const asyncDataPromises = matched
|
91
|
- .map(({asyncData}) => asyncData && asyncData({store, router: r})).
|
|
|
92
|
- filter(p => p);
|
89
|
+ .map(({ asyncData }) => asyncData && asyncData({ store, router: r }))
|
|
|
90
|
+ .filter(p => p);
|
93
|
|
91
|
|
94
|
return Promise.all(asyncDataPromises);
|
92
|
return Promise.all(asyncDataPromises);
|
95
|
};
|
93
|
};
|
96
|
|
94
|
|
97
|
-const trackPage = (path) => {
|
95
|
+const trackPage = path => {
|
98
|
if (window._hmt) {
|
96
|
if (window._hmt) {
|
99
|
try {
|
97
|
try {
|
100
|
window._hmt.push(['_trackPageview', path]);
|
98
|
window._hmt.push(['_trackPageview', path]);
|
|
@@ -111,9 +109,9 @@ router.onReady(() => { |
|
@@ -111,9 +109,9 @@ router.onReady(() => { |
111
|
param: {
|
109
|
param: {
|
112
|
F_URL: `${location.origin}${router.currentRoute.fullPath}`,
|
110
|
F_URL: `${location.origin}${router.currentRoute.fullPath}`,
|
113
|
PAGE_URL: '',
|
111
|
PAGE_URL: '',
|
114
|
- PAGE_NAME: router.currentRoute.name
|
|
|
115
|
- }
|
|
|
116
|
- }
|
112
|
+ PAGE_NAME: router.currentRoute.name,
|
|
|
113
|
+ },
|
|
|
114
|
+ },
|
117
|
});
|
115
|
});
|
118
|
|
116
|
|
119
|
if (isDegrade) {
|
117
|
if (isDegrade) {
|
|
@@ -121,7 +119,6 @@ router.onReady(() => { |
|
@@ -121,7 +119,6 @@ router.onReady(() => { |
121
|
}
|
119
|
}
|
122
|
|
120
|
|
123
|
router.beforeResolve((to, from, next) => {
|
121
|
router.beforeResolve((to, from, next) => {
|
124
|
-
|
|
|
125
|
if (from.query.bind_code) {
|
122
|
if (from.query.bind_code) {
|
126
|
app.$createThirdBind().close();
|
123
|
app.$createThirdBind().close();
|
127
|
} else if (to.query.bind_code) {
|
124
|
} else if (to.query.bind_code) {
|
|
@@ -132,7 +129,7 @@ router.onReady(() => { |
|
@@ -132,7 +129,7 @@ router.onReady(() => { |
132
|
trackPage(to.fullPath);
|
129
|
trackPage(to.fullPath);
|
133
|
const matched = router.getMatchedComponents(to);
|
130
|
const matched = router.getMatchedComponents(to);
|
134
|
|
131
|
|
135
|
- store.commit(ROUTE_CHANGE, {to, from});
|
132
|
+ store.commit(ROUTE_CHANGE, { to, from });
|
136
|
|
133
|
|
137
|
store.dispatch('reportYas', {
|
134
|
store.dispatch('reportYas', {
|
138
|
params: {
|
135
|
params: {
|
|
@@ -140,20 +137,20 @@ router.onReady(() => { |
|
@@ -140,20 +137,20 @@ router.onReady(() => { |
140
|
param: {
|
137
|
param: {
|
141
|
F_URL: `${location.origin}${to.fullPath}`,
|
138
|
F_URL: `${location.origin}${to.fullPath}`,
|
142
|
PAGE_URL: `${location.origin}${from.fullPath}`,
|
139
|
PAGE_URL: `${location.origin}${from.fullPath}`,
|
143
|
- PAGE_NAME: from.name
|
|
|
144
|
- }
|
|
|
145
|
- }
|
140
|
+ PAGE_NAME: from.name,
|
|
|
141
|
+ },
|
|
|
142
|
+ },
|
146
|
});
|
143
|
});
|
147
|
|
144
|
|
148
|
fetchAsycData(matched, to)
|
145
|
fetchAsycData(matched, to)
|
149
|
.then(next)
|
146
|
.then(next)
|
150
|
.catch(e => {
|
147
|
.catch(e => {
|
151
|
- store.dispatch('reportError', {error: e});
|
148
|
+ store.dispatch('reportError', { error: e });
|
152
|
console.error(e);
|
149
|
console.error(e);
|
153
|
return next();
|
150
|
return next();
|
154
|
});
|
151
|
});
|
155
|
} catch (e) {
|
152
|
} catch (e) {
|
156
|
- store.dispatch('reportError', {error: e});
|
153
|
+ store.dispatch('reportError', { error: e });
|
157
|
return next();
|
154
|
return next();
|
158
|
}
|
155
|
}
|
159
|
});
|
156
|
});
|
|
@@ -161,7 +158,6 @@ router.onReady(() => { |
|
@@ -161,7 +158,6 @@ router.onReady(() => { |
161
|
});
|
158
|
});
|
162
|
|
159
|
|
163
|
router.onError(e => {
|
160
|
router.onError(e => {
|
164
|
- store.dispatch('reportError', {error: e});
|
|
|
165
|
- router.push({name: 'error.500'});
|
161
|
+ store.dispatch('reportError', { error: e });
|
|
|
162
|
+ router.push({ name: 'error.500' });
|
166
|
}); |
163
|
}); |
167
|
- |
|
|