-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotteryTool.html
More file actions
343 lines (300 loc) · 9.22 KB
/
Copy pathLotteryTool.html
File metadata and controls
343 lines (300 loc) · 9.22 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>抽签工具 - JustHTML 只需网页</title>
<script>
/**
* 动态加载(强制去除缓存) CSS 的函数
* @param {string} src - 要加载的 CSS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadStyle(src) {
return new Promise((resolve, reject) => {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
link.async = true;
link.onload = resolve;
link.onerror = reject;
document.head.appendChild(link);
});
}
/**
* 动态加载(强制去除缓存) JS 的函数
* @param {string} src - 要加载的 JS 的 src 链接
* @returns {Promise} 返回一个 Promise 对象,用于处理异步加载
*/
function loadScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src + '?v=' + new Date().getTime(); // 使用时间戳避免缓存
script.async = true;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
</script>
<script>
loadStyle('../assets/style.css')
let scriptArray = [
"../assets/AddHeader_Tools.js",
"../assets/AddFooter.js",
"../assets/AddIco.js",
"../assets/AutoRun.js",
]
scriptArray.forEach(script => {
loadScript(script);
});
</script>
<script src="../package/Vue/code/vue.global.prod.js"></script>
<script type="module" src="../package/Sober/code/main.js"></script>
<style>
.lottery-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.lottery-box {
position: relative;
width: 300px;
height: 400px;
background: linear-gradient(145deg, #2d2d2d, #1e1e1e);
border-radius: 20px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
margin: 30px auto;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.lottery-lid {
position: absolute;
top: -30px;
width: 320px;
height: 30px;
background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
border-radius: 10px 10px 0 0;
cursor: pointer;
}
.lottery-content {
padding: 20px;
text-align: center;
}
.ticket {
background-color: #f8f9fa;
color: #333;
padding: 15px;
border-radius: 8px;
margin: 10px 0;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.result-display {
font-size: 1.5em;
font-weight: bold;
text-align: center;
min-height: 60px;
display: flex;
align-items: center;
justify-content: center;
margin: 20px 0;
padding: 15px;
background-color: var(--bg-tertiary);
border-radius: var(--border-radius);
min-width: 300px;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin: 15px 0;
justify-content: center;
}
.info-box {
background-color: var(--bg-tertiary);
padding: 10px;
border-radius: var(--border-radius);
margin: 10px 0;
text-align: center;
}
.history-box {
width: 100%;
max-width: 600px;
margin-top: 20px;
}
.history-item {
padding: 10px;
background-color: var(--bg-secondary);
border-radius: var(--border-radius);
margin-bottom: 8px;
display: flex;
justify-content: space-between;
}
.lottery-animation {
animation: flip 0.6s ease-in-out;
}
@keyframes flip {
0% { transform: rotateY(0); }
50% { transform: rotateY(180deg); }
100% { transform: rotateY(360deg); }
}
.draw-btn {
background: linear-gradient(45deg, #ff6b6b, #ffa500);
color: white;
border: none;
padding: 12px 25px;
border-radius: 50px;
cursor: pointer;
font-size: 1.2em;
font-weight: bold;
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
transition: all 0.3s;
}
.draw-btn:hover {
transform: translateY(-3px);
box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}
.draw-btn:active {
transform: translateY(1px);
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<a href="../index.html" class="back-link">← 返回首页</a>
<div class="tool-section">
<h2>抽签工具</h2>
<p>模拟传统抽签过程,用于决定顺序或选择</p>
<div class="info-box">
<p><strong>使用说明:</strong></p>
<p>添加多个选项,点击"开始抽签"按钮进行随机抽取</p>
</div>
<div class="lottery-container">
<div class="lottery-box">
<div class="lottery-lid" @click="toggleLid"></div>
<div class="lottery-content">
<div v-if="tickets.length === 0" class="ticket">
<p>请先添加签条</p>
</div>
<div v-else>
<div v-for="(ticket, index) in tickets" :key="index" class="ticket">
<p>{{ ticket }}</p>
</div>
</div>
</div>
</div>
<div>
<textarea
v-model="newTicket"
placeholder="输入签条内容,每行一个..."
rows="4"
style="width: 100%; max-width: 500px;"
></textarea>
<div class="controls">
<button @click="addTickets">添加签条</button>
<button @click="clearTickets">清空签条</button>
</div>
</div>
<button class="draw-btn" @click="drawTicket" :disabled="tickets.length === 0">开始抽签</button>
<div class="result-display" :class="{ 'lottery-animation': isAnimating }">
<span v-if="drawnTicket">{{ drawnTicket }}</span>
<span v-else>等待抽签...</span>
</div>
<div class="history-box" v-if="history.length > 0">
<h3>抽签历史</h3>
<div v-for="(record, index) in history" :key="index" class="history-item">
<span>{{ record.time }} - {{ record.ticket }}</span>
<button @click="removeHistory(index)">删除</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
const { createApp, ref } = Vue;
createApp({
setup() {
const tickets = ref([]);
const newTicket = ref('');
const drawnTicket = ref('');
const history = ref([]);
const isLidOpen = ref(false);
const isAnimating = ref(false);
const addTickets = () => {
if (!newTicket.value.trim()) {
alert('请输入签条内容');
return;
}
const ticketList = newTicket.value
.split('\n')
.map(ticket => ticket.trim())
.filter(ticket => ticket !== '');
tickets.value.push(...ticketList);
newTicket.value = '';
};
const drawTicket = () => {
if (tickets.value.length === 0) {
alert('请先添加至少一个签条');
return;
}
// 动画效果
isAnimating.value = true;
// 模拟抽奖动画
let counter = 0;
const maxIterations = 20;
const interval = setInterval(() => {
const randomIndex = Math.floor(Math.random() * tickets.value.length);
drawnTicket.value = tickets.value[randomIndex];
counter++;
if (counter >= maxIterations) {
clearInterval(interval);
// 最终结果
const finalIndex = Math.floor(Math.random() * tickets.value.length);
drawnTicket.value = tickets.value[finalIndex];
// 添加到历史记录
history.value.unshift({
time: new Date().toLocaleString(),
ticket: drawnTicket.value
});
// 重置动画状态
setTimeout(() => {
isAnimating.value = false;
}, 300);
}
}, 100);
};
const clearTickets = () => {
if (confirm('确定要清空所有签条吗?')) {
tickets.value = [];
drawnTicket.value = '';
}
};
const toggleLid = () => {
isLidOpen.value = !isLidOpen.value;
};
const removeHistory = (index) => {
history.value.splice(index, 1);
};
return {
tickets,
newTicket,
drawnTicket,
history,
isLidOpen,
isAnimating,
addTickets,
drawTicket,
clearTickets,
toggleLid,
removeHistory
};
}
}).mount('#app');
</script>
</body>
</html>