index.js
1.71 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
import {
SET_ENV,
SET_TITLE,
ROUTE_CHANGE,
INIT_ROUTE_CHANGE,
PAGE_INIT_VISIBLE
} from './types';
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,
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;
}
}
};
}