index.js
2.44 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
import * as Types from './types';
import cookie from 'yoho-cookie';
export default function() {
return {
state: {
context: {
title: '',
env: {
isApp: true,
isiOS: false,
isAndroid: false,
isYohoBuy: false,
channel: 'men',
fs: true,
},
route: '',
path: '',
needLogin: false,
isLogin: false
},
window: {
clientHeight: 0,
clientWidth: 0,
supportsPassive: false
},
historys: [],
direction: 'forword',
homePage: true
},
mutations: {
[Types.SET_ENV](state, {context}) {
state.context.title = context.title;
state.context.route = context.route;
state.context.path = context.path;
state.context.isLogin = context.user.uid > 1;
},
[Types.SET_TITLE](state, {title}) {
state.context.title = title;
},
[Types.ROUTE_CHANGE](state, {to}) {
if (state.historys.length >= 2 && state.historys[state.historys.length - 2].path === to.fullPath) {
state.historys.pop();
state.direction = 'back';
} else {
state.historys.push({
name: to.name,
path: to.fullPath
});
state.direction = 'forword';
}
console.log(state.direction)
state.homePage = state.historys.length <= 1;
},
[Types.SET_NEED_LOGIN](state, {needLogin}) {
state.context.needLogin = needLogin;
},
[Types.SET_WINDOW_SIZE](state, data) {
state.window = Object.assign(state.window, data);
},
[Types.SET_SUPPORT_PASSIVE](state, {supportsPassive}) {
state.window.supportsPassive = supportsPassive;
}
},
actions: {
reportYas(params, {params: {appop, param}, asyncindx = false}) {
document.addEventListener('deviceready', () => {
setTimeout(() => {
if (window._yas && window._yas.sendAppLogs) {
param = param || {};
if (!param.C_ID) {
const channel = {
men: 1,
women: 2
}[cookie.get('_Channel') || 'men'];
param.C_ID = channel;
}
window._yas.sendAppLogs({
appop,
param: param ? JSON.stringify(param) : '{}'
}, asyncindx);
}
}, 300);
});
}
}
};
}