index.js
2.87 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
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
import {
SET_ENV,
SET_TITLE,
ROUTE_CHANGE,
INIT_ROUTE_CHANGE,
PAGE_INIT_VISIBLE,
REPORT_YAS,
YOHO_PAGE_VISIBLE,
} from './types';
import cookie from 'yoho-cookie';
import _ from 'lodash/core';
export function createYoho() {
return {
state: {
title: '',
env: {
isApp: true,
isiOS: false,
isAndroid: false,
isYohoBuy: false,
channel: 'men',
fs: true
},
visible: true,
pageVisible: false,
history: [],
direction: 'forword'
},
mutations: {
[SET_ENV](state, params) {
Object.assign(state.env, params);
},
[SET_TITLE](state, params) {
state.title = params.title;
},
[INIT_ROUTE_CHANGE](state, {routes}) {
state.history = routes;
},
[ROUTE_CHANGE](state, {name, fullPath}) {
let routeIndex;
state.env.fs = false;
_.each(state.history, (h, index) => {
if (h.name === name) {
routeIndex = index;
return false;
}
});
if (routeIndex >= 0) {
state.history = state.history.slice(0, routeIndex + 1);
state.direction = 'back';
} else {
state.history.push({
name,
fullPath
});
state.direction = 'forword';
}
},
[PAGE_INIT_VISIBLE](state, {visible}) {
state.visible = visible;
},
[YOHO_PAGE_VISIBLE](state, {visible}) {
state.pageVisible = visible;
}
},
actions: {
[REPORT_YAS]({state, dispatch}, {params: {appop, param}, asyncindx = false, repeat = true}) {
if (window._yas && window._yas.sendCustomInfo) {
param = param || {};
if (!param.C_ID) {
const channel = {
men: 1,
women: 2
}[cookie.get('_Channel') || 'men'];
param.C_ID = channel;
}
window._yas.sendCustomInfo({
appop,
param: param ? JSON.stringify(param) : '{}'
}, asyncindx);
} else if (repeat && state.env.isiOS) {
setTimeout(() => {
dispatch(REPORT_YAS, {params: {appop, param}, asyncindx: false, repeat: false});
}, 1000);
}
}
}
};
}