index.js
1.53 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
export function setData(key, value) {
if (typeof value === 'string') {
return localStorage.setItem(key, value);
}
try {
localStorage.setItem(key, JSON.stringify(value));
} catch (err) {
return err;
}
}
export function getData(key) {
const value = localStorage.getItem(key);
try {
return JSON.parse(value);
} catch (err) {
return value;
}
}
export function removeData(key) {
return localStorage.removeItem(key);
}
export function clearData() {
return localStorage.clear();
}
export function getDomData(element, dataName) {
if (!element || !dataName || !element.getAttribute) {
return;
}
return element.getAttribute('data-' + dataName);
}
export const configField = 'config'; // 配置数据
export const resultField = 'result'; // 抽奖结果
export const newLotteryField = 'newLottery'; // 新增奖项
export const listField = 'list'; // 名单
export function conversionCategoryName(key) {
let name = '';
switch (key) {
case 'specialAward':
name = '特等奖';
break;
case 'firstPrize':
name = '一等奖';
break;
case 'secondPrize':
name = '二等奖';
break;
case 'thirdPrize':
name = '三等奖';
break;
case 'fourthPrize':
name = '四等奖';
break;
case 'fifthPrize':
name = '五等奖';
break;
default:
break;
}
const newLottery = getData(newLotteryField) || [];
const findres = newLottery.find(item => item.key === key);
if (findres) {
name = findres.name;
}
return name;
}