Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
404 lines (376 loc) · 10.3 KB
/
Copy pathindex.html
File metadata and controls
404 lines (376 loc) · 10.3 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>选择困难户系统</title>
<style>
#title{
margin-left: 10%;
line-height: 2;
}
#content{
width: 80%;
height: 350px;
background: #f0e8e8;
margin: 20px auto;
text-align: center;
position: relative;
line-height: 300px;
color: #414d5a;
font-size: 30px;
}
#start_bt{
background: #ccc;
width: 180px;
height: 80px;
font-size: 30px;
color: #f40;
border-radius: 12px;
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -90px;
}
#hint{
text-align: center;
height: 20px;
margin-left: -10%;
}
#option_name{
border: groove;
}
#query_all{
border-bottom: ridge;
}
#query_all_div_pirent{
width: 80%;
height: 500px;
background-color: black;
position: fixed;
z-index: 2;
opacity: 0.8;
visibility: hidden;
overflow: scroll;
}
#query_all_null{
color: white;
margin-left: 35%;
margin-top: 100px;
position: fixed;
visibility: hidden;
display: block;
}
#del_all_option{
margin: 10px;
background: #5454de;
color: white;
border-style: none;
float: right;
}
.del_one_option{
float:right;
color: white;
margin-right: 10px;
background: #5454de;
border-style: none;
}
#query_all_list{
margin-top: 70px;
line-height: 30px;
}
#menu_li{
width: 100px;
height: 23px;
margin-left: -5px;
background: white;
}
#menu_name{
margin: 20px 10px 10px 30px;
color: white;
border-style: none;
float: left;
font-size: 18px;
}
li{
color: white;
font-size: 16px;
}
</style>
</head>
<body width="100%">
<div style="text-align: center;font-size: 30px;color: #52a29a;margin-bottom: 10px;">选择困难户专用</div>
<div id="title">
<div>
<span id="query_all">查看选项</span>
<div id="query_all_div_pirent">
<span id="menu_name"></span>
<button id="del_all_option">删除菜单</button>
<ul id="query_all_list">
</ul>
<span id="query_all_null">无数据</span>
</div>
</div>
<div>
<span>选择菜单:</span>
<select id="menu_li" onchange="menu_update()">
</select>
<button id="add_menu_bt">新增菜单</button>
</div>
<div>
添加选项:<input id="option_name">
<button id="add_option_bt">添加</button>
</div>
<div id="hint"></div>
</div>
<div id="content">
<span id="option_show">
点击开始
</span>
<button id="start_bt">
start
</button>
</div>
<script>
var menu = [];
var $start_bt = document.getElementById('start_bt');
var $content = document.getElementById('content');
var $option_show = document.getElementById('option_show');
var $option_name = document.getElementById('option_name');
var $add_option_bt = document.getElementById('add_option_bt');
var $hint = document.getElementById('hint');
var $query_all = document.getElementById('query_all');
var $query_all_list = document.getElementById('query_all_list');
var $query_all_div_pirent = document.getElementById('query_all_div_pirent');
var $query_all_null = document.getElementById('query_all_null');
var $del_all_option = document.getElementById('del_all_option');
var $del_one_option = document.getElementsByClassName('del_one_option');
var $menu_li = document.getElementById('menu_li');
var $add_menu_bt = document.getElementById('add_menu_bt');
var $menu_name = document.getElementById('menu_name');
var pulldown = true;
var timer;
var timer1;
// 初始化内容
function init() {
var menu=[];
for(var i=0;i<localStorage.length;i++){
if(localStorage.key(i).slice(0,4) == "menu"){
menu.push(localStorage.key(i).slice(4));
}else{
localStorage.removeItem(localStorage.key(i));
}
}
menu.sort();
menu.reverse();
for(var i=0;i<menu.length;i++){
var menu_value = JSON.parse(localStorage.getItem("menu"+menu[i]));
$menu_li.add(new Option(menu_value[0],"menu"+menu[i]));
}
};
init();
//查询选项列表
$query_all.onclick = function(){
if(pulldown){
show_query_option();
}else{
hide_query_option();
}
}
//展示选项列表
function show_query_option(){
$query_all_div_pirent.style.visibility = "visible";
$query_all_div_pirent.style.display = "";
var list="";
if(localStorage.length < 1){
$query_all_null.style.visibility = "visible";
$del_all_option.style.display = "none";
$menu_name.style.display = "none";
}else{
var index = $menu_li.selectedIndex;
var value = $menu_li.options[index].value;
var arr1 = JSON.parse(localStorage.getItem(value));
$menu_name.innerHTML = arr1[0];
if(arr1.length < 2){
$query_all_null.style.visibility = "visible";
list = "";
}else{
for(var i=1;i<arr1.length;i++){
list += "<li>"+arr1[i]+"<button onclick='del_this_option(this)' class='del_one_option'>"+"删除"+"</button>"+"</li>";
}
}
$query_all_list.innerHTML=list;
}
pulldown = false;
}
//隐藏选项列表
function hide_query_option(){
$query_all_null.style.visibility = "hidden";
$query_all_div_pirent.style.display = "none";
pulldown = true;
}
//点击选项列表区域外隐藏选项列表
document.addEventListener("click",function(event){
if(event.target.id != "query_all" && $query_all_div_pirent.style.visibility == "visible"){
hide_query_option();
}
});
//点击选项列表区域不隐藏选项列表
$query_all_div_pirent.addEventListener("click",function(event){
//event=event||window.event;
event.stopPropagation();
});
//删除单个的选项
function del_this_option(self) {
var oUl = document.querySelector("#query_all_list");
var oList = oUl.querySelectorAll("li");
for(var i=0;i<oList.length;i++){
oList[i].index = i + 1;
oList[i].onclick = function(){
var index = $menu_li.selectedIndex;
var value = $menu_li.options[index].value;
var arr1 = JSON.parse(localStorage.getItem(value));
arr1.splice(this.index,1);
localStorage.setItem(value,JSON.stringify(arr1));
if(arr1.length<2){
//localStorage.removeItem("arr");
$query_all_null.style.visibility = "visible";
//$option_show.innerHTML = "点击开始";
}
}
}
self.parentNode.remove();
clearInterval(timer);
clearInterval(timer1);
$option_show.innerHTML = "点击开始";
$start_bt.innerHTML = 'start';
$start_bt.style.display='';
}
//删除全部选项
$del_all_option.onclick = function(){
var index = $menu_li.selectedIndex;
var value = $menu_li.options[index].value;
var arr1 = JSON.parse(localStorage.getItem(value));
if (confirm("确认删除此菜单吗?")) {
localStorage.removeItem(value);
$query_all_list.innerHTML="";
$query_all_null.style.visibility = "visible";
$option_show.innerHTML = "点击开始";
location.reload();
}
}
//添加菜单
$add_menu_bt.onclick = function(){
var menu = [];
var menu_name = prompt("请输入菜单","").trim();
var arr = [];
if(menu_name == ""){
$hint.innerHTML = "请输入菜单";
$hint.style.color = "red";
timers(2);
}
if(menu_name){
for(var i = 0;i<localStorage.length;i++){
menu.push(localStorage.key(i).slice(4));
}
arr.push(menu_name);
if(localStorage.length == 0){
localStorage.setItem("menu"+1,JSON.stringify(arr));
$menu_li.add(new Option(menu_name,"menu"+1));
}else{
var max = Math.max.apply(null,menu);
localStorage.setItem("menu"+(max+1),JSON.stringify(arr));
$menu_li.add(new Option(menu_name,"menu"+(max+1)));
}
location.reload();
}
}
//点击添加选项按钮
$add_option_bt.onclick = function(){
var option_name = $option_name.value.trim();
if(localStorage.length==0){
$hint.innerHTML = "请添加菜单";
$hint.style.color = "red";
}else if(option_name == ""){
$hint.innerHTML = "请输入选项";
$hint.style.color = "red";
}else{
var index = $menu_li.selectedIndex;
var value = $menu_li.options[index].value;
var menu = JSON.parse(localStorage.getItem(value));
menu.push(option_name);
localStorage.setItem(value,JSON.stringify(menu));
$hint.innerHTML = "添加成功";
$hint.style.color = "#37bf37";
}
$option_name.value = "";
timers(2);
}
function timers(second){
s =second;
var t = setInterval(function(){
s = s -1;
if(s<0){
$hint.innerHTML = "";
clearInterval(t);
}
},1000);
}
//点击开始
$start_bt.onclick = function(){
if(localStorage.length == 0){
$hint.innerHTML = "请添加菜单";
$hint.style.color = "red";
}else{
var index = $menu_li.selectedIndex;
var value = $menu_li.options[index].value;
var arr1 = JSON.parse(localStorage.getItem(value));
if(arr1.length < 2){
$hint.innerHTML = "请添加选项";
$hint.style.color = "red";
}else if(arr1.length < 3){
$hint.innerHTML = "最少添加两个选项";
$hint.style.color = "red";
}else{
start(arr1);
$start_bt.innerHTML = 'restart';
$start_bt.style.display='none';
}
}
timers(2);
}
function start(arr1){
timer = setInterval(function(){
var num = random(1,arr1.length - 1);
$option_show.innerHTML = arr1[num];
},50);
stop();
}
function stop(){
var s=2;
timer1 = setInterval(function(){
s = s -1;
if(s<0){
clearInterval(timer);
clearInterval(timer1);
$start_bt.style.display='';
}
},1000);
}
//切换菜单后更新页面
function menu_update(){
clearInterval(timer);
clearInterval(timer1);
$option_show.innerHTML = "点击开始";
$start_bt.innerHTML = 'start';
$start_bt.style.display='';
}
// 随机函数
function random(a,b){
var randomNum = Math.round(Math.random() * (b - a) + a);
return randomNum;
}
</script>
</body>
</html>