app.js
1.14 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
import Cookies from 'js-cookie'
import storage from '@/utils/storage'
const state = {
device: 'desktop',
language: Cookies.get('language') || 'zh',
size: Cookies.get('size') || 'medium',
category:[],
user:{},
token:''
}
const mutations = {
TOGGLE_DEVICE: (state, device) => {
state.device = device
},
TOGGLE_CATEGORY: (state, category) => {
state.category = category
},
TOGGLE_USER: (state, user) => {
state.user = user
storage.setUser(user)
},
TOGGLE_TOKEN: (state, token) => {
state.token = token
storage.setToken(token)
}
}
const actions = {
toggleDevice({ commit }, device) {
commit('TOGGLE_DEVICE', device)
},
toggleCategory({ commit }, category) {
commit('TOGGLE_CATEGORY', category)
},
toggleUser({ commit }, user) {
user.genderStr = user.gender?('male' === user.gender?'男':'女'):'请选择'
commit('TOGGLE_USER', user)
},
toggleToken({ commit }, token) {
commit('TOGGLE_TOKEN', token)
},
}
export default {
namespaced: true,
state,
mutations,
actions
}