index.js
4.26 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
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
import * as Types from './types';
import cookie from 'yoho-cookie';
import {merge} from 'lodash';
export default function(state = {}) {
return {
state: merge({
context: {
title: '',
env: {
isApp: true,
isiOS: false,
isAndroid: false,
isYohoBuy: false,
},
route: '',
path: '',
needLogin: false,
isLogin: false,
userHeadIco: ''
},
window: {
statusBarStatus: false,
statusBarHeight: 0,
statusBarColor: 'black',
clientHeight: 0,
clientWidth: 0,
supportsPassive: false,
supportWebp: false
},
historys: [],
direction: 'forword',
homePage: true
}, state),
mutations: {
[Types.SET_SERVER_INFO](state, {context}) {
state.context.title = context.title;
state.context.route = context.route;
state.context.path = context.path;
},
[Types.SET_ENV](state, {env}) {
state.context.env = Object.assign({}, env);
},
[Types.SET_LOGIN_INFO](state, {uid}) {
state.context.isLogin = uid > 1;
},
[Types.SET_TITLE](state, {title}) {
state.context.title = title;
},
[Types.ROUTE_CHANGE](state, {to}) {
let topath;
try {
topath = decodeURIComponent(to.path);
} catch (error) {
topath = to.path;
}
if (state.historys.length >= 2 && state.historys[state.historys.length - 2].path === topath) {
state.historys.pop();
state.direction = 'back';
} else {
state.historys.push({
name: to.name,
path: topath
});
state.direction = 'forword';
}
state.homePage = state.historys.length <= 1;
},
[Types.SET_NEED_LOGIN](state, {needLogin}) {
state.context.needLogin = needLogin;
},
[Types.SET_WINDOW_SIZE](state, {clientWidth, clientHeight}) {
state.window.clientWidth = clientWidth;
state.window.clientHeight = clientHeight;
},
[Types.SET_SUPPORT_PASSIVE](state, {supportsPassive}) {
state.window.supportsPassive = supportsPassive;
},
[Types.SET_SUPPORT_WEBP](state, {supportWebp}) {
state.window.supportWebp = supportWebp;
},
[Types.SET_STATUS_BAR_STATUS](state, {status}) {
state.window.statusBarStatus = !!status;
},
[Types.SET_STATUS_BAR_HEIGHT](state, {height}) {
state.window.statusBarHeight = height;
},
[Types.SET_STATUS_BAR_COLOR](state, {color}) {
if (state.context.env.isYohoBuy && state.context.env.isiOS && state.window.statusBarStatus) {
state.window.statusBarColor = color || 'black';
}
},
[Types.FETCH_USER_INFO_SUCCESS](state, {head_ico}) {
state.context.userHeadIco = head_ico;
},
[Types.FETCH_USER_INFO_FAILD](state) {
state.context.userHeadIco = '';
},
},
getters: {
getLogin(state) {
return state.context.isLogin;
}
},
actions: {
async fetchUserProfile({commit, state}) {
const result = await this.$api.get('/api/grass/userProfile');
if (result && result.code === 200) {
if (!result.data) {
result.data = {};
}
commit(Types.FETCH_USER_INFO_SUCCESS, result.data);
return result.data;
} else {
commit(Types.FETCH_USER_INFO_FAILD);
return {};
}
},
reportYas(params, {params: {appop, param}, asyncindx = false}) {
try {
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);
});
} catch (e) {
// pass
}
}
}
};
}