|
|
import Vue from 'vue';
|
|
|
import {
|
|
|
ROUTE_CHANGE,
|
|
|
} from 'store/yoho/types';
|
|
|
import {createApp} from './app';
|
|
|
import {createApi} from 'create-api';
|
|
|
import {Style, Toast, Dialog, DatePicker, ImagePreview} from 'cube-ui'; //eslint-disable-line
|
|
|
import {get} from 'lodash';
|
|
|
import { ROUTE_CHANGE } from 'store/yoho/types';
|
|
|
import { createApp } from './app';
|
|
|
import { createApi } from 'create-api';
|
|
|
import { Style, Toast, Dialog, DatePicker, ImagePreview } from 'cube-ui'; //eslint-disable-line
|
|
|
import { get } from 'lodash';
|
|
|
import Lazy from 'vue-lazyload';
|
|
|
import cookie from 'yoho-cookie';
|
|
|
import yoho from 'common/yoho';
|
...
|
...
|
@@ -23,7 +21,7 @@ const $app = document.getElementById('app'); |
|
|
|
|
|
const isDegrade = Boolean(!($app && $app.attributes['data-server-rendered']));
|
|
|
const context = get(window, '__INITIAL_STATE__.yoho.context');
|
|
|
const {app, router, store} = createApp(context);
|
|
|
const { app, router, store } = createApp(context);
|
|
|
const api = createApi();
|
|
|
|
|
|
if (window.__INITIAL_STATE__) {
|
...
|
...
|
@@ -45,8 +43,7 @@ Vue.use(OrderCouponList); |
|
|
Vue.use(OrderPromotionList);
|
|
|
Vue.use(Bind);
|
|
|
|
|
|
|
|
|
yoho.auth = async(loginUrl) => {
|
|
|
yoho.auth = async loginUrl => {
|
|
|
let user = await sdk.getUser();
|
|
|
|
|
|
if (user && user.uid) {
|
...
|
...
|
@@ -54,15 +51,16 @@ yoho.auth = async(loginUrl) => { |
|
|
} else {
|
|
|
cookie.set('third_backurl', location.href, {
|
|
|
domain: '.yohobuy.com',
|
|
|
path: '/'
|
|
|
path: '/',
|
|
|
});
|
|
|
|
|
|
location.href = loginUrl || `${location.origin}/xianyu/passport/login/taobao`;
|
|
|
location.href =
|
|
|
loginUrl || `${location.origin}/xianyu/passport/login/taobao`;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
yoho.authRealName = async() => {
|
|
|
yoho.authRealName = async () => {
|
|
|
if (await yoho.auth()) {
|
|
|
let res = await api.get('/api/ufo/sellerOrder/entryStatus');
|
|
|
|
...
|
...
|
@@ -71,7 +69,7 @@ yoho.authRealName = async() => { |
|
|
|
|
|
if (!get(res.data, 'isZhiMaCertWithPhoto')) {
|
|
|
router.push({
|
|
|
name: 'passport.auth'
|
|
|
name: 'passport.auth',
|
|
|
});
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -82,19 +80,19 @@ yoho.authRealName = async() => { |
|
|
|
|
|
return {
|
|
|
code: 403,
|
|
|
message: '未登录'
|
|
|
message: '未登录',
|
|
|
};
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const fetchAsycData = (matched, r) => {
|
|
|
const asyncDataPromises = matched
|
|
|
.map(({asyncData}) => asyncData && asyncData({store, router: r})).
|
|
|
filter(p => p);
|
|
|
.map(({ asyncData }) => asyncData && asyncData({ store, router: r }))
|
|
|
.filter(p => p);
|
|
|
|
|
|
return Promise.all(asyncDataPromises);
|
|
|
};
|
|
|
|
|
|
const trackPage = (path) => {
|
|
|
const trackPage = path => {
|
|
|
if (window._hmt) {
|
|
|
try {
|
|
|
window._hmt.push(['_trackPageview', path]);
|
...
|
...
|
@@ -111,9 +109,9 @@ router.onReady(() => { |
|
|
param: {
|
|
|
F_URL: `${location.origin}${router.currentRoute.fullPath}`,
|
|
|
PAGE_URL: '',
|
|
|
PAGE_NAME: router.currentRoute.name
|
|
|
}
|
|
|
}
|
|
|
PAGE_NAME: router.currentRoute.name,
|
|
|
},
|
|
|
},
|
|
|
});
|
|
|
|
|
|
if (isDegrade) {
|
...
|
...
|
@@ -121,7 +119,6 @@ router.onReady(() => { |
|
|
}
|
|
|
|
|
|
router.beforeResolve((to, from, next) => {
|
|
|
|
|
|
if (from.query.bind_code) {
|
|
|
app.$createThirdBind().close();
|
|
|
} else if (to.query.bind_code) {
|
...
|
...
|
@@ -132,7 +129,7 @@ router.onReady(() => { |
|
|
trackPage(to.fullPath);
|
|
|
const matched = router.getMatchedComponents(to);
|
|
|
|
|
|
store.commit(ROUTE_CHANGE, {to, from});
|
|
|
store.commit(ROUTE_CHANGE, { to, from });
|
|
|
|
|
|
store.dispatch('reportYas', {
|
|
|
params: {
|
...
|
...
|
@@ -140,20 +137,20 @@ router.onReady(() => { |
|
|
param: {
|
|
|
F_URL: `${location.origin}${to.fullPath}`,
|
|
|
PAGE_URL: `${location.origin}${from.fullPath}`,
|
|
|
PAGE_NAME: from.name
|
|
|
}
|
|
|
}
|
|
|
PAGE_NAME: from.name,
|
|
|
},
|
|
|
},
|
|
|
});
|
|
|
|
|
|
fetchAsycData(matched, to)
|
|
|
.then(next)
|
|
|
.catch(e => {
|
|
|
store.dispatch('reportError', {error: e});
|
|
|
store.dispatch('reportError', { error: e });
|
|
|
console.error(e);
|
|
|
return next();
|
|
|
});
|
|
|
} catch (e) {
|
|
|
store.dispatch('reportError', {error: e});
|
|
|
store.dispatch('reportError', { error: e });
|
|
|
return next();
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -161,7 +158,6 @@ router.onReady(() => { |
|
|
});
|
|
|
|
|
|
router.onError(e => {
|
|
|
store.dispatch('reportError', {error: e});
|
|
|
router.push({name: 'error.500'});
|
|
|
store.dispatch('reportError', { error: e });
|
|
|
router.push({ name: 'error.500' });
|
|
|
}); |
|
|
|
...
|
...
|
|