Repository navigation
Expand file tree
/
Copy path2.html
More file actions
503 lines (433 loc) · 16 KB
/
Copy path2.html
File metadata and controls
503 lines (433 loc) · 16 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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>随机分队工具</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
}
body {
background-color: #f5f7fa;
color: #333;
line-height: 1.6;
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
.container {
display: flex;
flex-direction: column;
gap: 30px;
}
header {
text-align: center;
padding: 20px;
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
color: white;
border-radius: 12px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
}
.subtitle {
font-size: 1.1rem;
opacity: 0.9;
}
.content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
}
@media (max-width: 768px) {
.content {
grid-template-columns: 1fr;
}
}
.panel {
background: white;
border-radius: 12px;
padding: 25px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}
.panel-title {
font-size: 1.5rem;
margin-bottom: 20px;
color: #2c3e50;
border-bottom: 2px solid #3498db;
padding-bottom: 10px;
}
.people-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 12px;
margin-bottom: 25px;
}
.person-item {
display: flex;
align-items: center;
padding: 10px 15px;
background: #f8f9fa;
border-radius: 8px;
transition: all 0.3s ease;
cursor: pointer;
border: 2px solid transparent;
}
.person-item:hover {
background: #e9ecef;
transform: translateY(-2px);
}
.person-item.selected {
background: #d1ecf1;
border-color: #17a2b8;
}
.person-item input {
margin-right: 10px;
cursor: pointer;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 15px;
align-items: center;
margin-top: 20px;
}
.control-group {
display: flex;
flex-direction: column;
flex: 1;
min-width: 150px;
}
label {
margin-bottom: 8px;
font-weight: 600;
color: #495057;
}
select, input[type="number"] {
padding: 12px 15px;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 1rem;
transition: border 0.3s;
}
select:focus, input:focus {
border-color: #3498db;
outline: none;
}
.buttons {
display: flex;
gap: 15px;
margin-top: 20px;
}
button {
padding: 14px 28px;
border: none;
border-radius: 8px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
flex: 1;
}
#randomizeBtn {
background: linear-gradient(to right, #3498db, #2ecc71);
color: white;
}
#randomizeBtn:hover {
transform: translateY(-3px);
box-shadow: 0 7px 14px rgba(52, 152, 219, 0.3);
}
#resetBtn {
background: #f8f9fa;
color: #495057;
border: 2px solid #ddd;
}
#resetBtn:hover {
background: #e9ecef;
}
.results {
margin-top: 30px;
}
.groups-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
margin-top: 20px;
}
.group-card {
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
border-top: 5px solid #3498db;
}
.group-header {
font-size: 1.3rem;
font-weight: 700;
color: #2c3e50;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px dashed #eee;
}
.group-members {
list-style-type: none;
}
.group-members li {
padding: 8px 0;
border-bottom: 1px solid #f5f5f5;
}
.group-members li:last-child {
border-bottom: none;
}
.empty-message {
text-align: center;
color: #7f8c8d;
font-style: italic;
padding: 40px 20px;
background: #f8f9fa;
border-radius: 10px;
margin-top: 20px;
}
.stats {
display: flex;
justify-content: space-between;
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
font-weight: 600;
}
footer {
text-align: center;
margin-top: 40px;
color: #7f8c8d;
font-size: 0.9rem;
padding-top: 20px;
border-top: 1px solid #eee;
}
.highlight {
color: #e74c3c;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>随机分队工具</h1>
<p class="subtitle">选择参与人员,设置分组数量,一键随机分队</p>
</header>
<div class="content">
<div class="panel">
<h2 class="panel-title">选择参与人员</h2>
<div class="people-list" id="peopleList">
<!-- 人员列表将通过JS动态生成 -->
</div>
<div class="controls">
<div class="control-group">
<label for="groupCount">分组数量</label>
<select id="groupCount">
<option value="2">2组</option>
<option value="3">3组</option>
<option value="4">4组</option>
<option value="5">5组</option>
<option value="6">6组</option>
</select>
</div>
<div class="control-group">
<label for="selectionMode">选择模式</label>
<select id="selectionMode">
<option value="all">全选</option>
<option value="none">全不选</option>
<option value="invert">反选</option>
</select>
</div>
</div>
<div class="buttons">
<button id="randomizeBtn">开始随机分队</button>
<button id="resetBtn">重置选择</button>
</div>
</div>
<div class="panel">
<h2 class="panel-title">分组结果</h2>
<div class="stats">
<div>已选择: <span id="selectedCount" class="highlight">0</span> 人</div>
<div>分组数: <span id="groupCountDisplay" class="highlight">2</span> 组</div>
</div>
<div class="results" id="resultsContainer">
<div class="empty-message">
请选择参与人员并点击"开始随机分队"按钮
</div>
</div>
</div>
</div>
<footer>
<p>随机分队工具 © 2023 | 共 <span id="totalPeople">8</span> 人可选</p>
</footer>
</div>
<script>
// 初始人员名单
const people = ['福德', '阳', '虎', '赵宇', '子瑶', '米', '刘蕤宁', '宋海峰'];
// DOM元素
const peopleListEl = document.getElementById('peopleList');
const groupCountEl = document.getElementById('groupCount');
const selectionModeEl = document.getElementById('selectionMode');
const randomizeBtn = document.getElementById('randomizeBtn');
const resetBtn = document.getElementById('resetBtn');
const resultsContainer = document.getElementById('resultsContainer');
const selectedCountEl = document.getElementById('selectedCount');
const groupCountDisplayEl = document.getElementById('groupCountDisplay');
const totalPeopleEl = document.getElementById('totalPeople');
// 初始化人员列表
function initPeopleList() {
peopleListEl.innerHTML = '';
totalPeopleEl.textContent = people.length;
people.forEach((person, index) => {
const personItem = document.createElement('div');
personItem.className = 'person-item';
personItem.innerHTML = `
<input type="checkbox" id="person${index}" checked>
<label for="person${index}">${person}</label>
`;
// 添加点击事件切换选中状态
personItem.addEventListener('click', (e) => {
if (e.target.tagName !== 'INPUT') {
const checkbox = personItem.querySelector('input');
checkbox.checked = !checkbox.checked;
updateSelectedCount();
togglePersonItemStyle(personItem, checkbox.checked);
}
});
// 监听复选框变化
const checkbox = personItem.querySelector('input');
checkbox.addEventListener('change', () => {
updateSelectedCount();
togglePersonItemStyle(personItem, checkbox.checked);
});
peopleListEl.appendChild(personItem);
});
updateSelectedCount();
}
// 切换人员项的选中样式
function togglePersonItemStyle(item, isSelected) {
if (isSelected) {
item.classList.add('selected');
} else {
item.classList.remove('selected');
}
}
// 更新已选择人数
function updateSelectedCount() {
const checkboxes = document.querySelectorAll('.person-item input:checked');
selectedCountEl.textContent = checkboxes.length;
groupCountDisplayEl.textContent = groupCountEl.value;
}
// 随机选择算法
function shuffleArray(array) {
const shuffled = [...array];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}
// 随机分组函数
function randomizeGroups() {
// 获取选中的人员
const selectedPeople = [];
document.querySelectorAll('.person-item').forEach((item, index) => {
const checkbox = item.querySelector('input');
if (checkbox.checked) {
selectedPeople.push(people[index]);
}
});
// 检查是否有足够人员
if (selectedPeople.length === 0) {
resultsContainer.innerHTML = '<div class="empty-message">请至少选择一名参与人员</div>';
return;
}
// 获取分组数量
const groupCount = parseInt(groupCountEl.value);
// 随机打乱人员顺序
const shuffledPeople = shuffleArray(selectedPeople);
// 创建分组
const groups = Array.from({ length: groupCount }, () => []);
// 分配人员到各组
shuffledPeople.forEach((person, index) => {
groups[index % groupCount].push(person);
});
// 显示分组结果
displayGroups(groups);
}
// 显示分组结果
function displayGroups(groups) {
let html = '<div class="groups-container">';
groups.forEach((group, index) => {
html += `
<div class="group-card">
<div class="group-header">第 ${index + 1} 组 (${group.length}人)</div>
<ul class="group-members">
${group.map(person => `<li>${person}</li>`).join('')}
</ul>
</div>
`;
});
html += '</div>';
resultsContainer.innerHTML = html;
}
// 处理选择模式变化
function handleSelectionModeChange() {
const mode = selectionModeEl.value;
const checkboxes = document.querySelectorAll('.person-item input');
switch(mode) {
case 'all':
checkboxes.forEach(checkbox => {
checkbox.checked = true;
togglePersonItemStyle(checkbox.closest('.person-item'), true);
});
break;
case 'none':
checkboxes.forEach(checkbox => {
checkbox.checked = false;
togglePersonItemStyle(checkbox.closest('.person-item'), false);
});
break;
case 'invert':
checkboxes.forEach(checkbox => {
checkbox.checked = !checkbox.checked;
togglePersonItemStyle(checkbox.closest('.person-item'), checkbox.checked);
});
break;
}
updateSelectedCount();
}
// 重置选择
function resetSelection() {
document.querySelectorAll('.person-item input').forEach(checkbox => {
checkbox.checked = true;
togglePersonItemStyle(checkbox.closest('.person-item'), true);
});
groupCountEl.value = "2";
selectionModeEl.value = "all";
updateSelectedCount();
resultsContainer.innerHTML = '<div class="empty-message">请选择参与人员并点击"开始随机分队"按钮</div>';
}
// 事件监听
groupCountEl.addEventListener('change', updateSelectedCount);
selectionModeEl.addEventListener('change', handleSelectionModeChange);
randomizeBtn.addEventListener('click', randomizeGroups);
resetBtn.addEventListener('click', resetSelection);
// 初始化
document.addEventListener('DOMContentLoaded', () => {
initPeopleList();
updateSelectedCount();
});
</script>
</body>
</html>