-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathworker.js
1855 lines (1665 loc) · 61 KB
/
worker.js
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Version:1.5.0
//Date:2024-11-22 10:50:47
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
//防止被滥用,在添加车辆信息时需要用来鉴权
const API_KEY = "sk-@Admin123";
const notifyMessage = "您好,有人需要您挪车,请及时处理。";
const sendSuccessMessage = "您好,我已收到你的挪车通知,我正在赶来的路上,请稍等片刻!";
//300秒内可发送5次通知
const rateLimitDelay = 300;
const rateLimitMaxRequests = 5;
//达到速率限制时返回内容
const rateLimitMessage = "我正在赶来的路上,请稍等片刻~~~";
//通知类型,其他的通知类型可自行实现
const notifyTypeMap = [
{ "id": "1", "name": "WxPusher", "functionName": wxpusher, "tip": "\r\nAT_xxxxxx|UID_xxxxxx" },
{ "id": "2", "name": "Bark", "functionName": bark, "tip": "\r\ntoken|soundName\r\n\r\n注:token为xxxxxx代表的值,直接输入该值即可,请勿输入完整链接(https://api.day.app/xxxxxx),soundName为铃声名称(默认使用:multiwayinvitation),如需自定义铃声需要把铃声文件先上传到BarkApp" },
{ "id": "3", "name": "飞书机器人", "functionName": feishu, "tip": "\r\ntoken\r\n\r\n注:token为xxxxxx代表的值,直接输入该值即可,请勿输入完整链接(https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxx)" },
{ "id": "4", "name": "企业微信机器人", "functionName": weixin, "tip": "\r\ntoken\r\n\r\n注:token为xxxxxx代表的值,直接输入该值即可,请勿输入完整链接(https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxx)" },
{ "id": "5", "name": "钉钉机器人", "functionName": dingtalk, "tip": "\r\ntoken\r\n\r\n注:token为xxxxxx代表的值,直接输入该值即可,请勿输入完整链接(https://oapi.dingtalk.com/robot/send?access_token=xxxxxx)" },
{ "id": "6", "name": "NapCatQQ", "functionName": onebot, "tip": "http://127.0.0.1:8000/send_private_msg|access_token|接收人QQ号" },
{ "id": "7", "name": "Lagrange.Onebot", "functionName": onebot, "tip": "http://127.0.0.1:8000/send_private_msg|access_token|接收人QQ号" }
]
async function handleRequest(request) {
try {
const url = new URL(request.url);
const pathname = url.pathname;
if (request.method === "OPTIONS") {
return getResponse("", 204);
}
else if (request.method == "POST") {
if (pathname == '/api/notifyOwner') {
const json = await request.json();
return await notifyOwner(json);
}
else if (pathname == '/api/callOwner') {
const json = await request.json();
return await callOwner(json);
}
else if (pathname == '/api/addOwner') {
if (!isAuth(request)) {
return getResponse(JSON.stringify({ code: 500, data: "Auth error", message: "fail" }), 200);
}
const json = await request.json();
return await addOwner(json);
}
else if (pathname == '/api/deleteOwner') {
if (!isAuth(request)) {
return getResponse(JSON.stringify({ code: 500, data: "Auth error", message: "fail" }), 200);
}
const json = await request.json();
return await deleteOwner(json);
}
else if (pathname == '/api/listOwner') {
if (!isAuth(request)) {
return getResponse(JSON.stringify({ code: 500, data: "Auth error", message: "fail" }), 200);
}
return await listOwner();
}
else if (pathname == '/api/notifyTypeList') {
return getNotifyTypeList();
}
else if (pathname == '/api/login') {
const { apiKey } = await request.json();
if (apiKey && apiKey == API_KEY) {
return getResponse(JSON.stringify({ code: 200, data: "Authorized", message: "success" }), 200);
}
else {
return getResponse(JSON.stringify({ code: 401, data: "Unauthorized", message: "fail" }), 200);
}
}
}
else if (request.method == "GET") {
if (pathname == "/login") {
return login();
}
else if (pathname == "/manager") {
return managerOwnerIndex();
}
else {
const style = url.searchParams.get("style") || "1";
const id = url.searchParams.get("id") || "";
return style == "2" ? await index2(id) : await index1(id);
}
}
} catch (error) {
return getResponse(JSON.stringify({ code: 500, data: error.message, message: "fail" }), 200);
}
}
function isAuth(request) {
const authHeader = request.headers.get("Authorization");
if (!authHeader || !authHeader.startsWith("Bearer ") || authHeader.split(" ")[1] !== API_KEY) {
return false;
}
else {
return true;
}
}
async function getKV(id) {
try {
if (id) {
const owner = await DATA.get(id) || null;
if (owner) {
return JSON.parse(owner);
}
}
} catch (e) {
}
return null;
}
async function putKV(id, owner, cfg) {
if (id) {
await DATA.put(id, JSON.stringify(owner), cfg);
return true;
}
else {
return false;
}
}
async function delKV(id) {
if (id) {
await DATA.delete(id);
return true;
}
else {
return false;
}
}
async function listKV(prefix, limit) {
return await DATA.list({ prefix, limit });
}
async function rateLimit(id) {
const key = `ratelimit:${id.toLowerCase()}`;
const currentCount = await getKV(key) || 0;
const notifyCount = parseInt(currentCount);
if (notifyCount >= rateLimitMaxRequests) {
return false;
}
await putKV(key, notifyCount + 1, {
expirationTtl: rateLimitDelay
});
return true
}
async function notifyOwner(json) {
const { id, message } = json;
const isCanSend = await rateLimit(id);
if (!isCanSend) {
return getResponse(JSON.stringify({ code: 200, data: rateLimitMessage, message: "success" }), 200);
}
const owner = await getKV(`car_${id.toLowerCase()}`);
if (!owner) {
return getResponse(JSON.stringify({ code: 500, data: "车辆信息错误!", message: "fail" }), 200);
}
if(!owner.isNotify){
return getResponse(JSON.stringify({ code: 500, data: "车主未开启该功能,请使用其他方式联系车主!", message: "fail" }), 200);
}
let resp = null;
const { no, notifyType, notifyToken } = owner;
const provider = notifyTypeMap.find(element => element.id == notifyType);
if (provider && provider.functionName && typeof provider.functionName === 'function') {
const sendMsg = `【${no}】${message || notifyMessage}`;
resp = await provider.functionName(notifyToken, sendMsg);
}
else {
resp = { code: 500, data: "发送失败!", message: "fail" };
}
return getResponse(JSON.stringify(resp), 200);
}
async function callOwner(json) {
const { id } = json;
const owner = await getKV(`car_${id.toLowerCase()}`);
if (!owner) {
return getResponse(JSON.stringify({ code: 500, data: "车辆信息错误!", message: "fail" }), 200);
}
if(!owner.isCall){
return getResponse(JSON.stringify({ code: 500, data: "车主未开启该功能,请使用其他方式联系车主!", message: "fail" }), 200);
}
const { phone } = owner;
return getResponse(JSON.stringify({ code: 200, data: phone, message: "success" }), 200);
}
async function addOwner(json) {
try {
const { id, no, phone, notifyType, notifyToken, isNotify, isCall } = json;
await putKV(`car_${id.toLowerCase()}`, { id, no, phone, notifyType, notifyToken, isNotify, isCall });
return getResponse(JSON.stringify({ code: 200, data: "添加成功", message: "success" }), 200);
} catch (e) {
return getResponse(JSON.stringify({ code: 500, data: "添加失败," + e.message, message: "success" }), 200);
}
}
async function deleteOwner(json) {
try {
const { id } = json;
await delKV(`car_${id.toLowerCase()}`);
return getResponse(JSON.stringify({ code: 200, data: "删除成功", message: "success" }), 200);
} catch (e) {
return getResponse(JSON.stringify({ code: 500, data: "删除失败," + e.message, message: "success" }), 200);
}
}
async function listOwner() {
const value = await listKV("car_", 50);
const keys = value.keys;
const arrys = [];
for (let i = 0; i < keys.length; i++) {
const owner = await getKV(keys[i].name);
if (!owner || !owner?.id) {
continue;
}
arrys.push(owner);
}
return getResponse(JSON.stringify({ code: 200, data: arrys, message: "success" }), 200);
}
function getNotifyTypeList() {
const types = [];
notifyTypeMap.forEach(element => {
types.push({ text: element.name, value: element.id, tip: element.tip })
});
return getResponse(JSON.stringify({ code: 200, data: types, message: "success" }), 200);
}
function login() {
const htmlContent = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>通知车主挪车</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background: #f0f2f5;
color: #333;
}
.container {
text-align: center;
padding: 20px;
width: 100%;
max-width: 400px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
background: #fff;
margin: 10px
}
h1 {
font-size: 24px;
margin-bottom: 20px;
color: #007bff;
}
input{
padding: 5px;
width: 100%;
}
button {
width: 100%;
padding: 5px;
margin: 10px 0;
font-size: 18px;
font-weight: bold;
color: #fff;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.3s;
}
.call-btn {
background: #17a2b8;
}
.call-btn:hover {
background: #138496;
}
@keyframes float {
0% {
transform: translateY(0px) rotate(0deg);
}
50% {
transform: translateY(-20px) rotate(5deg);
}
100% {
transform: translateY(0px) rotate(0deg);
}
}
.loading {
pointer-events: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.loading::after {
content: "";
position: absolute;
width: 20px;
height: 20px;
border: 3px solid #ffffff;
border-radius: 50%;
border-top-color: transparent;
animation: spin 0.8s linear infinite;
margin-left: 10px;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 12px 24px;
border-radius: 50px;
font-size: 16px;
opacity: 0;
transition: opacity 0.3s;
}
.toast.show {
opacity: 1;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
</style>
</head>
<body>
<div class="container">
<h1>登录</h1>
<input type="text" id="apiKey" placeholder="请输入API_KEY"/>
<button class="call-btn" onclick="login()">登录</button>
</div>
<div id="toast" class="toast"></div>
<div id="loadingBox" class="modal">
<div class="loading"></div>
</div>
<script>
function login() {
const authKey = document.getElementById('apiKey').value;
if (!authKey) {
showToast("请输入API_KEY");
return;
}
showLoading(true);
fetch("/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
apiKey: authKey
})
})
.then(response => response.json())
.then(data => {
showLoading(false);
if(data.code==200){
showToast("登录成功!");
setTimeout(() => {
localStorage.setItem('API_KEY', authKey);
window.location.href="/manager";
}, 500);
}
else{
showToast("登录失败,API_KEY错误!");
}
})
.catch(error => {
showLoading(false);
console.error("Error sending notification:", error);
alert("通知发送出错,请检查网络连接。");
});
}
function showToast(message, duration = 5000) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, duration);
}
// 显示添加模态框
function showLoading(isShow) {
if (isShow) {
document.getElementById('loadingBox').style.display = 'block';
}
else {
document.getElementById('loadingBox').style.display = 'none';
}
}
</script>
</body>
</html>`;
return new Response(htmlContent, {
headers: {
'Content-Type': 'text/html;charset=UTF-8',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*'
}
})
}
async function index1(id) {
const owner = await getKV(`car_${id.toLowerCase()}`);
const isNotify = owner?.isNotify ?? true;
const isCall = owner?.isCall ?? true;
const htmlContent = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>通知车主挪车</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background: #f0f2f5;
color: #333;
}
.container {
text-align: center;
padding: 20px;
width: 100%;
max-width: 400px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
background: #fff;
margin: 10px
}
h1 {
font-size: 24px;
margin-bottom: 20px;
color: #007bff;
}
p {
margin-bottom: 20px;
font-size: 16px;
color: #555;
}
button {
width: 100%;
padding: 15px;
margin: 10px 0;
font-size: 18px;
font-weight: bold;
color: #fff;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.3s;
}
.notify-btn {
background: #28a745;
}
.notify-btn:hover {
background: #218838;
}
.call-btn {
background: #17a2b8;
}
.call-btn:hover {
background: #138496;
}
.loading {
pointer-events: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.loading::after {
content: "";
position: absolute;
width: 20px;
height: 20px;
border: 3px solid #ffffff;
border-radius: 50%;
border-top-color: transparent;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
.toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 12px 24px;
border-radius: 50px;
font-size: 16px;
opacity: 0;
transition: opacity 0.3s;
}
.toast.show {
opacity: 1;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.hide-notify{
${!isNotify ? `display: none;` : ""}
}
.hide-call{
${!isCall ? `display: none;` : ""}
}
</style>
</head>
<body>
<div class="container">
<h1>通知车主挪车</h1>
<p>如需通知车主,请点击以下按钮</p>
<button class="notify-btn hide-notify" onclick="notifyOwner()">通知车主挪车</button>
<button class="call-btn hide-call" onclick="callOwner()">拨打车主电话</button>
</div>
<div id="toast" class="toast"></div>
<div id="loadingBox" class="modal">
<div class="loading"></div>
</div>
<script>
function getQueryVariable(variable) {
let query = window.location.search.substring(1);
let vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split("=");
if (pair[0].toLowerCase() == variable.toLowerCase()) {
return pair[1];
}
}
return "";
}
// 发送通知
function notifyOwner() {
let id = getQueryVariable("id");
if (!id) {
showToast("未获取到id参数");
return;
}
showLoading(true);
fetch("/api/notifyOwner", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: id,
message: ""
})
})
.then(response => response.json())
.then(data => {
showLoading(false);
showToast(data.data);
})
.catch(error => {
showLoading(false);
console.error("Error sending notification:", error);
alert("通知发送出错,请检查网络连接。");
});
}
// 拨打车主电话
function callOwner() {
let id = getQueryVariable("id");
if (!id) {
showToast("未获取到id参数");
return;
}
showLoading(true);
fetch("/api/callOwner", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: id,
})
})
.then(response => response.json())
.then(data => {
showLoading(false);
if (data.code === 200) {
window.location.href = "tel:" + data.data;
} else {
alert(data.data);
}
})
.catch(error => {
showLoading(false);
console.error("Error sending notification:", error);
alert("通知发送出错,请检查网络连接。");
});
}
function showToast(message, duration = 5000) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, duration);
}
// 显示添加模态框
function showLoading(isShow) {
if (isShow) {
document.getElementById('loadingBox').style.display = 'block';
}
else {
document.getElementById('loadingBox').style.display = 'none';
}
}
</script>
</body>
</html>`;
return new Response(htmlContent, {
headers: {
'Content-Type': 'text/html;charset=UTF-8',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*'
}
})
}
async function index2(id) {
const owner = await getKV(`car_${id.toLowerCase()}`);
const isNotify = owner?.isNotify ?? true;
const isCall = owner?.isCall ?? true;
const htmlContent = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>通知车主挪车</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--primary-color: #4776E6;
--secondary-color: #8E54E9;
--text-color: #2c3e50;
--shadow-color: rgba(0, 0, 0, 0.1);
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
color: var(--text-color);
padding: 20px;
line-height: 1.6;
}
.container {
text-align: center;
padding: 40px 30px;
width: 100%;
max-width: 400px;
border-radius: 16px;
box-shadow: 0 10px 40px var(--shadow-color);
background: rgba(255, 255, 255, 0.95);
/* backdrop-filter: blur(10px); */
transform: translateY(0);
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.container:hover {
transform: translateY(-8px);
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.15);
}
h1 {
/* font-size: 32px; */
margin-bottom: 25px;
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-weight: 700;
}
.car-icon {
font-size: 64px;
margin-bottom: 25px;
display: inline-block;
animation: float 6s ease-in-out infinite;
}
p {
margin-bottom: 30px;
/* font-size: 18px; */
color: #546e7a;
line-height: 1.8;
}
.button-group {
display: flex;
flex-wrap: wrap;
/* 允许子元素换行 */
justify-content: space-between;
/* 子元素在主轴上均匀分布 */
gap: 10px;
margin-bottom: 20px;
}
button {
flex: 1;
padding: 10px;
/* font-size: 18px;
font-weight: 600; */
border-radius: 10px;
color: #fff;
border: none;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}
button:active {
transform: scale(0.98);
}
.action-btn {
background: linear-gradient(45deg, #546c7c, #546c7c);
box-shadow: 0 4px 15px rgba(71, 118, 230, 0.2);
}
.action-btn:hover {
box-shadow: 0 6px 20px rgba(71, 118, 230, 0.3);
transform: translateY(-2px);
}
.notify-btn {
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
box-shadow: 0 4px 15px rgba(71, 118, 230, 0.2);
}
.notify-btn:hover {
box-shadow: 0 6px 20px rgba(71, 118, 230, 0.3);
transform: translateY(-2px);
}
.call-btn {
background: linear-gradient(45deg, #00b09b, #96c93d);
box-shadow: 0 4px 15px rgba(0, 176, 155, 0.2);
}
.call-btn:hover {
box-shadow: 0 6px 20px rgba(0, 176, 155, 0.3);
transform: translateY(-2px);
}
@keyframes float {
0% {
transform: translateY(0px) rotate(0deg);
}
50% {
transform: translateY(-20px) rotate(5deg);
}
100% {
transform: translateY(0px) rotate(0deg);
}
}
.loading {
pointer-events: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.loading::after {
content: "";
position: absolute;
width: 20px;
height: 20px;
border: 3px solid #ffffff;
border-radius: 50%;
border-top-color: transparent;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
.toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 12px 24px;
border-radius: 50px;
font-size: 16px;
opacity: 0;
transition: opacity 0.3s;
}
.toast.show {
opacity: 1;
}
textarea {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 4px;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.hide-notify{
${!isNotify ? `display: none;` : ""}
}
.hide-call{
${!isCall ? `display: none;` : ""}
}
</style>
</head>
<body>
<div class="container">
<div class="car-icon">🚗</div>
<h1>温馨提示</h1>
<p>不好意思阻碍到您的出行了<br>请通过以下方式联系我,我会立即前来挪车</p>
<div class="button-group hide-notify">
<textarea rows="5" id="notifyMessage" placeholder="给车主留言">车主,有人需要您挪车,请及时处理一下哦。</textarea>
</div>
<div class="button-group hide-notify">
<button class="action-btn" data-msg="车主,有人需要您挪车,请及时处理一下哦。">
<span>挪车</span>
</button>
<button class="action-btn" data-msg="车主,您爱车的车窗未关,请及时处理一下哦。">
<span>未关窗</span>
</button>
</div>
<div class="button-group hide-notify">
<button class="action-btn" data-msg="车主,您爱车的车灯未关,请及时处理一下哦。">
<span>未关灯</span>
</button>
<button class="action-btn" data-msg="车主,此处有交警查车,请及时处理一下哦。">
<span>交警</span>
</button>
</div>
<div class="button-group">
<button class="notify-btn hide-notify" onclick="notifyOwner()">
<span>微信通知</span> 📱
</button>
<button class="call-btn hide-call" onclick="callOwner()">
<span>电话联系</span> 📞
</button>
</div>
</div>
<div id="toast" class="toast"></div>
<div id="loadingBox" class="modal">
<div class="loading"></div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
let btns = document.querySelectorAll(".action-btn");
btns.forEach(element => {
element.addEventListener("click", function (e) {
document.getElementById("notifyMessage").value = e.currentTarget.dataset.msg;
})
});
});
function showToast(message, duration = 5000) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, duration);