-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
261 lines (226 loc) · 9.64 KB
/
index.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
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>班级随机抽号器</title>
<link rel="icon" href="https://wmimg.com/i/1169/2024/12/674c46c8cb5e7.png" type="image/webp">
<!-- 引入Bootstrap CSS -->
<link href="/bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f8f9fa;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
.container {
text-align: center;
margin-top: 50px; /* 增加顶部边距,使主体内容向下移动 */
}
#result {
font-size: 128px; /* 加大字体大小 */
margin-top: 20px;
margin-bottom: 40px;
color: #007bff;
}
.input-group {
margin-bottom: 20px;
}
.probability-section {
margin-top: 40px;
}
footer {
margin-top: auto;
padding: 10px;
background-color: #e9ecef;
width: 100%;
text-align: center;
font-size: 14px;
color: #6c757d;
}
#customImage {
display: none;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1 class="mb-4">班级随机抽号器</h1>
<div id="result">?</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">最小学号</span>
</div>
<input type="number" id="min" class="form-control" value="1">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">最大学号</span>
</div>
<input type="number" id="max" class="form-control" value="50">
</div>
<div class="row justify-content-center">
<div class="col-auto">
<button id="startBtn" class="btn btn-primary btn-lg mr-2">开始抽号</button>
</div>
<div class="col-auto">
<button id="stopBtn" class="btn btn-danger btn-lg" disabled>暂停抽号</button>
</div>
<div class="col-auto">
<button id="setProbBtn" class="btn btn-secondary btn-lg" data-toggle="modal" data-target="#probModal">设置</button>
</div>
</div>
</div>
<!-- 概率设置模态框 -->
<div class="modal fade" id="probModal" tabindex="-1" role="dialog" aria-labelledby="probModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="probModalLabel">设置</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="probInputs" class="row">
<!-- 学号和概率输入框将在这里动态生成 -->
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">密码</span>
</div>
<input type="password" id="password" class="form-control">
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="customCheckbox">
<label class="form-check-label" for="customCheckbox">
定制
</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="saveProbBtn">保存</button>
<button type="button" class="btn btn-warning" id="resetProbBtn">恢复默认</button>
</div>
</div>
</div>
</div>
<!-- 显示定制照片的区域 -->
<div id="customImage">
<img src="https://wmimg.com/i/1169/2024/12/674c478b08c82.png" alt="定制照片" style="max-width: 100%;">
</div>
<!-- 引入Bootstrap JS和依赖 -->
<script src="/jquery-3.5.1.slim.min.js"></script>
<script src="/popper.min.js"></script>
<script src="/bootstrap.min.js"></script>
<script>
let intervalId;
let min, max;
let probabilities = {};
let defaultProbabilities = {};
document.getElementById('startBtn').addEventListener('click', function() {
min = parseInt(document.getElementById('min').value);
max = parseInt(document.getElementById('max').value);
if (min >= max) {
alert('最小学号必须小于最大学号!');
return;
}
document.getElementById('startBtn').disabled = true;
document.getElementById('stopBtn').disabled = false;
intervalId = setInterval(function() {
const randomNum = getRandomNumber();
document.getElementById('result').textContent = randomNum;
}, 100); // 0.1秒一个
});
document.getElementById('stopBtn').addEventListener('click', function() {
clearInterval(intervalId);
document.getElementById('startBtn').disabled = false;
document.getElementById('stopBtn').disabled = true;
});
document.getElementById('setProbBtn').addEventListener('click', function() {
min = parseInt(document.getElementById('min').value);
max = parseInt(document.getElementById('max').value);
if (min >= max) {
alert('最小学号必须小于最大学号!');
return;
}
const probInputsDiv = document.getElementById('probInputs');
probInputsDiv.innerHTML = ''; // 清空之前的输入框
for (let i = min; i <= max; i++) {
const colDiv = document.createElement('div');
colDiv.className = 'col-3 mb-3';
const inputGroup = document.createElement('div');
inputGroup.className = 'input-group';
const prependDiv = document.createElement('div');
prependDiv.className = 'input-group-prepend';
prependDiv.innerHTML = `<span class="input-group-text">学号 ${i}</span>`;
const input = document.createElement('input');
input.type = 'number';
input.className = 'form-control prob-input';
input.value = probabilities[i] || 0;
input.dataset.number = i;
inputGroup.appendChild(prependDiv);
inputGroup.appendChild(input);
colDiv.appendChild(inputGroup);
probInputsDiv.appendChild(colDiv);
defaultProbabilities[i] = 0; // 默认概率为0
}
});
document.getElementById('saveProbBtn').addEventListener('click', function() {
const password = document.getElementById('password').value;
if (password !== '1711') {
alert('密码错误!');
return;
}
const probInputs = document.querySelectorAll('.prob-input');
probInputs.forEach(input => {
const probNumber = parseInt(input.dataset.number);
const probValue = parseInt(input.value);
if (probValue < 0 || probValue > 100) {
alert(`学号 ${probNumber} 的概率值必须在0到100之间!`);
return;
}
probabilities[probNumber] = probValue;
});
alert('设置已保存!');
$('#probModal').modal('hide');
});
document.getElementById('resetProbBtn').addEventListener('click', function() {
const probInputs = document.querySelectorAll('.prob-input');
probInputs.forEach(input => {
const probNumber = parseInt(input.dataset.number);
input.value = defaultProbabilities[probNumber];
probabilities[probNumber] = defaultProbabilities[probNumber];
});
alert('设置已恢复为默认值!');
});
document.getElementById('customCheckbox').addEventListener('change', function() {
const customImage = document.getElementById('customImage');
customImage.style.display = this.checked ? 'block' : 'none';
});
function getRandomNumber() {
const totalProb = Object.values(probabilities).reduce((sum, prob) => sum + prob, 0);
const random = Math.random() * 100;
let cumulativeProb = 0;
for (const [number, prob] of Object.entries(probabilities)) {
cumulativeProb += prob;
if (random < cumulativeProb) {
return number;
}
}
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
<!-- 版权页脚 -->
<footer>
<p>© 2024 Wu jingbo </p>
</footer>
</body>
</html>