-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
1870 lines (1823 loc) · 74 KB
/
Copy pathadmin.php
File metadata and controls
1870 lines (1823 loc) · 74 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
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
<?php
// admin.php
session_start(); // 启动会话以存储登录状态
// 简单的登录检查
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
// 未登录,重定向到登录页面
header('Location: login.php');
exit();
}
// 从 Vercel 获取完整数据
$data_url = 'https://data-gold-xi.vercel.app/data.json'; // *** 请替换为实际的 Vercel 数据文件 URL ***
$json_data = @file_get_contents($data_url);
if ($json_data === FALSE) {
$gameData = [
'rooms' => [
['id' => 'room1', 'name' => '包厢A', 'machines' => [], 'note' => '', 'activeSessions' => []],
['id' => 'room2', 'name' => '包厢B', 'machines' => [], 'note' => '', 'activeSessions' => []]
],
'machines' => [
['id' => 'machine1', 'name' => 'PS5-01', 'image' => 'https://placehold.co/120x120/blue/white?text=PS5'],
// ... 其他默认机器 ...
],
'games' => [
['id' => 'game1', 'name' => '战神4', 'image' => 'https://placehold.co/120x120/orange/white?text=战神4', 'tags' => ['动作', '冒险']]
],
'machineGames' => []
];
} else {
$gameData = json_decode($json_data, true);
if (json_last_error() !== JSON_ERROR_NONE) {
$gameData = ['rooms' => [], 'machines' => [], 'games' => [], 'machineGames' => []];
}
// 确保必要字段存在
if (!isset($gameData['rooms'])) $gameData['rooms'] = [];
if (!isset($gameData['machines'])) $gameData['machines'] = [];
if (!isset($gameData['games'])) $gameData['games'] = [];
if (!isset($gameData['machineGames'])) $gameData['machineGames'] = [];
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>管理员后台 - 电玩店包厢管理系统</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 10px;
touch-action: manipulation;
}
.container {
max-width: 1400px;
margin: 0 auto;
}
.admin-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
flex-wrap: wrap;
gap: 10px;
}
.admin-header h1 {
color: white;
font-size: 1.8rem;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
text-align: center;
flex: 1;
}
/* 统一按钮样式 - 基础类 */
.btn {
border: none;
padding: 8px 12px;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
text-align: center;
transition: all 0.2s ease;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 4px;
}
.btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.btn:active {
transform: translateY(0);
}
.btn-primary {
background: #667eea;
color: white;
box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}
.btn-info {
background: #3b82f6;
color: white;
box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}
.btn-success {
background: #4ade80;
color: white;
box-shadow: 0 2px 4px rgba(74, 222, 128, 0.3);
}
.btn-warning {
background: #f59e0b;
color: white;
box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
}
.btn-danger {
background: #ef4444;
color: white;
box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}
/* 功能按钮区域 */
.action-buttons {
display: flex;
gap: 8px;
margin-bottom: 15px;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.action-btn {
flex: 1;
min-width: 100px;
}
/* 搜索框样式 */
.search-container {
display: flex;
align-items: center;
background: white;
border-radius: 8px;
padding: 2px 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
flex: 1;
max-width: 300px;
}
.search-container input {
border: none;
outline: none;
padding: 6px;
font-size: 14px;
flex: 1;
min-width: 0;
}
.search-container button {
background: none;
border: none;
cursor: pointer;
padding: 4px;
color: #667eea;
font-size: 16px;
}
/* 主要内容区域 */
.main-content {
display: flex;
gap: 10px;
margin-bottom: 10px;
flex-wrap: wrap;
}
/* 可用机器区域 */
.available-machines {
flex: 1;
min-width: 260px;
background: white;
padding: 12px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.available-machines h2 {
color: #333;
margin-bottom: 10px;
padding-bottom: 6px;
border-bottom: 2px solid #667eea;
font-size: 1.1rem;
}
.machine-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
gap: 10px;
}
.machine-card {
background: #f8fafc;
border-radius: 8px;
overflow: hidden;
border: 2px solid #e2e8f0;
position: relative;
cursor: -webkit-grab;
cursor: grab;
user-select: none;
display: flex;
flex-direction: column;
}
.machine-image {
width: 100%;
height: 70px;
background: #f1f5f9;
background-size: cover;
background-position: center;
}
.machine-name {
padding: 6px;
text-align: center;
font-weight: 600;
color: #333;
font-size: 12px;
word-wrap: break-word;
}
/* 机器卡片底部按钮区域 */
.machine-actions {
display: flex;
border-top: 1px solid #e2e8f0;
}
.machine-action-btn {
flex: 1;
padding: 6px 0;
border: none;
background: #f1f5f9;
font-size: 12px;
cursor: pointer;
transition: background-color 0.2s;
color: #475569;
}
.machine-action-btn:hover {
background: #e2e8f0;
}
.machine-action-btn.view {
color: #3b82f6;
}
.machine-action-btn.edit {
color: #10b981;
}
.machine-action-btn.delete {
color: #ef4444;
}
/* 包厢区域 */
.game-rooms {
flex: 2;
min-width: 280px;
display: grid;
/* 默认使用 auto-fit */
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
gap: 12px;
}
/* 强制在大于 500px 的屏幕上至少显示两列 (针对折叠屏) */
@media (min-width: 501px) {
.game-rooms {
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
}
/* 在更大的屏幕上显示更多列 */
@media (min-width: 1025px) {
.game-rooms {
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
}
/* 隐藏已使用的包厢的类 */
.game-rooms.hide-used .room-card.used {
display: none;
}
.room-card {
background: white;
border-radius: 12px;
padding: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
border-left: 4px solid transparent;
}
.room-card.used {
border-left-color: #667eea;
}
.room-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding-bottom: 6px;
border-bottom: 2px solid #667eea;
}
.room-header h3 {
color: #333;
font-size: 1.05rem;
font-weight: 600;
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.room-controls {
display: flex;
gap: 3px;
}
.room-edit, .room-delete {
width: 24px;
height: 24px;
border-radius: 50%;
font-size: 12px;
}
.machine-dropzone {
min-height: 50px;
background: #f8fafc;
border-radius: 6px;
padding: 8px;
margin-bottom: 10px;
border: 2px dashed #cbd5e1;
position: relative;
z-index: 1;
font-size: 12px;
}
.machine-dropzone.empty {
display: flex;
justify-content: center;
align-items: center;
color: #94a3b8;
font-style: italic;
font-size: 11px;
min-height: 50px;
}
.machine-in-room {
background: #dbeafe;
padding: 6px;
margin: 2px 0;
border-radius: 6px;
display: flex;
justify-content: space-between;
align-items: center;
border: 2px solid #93c5fd;
position: relative;
font-size: 12px;
}
.machine-name {
font-weight: 600;
color: #2563eb;
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
/* 为包厢内的机器添加查看按钮 */
.machine-view-btn {
width: 20px;
height: 20px;
border-radius: 50%;
font-size: 12px;
margin-right: 4px;
}
.machine-remove-btn {
width: 20px;
height: 20px;
border-radius: 50%;
font-size: 12px;
}
.session-controls {
display: flex;
gap: 8px;
margin-bottom: 8px;
}
.session-btn {
flex: 1;
min-width: 70px;
padding: 8px;
}
.note-section {
margin-top: 6px;
}
.note-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 6px;
}
.note-header label {
font-weight: 600;
color: #333;
font-size: 13px;
}
.note-content {
background: #f8fafc;
padding: 6px;
border: 2px solid #e0e0e0;
border-radius: 6px;
min-height: 30px;
font-size: 12px;
color: #333;
word-wrap: break-word;
line-height: 1.4;
}
.session-info {
background: #f0fdf4;
padding: 6px;
border-radius: 6px;
font-size: 11px;
color: #16a34a;
margin-bottom: 8px;
border: 1px solid #bbf7d0;
}
.session-info h4 {
margin-bottom: 3px;
color: #059669;
font-size: 12px;
}
.session-info p {
margin: 1px 0;
font-size: 10px;
}
.time-left {
font-weight: 600;
color: #dc2626;
}
/* 模态框样式 */
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.6);
justify-content: center;
align-items: center;
z-index: 1000;
backdrop-filter: blur(2px);
}
.modal-content {
background: white;
padding: 20px;
border-radius: 12px;
max-width: 95%;
width: 350px;
max-height: 90vh;
overflow-y: auto;
box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding-bottom: 8px;
border-bottom: 2px solid #e0e0e0;
}
.modal-header h3 {
color: #333;
font-size: 1.2rem;
}
.modal-close {
width: 28px;
height: 28px;
border-radius: 50%;
font-size: 18px;
}
.form-group {
margin-bottom: 12px;
}
.form-group label {
display: block;
margin-bottom: 4px;
font-weight: 500;
font-size: 13px;
}
.form-group input, .form-group textarea {
width: 100%;
padding: 8px;
border: 2px solid #e0e0e0;
border-radius: 6px;
font-size: 13px;
}
.form-group textarea {
min-height: 60px;
resize: vertical;
}
.installed-games {
margin: 10px 0;
padding: 10px;
background: #f1f5f9;
border-radius: 6px;
min-height: 50px;
}
.installed-games h4 {
font-size: 14px;
margin-bottom: 8px;
color: #333;
}
.game-option {
display: inline-block;
background: #e2e8f0;
padding: 4px 8px;
border-radius: 12px;
font-size: 11px;
margin: 2px 4px 2px 0;
color: #475569;
cursor: pointer;
}
.game-option.add {
background: #667eea;
color: white;
}
.game-option.remove {
background: #ef4444;
color: white;
}
/* 游戏列表模态框内的搜索框 */
.games-modal-search-container {
margin-bottom: 10px;
display: flex;
align-items: center;
background: #f1f5f9;
border-radius: 6px;
padding: 2px 6px;
}
.games-modal-search-container input {
border: none;
outline: none;
padding: 4px;
font-size: 12px;
flex: 1;
background: transparent;
}
.games-modal-search-container button {
background: none;
border: none;
cursor: pointer;
padding: 2px;
color: #667eea;
font-size: 14px;
}
/* 新增:全局搜索区域样式 */
.global-search-container {
display: flex;
gap: 10px;
margin-bottom: 15px;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.global-search-box {
display: flex;
align-items: center;
background: white;
border-radius: 8px;
padding: 2px 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
flex: 1;
max-width: 300px;
}
.global-search-box input {
border: none;
outline: none;
padding: 6px;
font-size: 14px;
flex: 1;
min-width: 0;
}
.global-search-box button {
background: none;
border: none;
cursor: pointer;
padding: 4px;
color: #667eea;
font-size: 16px;
}
.export-btn {
flex: 0 0 auto; /* 不伸缩,保持原始大小 */
}
/* 新增:全局搜索结果区域样式 */
.global-search-results {
background: white;
padding: 15px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
margin-bottom: 15px;
display: none; /* 默认隐藏 */
}
.global-search-results h3 {
margin-bottom: 10px;
color: #333;
font-size: 1.1rem;
}
.global-search-results ul {
list-style-type: none;
padding-left: 0;
}
.global-search-results li {
padding: 5px 0;
border-bottom: 1px solid #eee;
}
.global-search-results li:last-child {
border-bottom: none;
}
@media (max-width: 768px) {
.main-content {
flex-direction: column;
}
.action-buttons, .global-search-container {
justify-content: center;
flex-direction: column;
}
.search-container, .global-search-box {
max-width: 100%;
margin-top: 5px;
}
.session-controls {
flex-direction: column;
}
/* 在手机上强制一列 */
.game-rooms {
grid-template-columns: 1fr;
}
.available-machines, .game-rooms {
min-width: 100%;
}
.machine-list {
grid-template-columns: repeat(3, 1fr);
}
.modal-content {
width: 95%;
margin: 20px;
}
.export-btn {
width: 100%; /* 在小屏幕上按钮占满宽度 */
}
}
</style>
</head>
<body>
<div class="container">
<div class="admin-header">
<h1>🎮 管理员后台</h1>
<div>
<a href="logout.php" class="btn btn-danger">登出</a> <!-- 新增登出链接 -->
<button id="backToHome" class="btn btn-primary">返回首页</button>
</div>
</div>
<div class="action-buttons">
<button id="addRoom" class="action-btn btn btn-info">添加包厢</button>
<button id="addMachine" class="action-btn btn btn-success">添加游戏机</button>
<button id="editGames" class="action-btn btn btn-warning">编辑游戏目录</button>
</div>
<!-- 新增:全局搜索和导出区域 -->
<div class="global-search-container">
<div class="global-search-box">
<input type="text" id="globalSearchInput" placeholder="搜索游戏名称...">
<button id="globalSearchButton">🔍</button>
</div>
<button id="exportData" class="btn btn-success export-btn">导出数据</button>
</div>
<!-- 新增:全局搜索结果显示区域 -->
<div class="global-search-results" id="globalSearchResults">
<h3>搜索结果</h3>
<ul id="globalSearchResultsList"></ul>
</div>
<!-- 隐藏/显示已使用包厢按钮 -->
<div style="text-align: center; margin-bottom: 10px;">
<button id="toggleUsedRooms" class="btn btn-primary">隐藏已使用包厢</button>
</div>
<div class="main-content">
<!-- 可用机器区域 -->
<div class="available-machines">
<h2>可用机器</h2>
<div class="machine-list" id="availableMachines"></div>
</div>
<!-- 包厢区域 -->
<div class="game-rooms" id="gameRooms"></div>
</div>
</div>
<!-- 编辑游戏机模态框 -->
<div class="modal" id="editMachineModal">
<div class="modal-content">
<div class="modal-header">
<h3 id="editMachineTitle">编辑游戏机</h3>
<button class="modal-close btn btn-danger" id="closeEditMachineModal">×</button>
</div>
<div class="edit-machine-form">
<div class="form-group">
<label for="machineName">机器名称</label>
<input type="text" id="machineName" placeholder="输入机器名称">
</div>
<div class="form-group">
<label for="machineImage">图片URL</label>
<input type="text" id="machineImage" placeholder="输入图片URL">
</div>
<div class="installed-games">
<h4>已安装的游戏</h4>
<div id="installedGamesList"></div>
</div>
<div class="installed-games">
<h4>可添加的游戏</h4>
<div id="availableGamesList"></div>
</div>
<button id="saveMachineBtn" class="btn btn-success">保存</button>
</div>
</div>
</div>
<!-- 编辑包厢模态框 -->
<div class="modal" id="editRoomModal">
<div class="modal-content">
<div class="modal-header">
<h3 id="editRoomTitle">编辑包厢</h3>
<button class="modal-close btn btn-danger" id="closeEditRoomModal">×</button>
</div>
<div class="form-group">
<label for="roomName">包厢名称</label>
<input type="text" id="roomName" placeholder="输入包厢名称">
</div>
<button id="saveRoomBtn" class="btn btn-success">保存</button>
</div>
</div>
<!-- 编辑备注模态框 -->
<div class="modal" id="editNoteModal">
<div class="modal-content">
<div class="modal-header">
<h3 id="editNoteTitle">编辑备注</h3>
<button class="modal-close btn btn-danger" id="closeEditNoteModal">×</button>
</div>
<div class="form-group">
<label for="noteContent">备注内容</label>
<textarea id="noteContent" placeholder="输入备注内容..."></textarea>
</div>
<button id="saveNoteBtn" class="btn btn-success">保存备注</button>
</div>
</div>
<!-- 游戏列表模态框 (带搜索) -->
<div class="modal" id="gamesModal">
<div class="modal-content">
<div class="modal-header">
<h3 id="gamesModalTitle">游戏列表</h3>
<button class="modal-close btn btn-danger" id="closeGamesModal">×</button>
</div>
<!-- 添加搜索框到游戏列表模态框 -->
<div class="games-modal-search-container">
<input type="text" id="gamesModalSearch" placeholder="搜索已安装游戏...">
<button id="clearGamesModalSearch">×</button>
</div>
<div id="gamesList"></div>
</div>
</div>
<!-- 选择机器模态框 -->
<div class="modal" id="selectMachineModal">
<div class="modal-content">
<div class="modal-header">
<h3 id="selectMachineTitle">选择机器</h3>
<button class="modal-close btn btn-danger" id="closeSelectMachineModal">×</button>
</div>
<div id="machineOptions"></div>
</div>
</div>
<!-- 输入时长模态框 -->
<div class="modal" id="durationModal">
<div class="modal-content">
<div class="modal-header">
<h3 id="durationTitle">选择时长</h3>
<button class="modal-close btn btn-danger" id="closeDurationModal">×</button>
</div>
<div id="durationOptions"></div>
</div>
</div>
<!-- 加时续玩密码模态框 -->
<div class="modal" id="extendPasswordModal">
<div class="modal-content">
<div class="modal-header">
<h3>加时续玩</h3>
<button class="modal-close btn btn-danger" id="closeExtendPasswordModal">×</button>
</div>
<p id="extendMinutesText">续玩 <span id="extendMinutes">0</span> 分钟</p>
<input type="password" id="extendPasswordInput" class="password-input" placeholder="输入密码">
<div style="display: flex; justify-content: center; gap: 10px; margin-top: 15px;">
<button class="btn btn-danger" id="cancelExtend">取消</button>
<button class="btn btn-success" id="confirmExtend">确认</button>
</div>
</div>
</div>
<script>
// 全局变量
let gameData = null;
let currentEditingMachineId = null;
let currentEditingRoomId = null;
let currentNoteRoomId = null;
let currentSelectingMachine = null;
let currentRoomId = null;
let currentMachineId = null;
let extendMinutes = 0;
let dragSource = null;
// const ADMIN_PASSWORD = '123456'; // 移除前端密码检查
let hideUsedRooms = false;
// DOM元素缓存
const elements = {
backToHome: document.getElementById('backToHome'),
addRoom: document.getElementById('addRoom'),
addMachine: document.getElementById('addMachine'),
editGames: document.getElementById('editGames'),
availableMachines: document.getElementById('availableMachines'),
gameRooms: document.getElementById('gameRooms'),
editMachineModal: document.getElementById('editMachineModal'),
closeEditMachineModal: document.getElementById('closeEditMachineModal'),
editMachineTitle: document.getElementById('editMachineTitle'),
machineName: document.getElementById('machineName'),
machineImage: document.getElementById('machineImage'),
installedGamesList: document.getElementById('installedGamesList'),
availableGamesList: document.getElementById('availableGamesList'),
saveMachineBtn: document.getElementById('saveMachineBtn'),
editRoomModal: document.getElementById('editRoomModal'),
closeEditRoomModal: document.getElementById('closeEditRoomModal'),
editRoomTitle: document.getElementById('editRoomTitle'),
roomName: document.getElementById('roomName'),
saveRoomBtn: document.getElementById('saveRoomBtn'),
editNoteModal: document.getElementById('editNoteModal'),
closeEditNoteModal: document.getElementById('closeEditNoteModal'),
editNoteTitle: document.getElementById('editNoteTitle'),
noteContent: document.getElementById('noteContent'),
saveNoteBtn: document.getElementById('saveNoteBtn'),
gamesModal: document.getElementById('gamesModal'),
closeGamesModal: document.getElementById('closeGamesModal'),
gamesModalTitle: document.getElementById('gamesModalTitle'),
gamesList: document.getElementById('gamesList'),
// 添加游戏列表模态框的搜索元素
gamesModalSearch: document.getElementById('gamesModalSearch'),
clearGamesModalSearch: document.getElementById('clearGamesModalSearch'),
selectMachineModal: document.getElementById('selectMachineModal'),
closeSelectMachineModal: document.getElementById('closeSelectMachineModal'),
selectMachineTitle: document.getElementById('selectMachineTitle'),
machineOptions: document.getElementById('machineOptions'),
durationModal: document.getElementById('durationModal'),
closeDurationModal: document.getElementById('closeDurationModal'),
durationTitle: document.getElementById('durationTitle'),
durationOptions: document.getElementById('durationOptions'),
extendPasswordModal: document.getElementById('extendPasswordModal'),
closeExtendPasswordModal: document.getElementById('closeExtendPasswordModal'),
extendMinutes: document.getElementById('extendMinutes'),
extendPasswordInput: document.getElementById('extendPasswordInput'),
confirmExtend: document.getElementById('confirmExtend'),
cancelExtend: document.getElementById('cancelExtend'),
toggleUsedRooms: document.getElementById('toggleUsedRooms'),
// 新增:全局搜索和导出相关元素
globalSearchInput: document.getElementById('globalSearchInput'),
globalSearchButton: document.getElementById('globalSearchButton'),
exportData: document.getElementById('exportData'),
globalSearchResults: document.getElementById('globalSearchResults'),
globalSearchResultsList: document.getElementById('globalSearchResultsList')
};
// 加载数据 (直接使用 PHP 获取的数据)
function loadData() {
// 直接使用 PHP 获取的数据
gameData = <?php echo json_encode($gameData); ?>;
// 确保 machineGames 结构正确
gameData.machines.forEach(machine => {
if (!gameData.machineGames[machine.id]) {
gameData.machineGames[machine.id] = [];
}
});
renderAvailableMachines();
renderGameRooms();
}
// 获取默认数据 (简化)
function getDefaultData() {
return <?php echo json_encode($gameData); ?>;
}
// 修改保存数据函数,使其调用新的 PHP API 脚本
function saveData() {
if (!gameData) return;
// 发送数据到 PHP 脚本
fetch('api/save_data.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(gameData)
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应错误 ' + response.status);
}
return response.text(); // 假设 PHP 返回文本消息
})
.then(data => {
console.log('保存成功:', data);
// showMessage("数据已保存"); // 显示成功消息
// 可以在这里添加其他成功后的逻辑
})
.catch(error => {
console.error('保存失败:', error);
showMessage('保存失败: ' + error.message); // 显示错误消息
});
}
// 设置事件监听器
function setupEventListeners() {
if (elements.backToHome) {
elements.backToHome.addEventListener('click', () => {
window.location.href = 'index.php'; // 修改为 index.php
});
}
if (elements.addRoom) elements.addRoom.addEventListener('click', addRoom);
if (elements.addMachine) elements.addMachine.addEventListener('click', addMachine);
if (elements.editGames) elements.editGames.addEventListener('click', () => {
window.location.href = 'games.php'; // 修改为 games.php
});
if (elements.closeEditMachineModal) elements.closeEditMachineModal.addEventListener('click', () => {
elements.editMachineModal.style.display = 'none';
});
if (elements.saveMachineBtn) elements.saveMachineBtn.addEventListener('click', saveMachine);
if (elements.closeEditRoomModal) elements.closeEditRoomModal.addEventListener('click', () => {
elements.editRoomModal.style.display = 'none';
});
if (elements.saveRoomBtn) elements.saveRoomBtn.addEventListener('click', saveRoom);
if (elements.closeEditNoteModal) elements.closeEditNoteModal.addEventListener('click', () => {
elements.editNoteModal.style.display = 'none';
});
if (elements.saveNoteBtn) elements.saveNoteBtn.addEventListener('click', saveNote);
// 游戏列表模态框事件 (带搜索)
if (elements.closeGamesModal) elements.closeGamesModal.addEventListener('click', () => {
elements.gamesModal.style.display = 'none';
// 关闭时清空搜索框
if (elements.gamesModalSearch) elements.gamesModalSearch.value = '';
});
// 添加游戏列表模态框的搜索事件
if (elements.gamesModalSearch) elements.gamesModalSearch.addEventListener('input', filterGamesInModal);
if (elements.clearGamesModalSearch) elements.clearGamesModalSearch.addEventListener('click', () => {
if (elements.gamesModalSearch) elements.gamesModalSearch.value = '';
filterGamesInModal();
});
if (elements.closeSelectMachineModal) elements.closeSelectMachineModal.addEventListener('click', () => {
elements.selectMachineModal.style.display = 'none';
});
if (elements.closeDurationModal) elements.closeDurationModal.addEventListener('click', () => {
elements.durationModal.style.display = 'none';
});
if (elements.closeExtendPasswordModal) elements.closeExtendPasswordModal.addEventListener('click', () => {
elements.extendPasswordModal.style.display = 'none';
});
if (elements.confirmExtend) elements.confirmExtend.addEventListener('click', checkExtendPassword);
if (elements.cancelExtend) elements.cancelExtend.addEventListener('click', () => {
elements.extendPasswordModal.style.display = 'none';
});
if (elements.extendPasswordInput) elements.extendPasswordInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
checkExtendPassword();
}
});
if (elements.toggleUsedRooms) {
elements.toggleUsedRooms.addEventListener('click', toggleUsedRooms);
}
// 新增:全局搜索和导出事件监听器
if (elements.globalSearchButton) elements.globalSearchButton.addEventListener('click', performGlobalSearch);
if (elements.globalSearchInput) elements.globalSearchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
performGlobalSearch();
}
});
if (elements.exportData) elements.exportData.addEventListener('click', exportCurrentData);
}
// 切换隐藏/显示已使用包厢
function toggleUsedRooms() {
hideUsedRooms = !hideUsedRooms;
if (elements.gameRooms) {
if (hideUsedRooms) {
elements.gameRooms.classList.add('hide-used');
if (elements.toggleUsedRooms) elements.toggleUsedRooms.textContent = '显示已使用包厢';
} else {
elements.gameRooms.classList.remove('hide-used');
if (elements.toggleUsedRooms) elements.toggleUsedRooms.textContent = '隐藏已使用包厢';
}
}
}
// 过滤游戏列表模态框中的游戏
function filterGamesInModal() {
if (!elements.gamesList || !elements.gamesModalSearch) return;
const searchTerm = elements.gamesModalSearch.value.trim().toLowerCase();
const gameItems = elements.gamesList.querySelectorAll('.game-item');
gameItems.forEach(item => {
const gameName = item.querySelector('.game-name')?.textContent.toLowerCase() || '';
if (gameName.includes(searchTerm)) {
item.style.display = '';
} else {
item.style.display = 'none';
}
});
}
// 新增:执行全局搜索
function performGlobalSearch() {
if (!elements.globalSearchInput || !elements.globalSearchResults || !elements.globalSearchResultsList || !gameData) return;