index.js
1.86 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 Vue from 'vue';
import Vuex from 'vuex';
import {
setData,
resultField,
newLotteryField,
listField
} from '@/helper/index';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
config: {
name: '年会抽奖',
number: 70,
specialAward: 0,
firstPrize: 1,
secondPrize: 5,
thirdPrize: 8,
fourthPrize: 10,
fifthPrize: 20
},
result: {
specialAward: [],
firstPrize: [],
secondPrize: [],
thirdPrize: [],
fourthPrize: [],
fifthPrize: []
},
newLottery: [],
list: []
},
mutations: {
setClearStore(state) {
state.config = {
name: '年会抽奖',
number: 70,
specialAward: 0,
firstPrize: 1,
secondPrize: 5,
thirdPrize: 8,
fourthPrize: 10,
fifthPrize: 20
};
state.result = {
specialAward: [],
firstPrize: [],
secondPrize: [],
thirdPrize: [],
fourthPrize: [],
fifthPrize: []
};
state.newLottery = [];
state.list = [];
},
setConfig(state, config) {
state.config = config;
},
setResult(state, result = {}) {
state.result = result;
setData(resultField, state.result);
},
setNewLottery(state, newLottery) {
if (state.newLottery.find(item => item.name === newLottery.name)) {
return;
}
state.newLottery.push(newLottery);
setData(newLotteryField, state.newLottery);
},
setList(state, list) {
const arr = state.list;
list.forEach(item => {
const arrIndex = arr.findIndex(data => data.key === item.key);
if (arrIndex > -1) {
arr[arrIndex].name = item.name;
} else {
arr.push(item);
}
});
state.list = arr;
setData(listField, arr);
}
},
actions: {},
modules: {}
});