-
Notifications
You must be signed in to change notification settings - Fork 2
/
setting.html
143 lines (129 loc) · 4.85 KB
/
setting.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="screen-orientation" content="portrait">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"/>
<title>抽奖设置</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<link id="linkStyle" rel="stylesheet" type="text/css" href="skin/style1/main.css">
<script type="text/javascript">
let styleValue = localStorage.getItem('act_style')
if(styleValue){
let linkEl = document.getElementById('linkStyle')
linkEl.href = `skin/${styleValue}/main.css`
}
</script>
</head>
<body>
<div id="main" class="wall">
<div style="width: 11rem;margin: 0 auto;">
<div class="title-panel">活动设置</div>
<div class="pond-panel">
<textarea id="txtPond" onpaste="onPaste"></textarea>
<div class="tools pond-btns">
<label>活动标题:</label><input id="txtTitle" type="text" class="input-txt" value="" placeholder="抽奖活动标题" onchange="onTitleChange(this.value)" />
<label>活动样式:</label>
<select id="selStyle" class="sel-style" onchange="onStyleChange(this.value)">
<option value="style1">黎明时分</option>
<option value="style2">红红火火</option>
<option value="style3">深色</option>
<option value="style4">蓝紫</option>
<option value="style5">黑蓝</option>
</select>
<label>人数设置:</label><input id="txtNum" type="text" class="input-txt" value="" placeholder="数字以,分隔,如:1,3,5" onchange="onNumChange(this.value)" />
<a href="javascript:void(0)" class="pure-button" onclick="onClear()">清空奖池</a><br/>
<a href="javascript:void(0)" class="pure-button" onclick="onSave()">保存奖池</a>
<div class="desc-panel">
<h1>说明:</h1>
<p>Excel 中直接复制ERP、姓名两列粘贴</p>
<p>或</p>
<p>手动录入,如:</p>
<p>ERP,姓名</p>
<p>ERP,姓名</p>
</div>
</div>
</div>
</div>
</div>
<div class="toast"><span></span></div>
<script type="text/javascript" src="js/adaptive.js"></script>
<script type="text/javascript">
let $txtTitle = document.getElementById('txtTitle')
$txtTitle.value = localStorage.getItem('act_title') || ''
let $txtNum = document.getElementById('txtNum')
$txtNum.value = JSON.parse(localStorage.getItem('act_nums') || '[]').join(',')
let textArea = document.getElementById('txtPond')
textArea.placeholder = 'Excel 中直接复制ERP、姓名两列粘贴 \n 或 \n 手动录入,如:\n ERP,姓名 \nERP,姓名 \n '
textArea.addEventListener('paste', onPaste)
onLoad()
function onLoad(){
let styleValue = localStorage.getItem('act_style') || 'style1'
document.getElementById('selStyle').value = styleValue
let pondList = JSON.parse(localStorage.getItem('act_pondList'))
if(pondList && pondList.length){
textArea.value = pondList.map(item => item.erp +','+ item.name).join('\n')
}
}
function onPaste(event){
event.preventDefault()
var text = (event.clipboardData || window.clipboardData).getData('text');
text = text.replace(/[\t,,]+/g, ',')
textArea.value += text
}
function onClear(event){
textArea.value = ''
localStorage.removeItem('act_pondList')
localStorage.removeItem('act_choosed')
}
function onSave(){
if(!textArea.value){
toast('请录入奖池名单')
return
}
let listStr = textArea.value.split('\n')
let pondList = listStr.filter(item => {
return item && item.length
}).map(item => {
let itemArr = item.split(/,|,/)
return {
erp: itemArr[0].trim(),
name: itemArr[1].trim()
}
})
localStorage.setItem('act_pondList', JSON.stringify(pondList))
toast('保存成功!')
}
function toast(msg){
let $toast = document.getElementsByClassName('toast')[0]
$toast.getElementsByTagName('span')[0].innerText = msg
$toast.style.display = 'block'
setTimeout(() => {
$toast.style.display = 'none'
}, 1000 * 1.5);
}
function onTitleChange(title){
if(!title){
localStorage.removeItem('act_title')
return
}
localStorage.setItem('act_title', title)
}
function onNumChange(nums){
if(!nums){
localStorage.removeItem('act_nums')
return
}
let numList = nums.replace(/[,,]+/g, ',').split(',')
localStorage.setItem('act_nums', JSON.stringify(numList))
}
function onStyleChange(style){
let $linkStyle = document.getElementById('linkStyle')
$linkStyle.href = `skin/${style}/main.css`
localStorage.setItem('act_style', style)
}
</script>
</body>
</html>