-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·1835 lines (1722 loc) · 82.4 KB
/
Copy pathindex.html
File metadata and controls
executable file
·1835 lines (1722 loc) · 82.4 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
<!DOCTYPE html>
<html lang="en">
<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">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="theme-color" content="#0e2422">
<title>雀阁 · 纸牌房</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Ma+Shan+Zheng&family=Noto+Serif+SC:wght@400;600;700&family=Noto+Sans+SC:wght@400;500;600&family=ZCOOL+XiaoWei&family=JetBrains+Mono:wght@500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/css/theme.css">
<link rel="stylesheet" href="/css/style.css?v=layout-20260626-8">
</head>
<body class="theme-guofeng">
<div id="app" v-cloak>
<!-- 登录界面 -->
<div class="full-screen login-wrapper" v-if="where === 0">
<div class="login-panel layout-center">
<div class="row title">
雀阁
</div>
<template v-if="isAutoLogin">
<div class="auto-login">正在使用 ZWWX.CLUB 登录,请稍候…</div>
<div class="row" style="margin-top:14px;text-align:center;">
<a href="javascript:;" @click="cancelAutoLogin()" style="color:#888;font-size:12px;">迟迟无法进入?点此取消并改用其他方式</a>
</div>
</template>
<template v-else-if="!guestMode">
<div v-if="loginError" class="login-error" style="margin:8px 0 12px;padding:10px 12px;background:#3b1f1f;border:1px solid #8a3a3a;color:#ffb3b3;border-radius:6px;font-size:13px;line-height:1.5;text-align:left;">
<div style="font-weight:bold;margin-bottom:4px;">登录失败</div>
<div>{{loginError}}</div>
<div v-if="debugMode" style="margin-top:6px;color:#aaa;font-size:11px;word-break:break-all;">token 片段:{{tokenSnippet || '(无)'}}</div>
</div>
<div class="login-form" style="display:flex;flex-direction:column;gap:12px;align-items:center;">
<button @click="goDiscuzLogin">使用 ZWWX.CLUB 账号登录</button>
<button class="btn-ghost" @click="guestMode = true">以访客身份进入</button>
</div>
</template>
<template v-else>
<div class="login-form">
<input type="text" class="input" placeholder="请输入您的雅号(访客)" v-model.trim="posState.self.name" @keyup.enter="login"><button
@click="login">入 座</button>
</div>
<div class="row" style="margin-top:8px;text-align:center;">
<a href="javascript:;" @click="guestMode = false" style="color:#888;font-size:12px;">返回登录方式选择</a>
</div>
</template>
</div>
</div>
<!-- 大厅 -->
<div class="full-screen house" v-if="where === 1">
<div class="row text-right quick-bar">
<div class="quick-brand">
<strong>雀阁</strong>
<span>纸牌房</span>
</div>
<span v-if="myUser && myUser.username" class="user-badge" :title="'已用 Discuz 账号登录 (uid=' + myUser.uid + ')'">{{myUser.username}}</span>
<button class="btn-ghost btn-mute" type="button" @click="toggleMute"
:title="muted ? '开启音效' : '静音'">{{muted ? '♪ 静音' : '♪ 音效'}}</button>
<button class="btn-ghost" type="button" @click="openStats">我的战绩</button>
<button class="btn-ghost" type="button" @click="openRules">玩法规则</button>
<button @click="quickJoin">快速入局</button>
</div>
<div class="hall-shell">
<div class="hall-hero">
<div>
<div class="hall-kicker">多人纸牌 · 动态房间</div>
<h1>{{gameTypeName(selectedGameType)}}大厅</h1>
<p>{{selectedGameType === 'guandan' ? '四人两副牌,对家配合,支持级牌与逢人配。' : '三人经典斗地主,支持 AI 陪玩、智囊推荐和观战。'}}</p>
</div>
<div class="hall-stats">
<div>
<strong>{{lobbyStats.open}}</strong>
<span>公开房</span>
</div>
<div>
<strong>{{lobbyStats.players}}</strong>
<span>在线座位</span>
</div>
<div>
<strong>{{lobbyStats.playing}}</strong>
<span>对局中</span>
</div>
</div>
</div>
<div class="hall-actions">
<div class="mode-tabs">
<button type="button" :class="{active:selectedGameType==='doudizhu'}" @click="selectedGameType='doudizhu'">斗地主</button>
<button type="button" :class="{active:selectedGameType==='guandan'}" @click="selectedGameType='guandan'">掼蛋</button>
</div>
<button type="button" class="btn-vermilion" @click="createRoom(false)">开公开房</button>
<button type="button" class="btn-ghost" @click="createRoom(true)">开私密房</button>
<div class="room-code-join">
<input type="text" class="input" maxlength="6" placeholder="输入房号" v-model.trim="roomCodeInput" @keyup.enter="joinRoomByCode">
<button type="button" @click="joinRoomByCode">加入</button>
</div>
</div>
<div v-if="!filteredRooms.length" class="empty-hall">
<strong>{{gameTypeName(selectedGameType)}}暂无公开房</strong>
<span>可以直接快速入局,系统会自动创建并入座。</span>
</div>
<div class="room-grid" v-if="filteredRooms.length">
<div v-for="desk in filteredRooms" class="desk room-card" :class="{'desk-busy': deskBusyCount(desk) > 0}">
<div class="room-card-head">
<span>{{desk.gameLabel || gameTypeName(desk.gameType)}}</span>
<b>#{{desk.roomCode || desk.deskId}}</b>
</div>
<div class="room-card-meta">
<span>{{deskBusyCount(desk)}} / {{desk.seatCount || desk.positions.length}} 人</span>
<span v-if="desk.gameType === 'guandan'">打 {{desk.guandanLevelLabel || '2'}}</span>
<span>{{roomStatusText(desk)}}</span>
</div>
<div class="seat-strip">
<button v-for="position in desk.positions" type="button" class="seat-chip" :class="{filled: position.state > 0, ready: position.state === 2}"
@click="sitDown(desk.deskId,position)" :title="position.userName || '空位'">
{{seatInitial(position)}}
</button>
</div>
<div class="room-card-foot">
<button type="button" class="btn-ghost" @click="copyRoomCode(desk.roomCode || desk.deskId)">复制房号</button>
<button type="button" v-if="deskBusyCount(desk) > 0" class="btn-ghost" @click.stop="spectate(desk.deskId)">观战</button>
<button type="button" @click="joinOpenSeat(desk)">入房</button>
</div>
</div>
</div>
</div>
</div>
<!-- 房间 -->
<div class="full-screen room" v-if="where === 2" :class="{'room-spec': isSpec, 'room-guandan': gameType === 'guandan', 'room-playing': roomState.state > 0 && roomState.state < 3, 'room-waiting': roomState.state === 0 || roomState.state === 3}">
<button class="btn-exit-room" @click="exitRoom">{{isSpec ? '退出观战' : '返回大厅'}}</button>
<span v-if="myUser && myUser.username" class="user-badge user-badge-room" :title="'已用 Discuz 账号登录 (uid=' + myUser.uid + ')'">{{myUser.username}}</span>
<div v-if="isSpec" class="spec-badge">观 战 模 式</div>
<div class="room-topbar">
<div class="room-title">
<strong>{{gameTypeName(gameType)}}</strong>
<span>房号 {{roomCode || deskId}}</span>
<span v-if="gameType === 'guandan'">打 {{guandanLevelLabel}}</span>
</div>
<div class="room-top-actions">
<span>{{currentRoomPlayers}} / {{gameType === 'guandan' ? 4 : 3}} 人</span>
<button type="button" class="btn-ghost" @click="copyRoomCode(roomCode || deskId)">复制房号</button>
<button type="button" class="btn-ghost" @click="openRules">规则</button>
</div>
</div>
<!-- 掼蛋队伍计分板 -->
<div class="guandan-board" v-if="gameType === 'guandan'">
<div class="guandan-board-title">掼蛋记分</div>
<div class="guandan-level">当前打 <strong>{{guandanLevelLabel}}</strong></div>
<div class="guandan-team-row" v-for="team in guandanTeams" :class="{active: team.score > 0}">
<div>
<strong>{{team.name}}</strong>
<span>{{team.members}}</span>
</div>
<b>+{{team.score}}</b>
</div>
<div class="guandan-order" v-if="guandanLastOrder.length">
<span>上局名次</span>
<em>{{guandanLastOrder.join(' / ')}}</em>
</div>
</div>
<!-- 累计记分板 -->
<div class="score-board" v-if="gameType === 'doudizhu' && scoreList.length">
<div class="score-board-title">本桌积分</div>
<div class="score-board-row" v-for="row in scoreList" :key="row.name">
<span class="score-board-name">{{row.name}}</span>
<span class="score-board-num" :class="{ pos: row.total > 0, neg: row.total < 0 }">
{{row.total > 0 ? '+' + row.total : row.total}}
</span>
</div>
</div>
<div class="btn-group" v-if="!isSpec && roomState.state > 0 && roomState.state < 3 && roomState.ctxPos === 'self'">
<span class="clock">{{roomState.timeout}}</span>
<template v-if="roomState.state === 1">
<button class="btn btn-call" v-for="score in roomState.ctxScore" @click="callScore(score)">{{score}}分</button>
<button class="btn btn-call" @click="callScore(0)">不叫</button>
</template>
<template v-if="roomState.state === 2">
<button class="btn btn-vermilion" @click="playCards">出 牌</button>
<button class="btn btn-ghost btn-ai" type="button" @click="aiSuggest" title="智囊推荐">智 囊</button>
<button class="btn btn-jade" @click="passCards" v-if="roomState.ctxCard.len && roomState.ctxCard.ctxPos !== roomState.ctxPos">不 出</button>
</template>
</div>
<button v-if="!isSpec && posState.self.state < 2" @click="prepare" class="btn-prepare">准 备</button>
<!-- 等待区操作:召唤AI / 请走AI -->
<div class="bot-bar" v-if="!isSpec && (roomState.state === 0 || roomState.state === 3)">
<button v-if="hasEmptySeat" class="btn-bot btn-bot-add" type="button" @click="addBots">{{gameType === 'guandan' ? '召 唤 A I 补 位' : '召 唤 A I 对 手'}}</button>
<button v-if="hasBotSeat" class="btn-bot btn-bot-remove" type="button" @click="removeBots">请 走 A I</button>
</div>
<div v-if="isSpec && roomState.state === 0" class="spec-tip">本桌正在准备中,待开局后可观战。</div>
<div class="card-groups" v-if="roomState.state">
<!-- 自己的牌列表 -->
<div class="card-group card-group-self" :style="handGroupStyle(posState.self.cards, 'self')" v-if="!isSpec && !(roomState.state === 3 && posState.self.state === 2)">
<div @dragstart.prevent
@mousedown.prevent="dragSelectStart(card, $event)"
@mouseenter="dragSelectOver(card)"
@touchstart.prevent="dragSelectStart(card, $event)"
@touchmove.prevent="dragSelectTouchMove($event)"
v-for="(card,index) in posState.self.cards"
class="card" :class="'card-' + card.value + '-' + card.type" :data-card-key="card.value + '_' + card.type + '_' + (card.deck || 0)" :style="{left:index * handGap(posState.self.cards, 'self') + 'px',top:card.selected ? '-20px' : 0}">
</div>
</div>
<!-- 左家的牌列表 -->
<div class="card-group card-group-left" :style="handGroupStyle(posState.left.cards, 'side')">
<div @dragStart=" dragStart($event)" v-for="(card,index) in posState.left.cards" class="card" :class="roomState.state === 3 ? 'card-' + card.value + '-' + card.type : 'card-unknow'"
:style="{left:index * handGap(posState.left.cards, 'side') + 'px'}">
</div>
<div class="icon-group icon-group-left text-left" v-if="roomState.ctxPos == 'left' && roomState.state < 3">
<span class="clock">{{roomState.timeout}}</span>
</div>
<div class="text-tips text-tips-left text-left" v-if="roomState.state < 3">剩余:{{posState.left.cards.length}}张</div>
</div>
<!-- 右家的牌列表 -->
<div class="card-group card-group-right" :style="handGroupStyle(posState.right.cards, 'side')">
<div @dragStart="dragStart($event)" v-for="(card,index) in posState.right.cards" class="card" :class="roomState.state === 3 ? 'card-' + card.value + '-' + card.type : 'card-unknow'"
:style="{left:index * handGap(posState.right.cards, 'side') + 'px'}">
</div>
<div class="icon-group icon-group-right text-right" v-if="roomState.ctxPos == 'right' && roomState.state < 3">
<span class="clock">{{roomState.timeout}}</span>
</div>
<div class="text-tips text-tips-right text-right" v-if="roomState.state < 3">剩余:{{posState.right.cards.length}}张</div>
</div>
<!-- 对家/上方玩家(掼蛋) -->
<div class="card-group card-group-top card-group-up" v-if="gameType === 'guandan'" :style="handGroupStyle(posState.top.cards, 'top')">
<div @dragStart="dragStart($event)" v-for="(card,index) in posState.top.cards" class="card" :class="roomState.state === 3 ? 'card-' + card.value + '-' + card.type : 'card-unknow'"
:style="{left:index * handGap(posState.top.cards, 'top') + 'px'}">
</div>
<div class="icon-group icon-group-top text-center" v-if="roomState.ctxPos == 'top' && roomState.state < 3">
<span class="clock">{{roomState.timeout}}</span>
</div>
<div class="text-tips text-tips-top text-center" v-if="roomState.state < 3">剩余:{{posState.top.cards.length}}张</div>
</div>
<!-- 斗地主底牌列表 -->
<div class="card-group card-group-top" v-if="gameType === 'doudizhu'" :style="handGroupStyle(posState.kitty.cards, 'kitty')">
<div @dragStart="dragStart($event)" v-for="(card,index) in posState.kitty.cards" class="card" :style="{left:index * handGap(posState.kitty.cards, 'kitty') + 'px'}"
:class="roomState.state >= 2 ? 'card-' + card.value + '-' + card.type : ' card-unknow' ">
</div>
</div>
</div>
<!-- 出牌区域 -->
<div class="screen-center">
<!-- 左家的出牌区域 -->
<div class="card-ctx card-ctx-left" v-if="(roomState.state === 2 && (posState.left.ctxCards.length || posState.left.isPass)) || (roomState.state === 1 && posState.left.callScore > -1)" :style="handGroupStyle(posState.left.ctxCards, 'ctxSide')">
<template v-if="roomState.state === 2">
<div v-if="!posState.left.isPass" @dragStart="dragStart($event)" v-for="(card,index) in posState.left.ctxCards"
class="card" :class="'card-' + card.value + '-' + card.type" :style="{left:index * handGap(posState.left.ctxCards, 'ctxSide') + 'px'}">
</div>
<div v-if="posState.left.isPass" class="score-tipe pass-tipe">
不出
</div>
</template>
<span class="score-tipe" v-if="roomState.state == 1 && posState.left.callScore > -1">{{posState.left.callScore
> 0 ? posState.left.callScore + '分' : '不叫' }}</span>
</div>
<!-- 自己的出牌区域 -->
<div class="card-ctx card-ctx-self" v-if="(roomState.state === 2 && (posState.self.ctxCards.length || posState.self.isPass)) || (roomState.state === 1 && posState.self.callScore > -1)" :style="handGroupStyle(posState.self.ctxCards, 'ctxSelf')">
<template v-if="roomState.state === 2">
<div v-if="!posState.self.isPass" @dragStart="dragStart($event)" v-for="(card,index) in posState.self.ctxCards"
class="card" :class="'card-' + card.value + '-' + card.type" :style="{left:index * handGap(posState.self.ctxCards, 'ctxSelf') + 'px'}">
</div>
<div v-if="posState.self.isPass" class="score-tipe pass-tipe">
不出
</div>
</template>
<span class="score-tipe" v-if="roomState.state == 1 && posState.self.callScore > -1">
{{posState.self.callScore
> 0 ? posState.self.callScore + '分' : '不叫' }}
</span>
</div>
<!-- 右家的出牌区域 -->
<div class="card-ctx card-ctx-right" v-if="(roomState.state === 2 && (posState.right.ctxCards.length || posState.right.isPass)) || (roomState.state === 1 && posState.right.callScore > -1)" :style="handGroupStyle(posState.right.ctxCards, 'ctxSide')">
<template v-if="roomState.state === 2">
<div v-if="!posState.right.isPass" @dragStart="dragStart($event)" v-for="(card,index) in posState.right.ctxCards"
class="card" :class="'card-' + card.value + '-' + card.type" :style="{left:index * handGap(posState.right.ctxCards, 'ctxSide') + 'px'}">
</div>
<div v-if="posState.right.isPass" class="score-tipe pass-tipe">
不出
</div>
</template>
<span class="score-tipe" v-if="roomState.state == 1 && posState.right.callScore > -1">{{posState.right.callScore
> 0 ? posState.right.callScore + '分' : '不叫' }}</span>
</div>
<!-- 上家的出牌区域(掼蛋) -->
<div class="card-ctx card-ctx-top" v-if="gameType === 'guandan' && roomState.state === 2 && (posState.top.ctxCards.length || posState.top.isPass)" :style="handGroupStyle(posState.top.ctxCards, 'ctxTop')">
<template v-if="roomState.state === 2">
<div v-if="!posState.top.isPass" @dragStart="dragStart($event)" v-for="(card,index) in posState.top.ctxCards"
class="card" :class="'card-' + card.value + '-' + card.type" :style="{left:index * handGap(posState.top.ctxCards, 'ctxTop') + 'px'}">
</div>
<div v-if="posState.top.isPass" class="score-tipe pass-tipe">
不出
</div>
</template>
</div>
</div>
<!-- 玩家头像 -->
<div class="players">
<div class="screen-center">
<div class="player-wrapper player-top" v-if="gameType === 'guandan' && posState.top.state">
<div class="player-photo" :class="{'player-photo-bot': posState.top.isBot}" :style="playerPhotoStyle(posState.top)">
<span class="bot-tag" v-if="posState.top.isBot">AI</span>
<span class="team-tag team-ally">队友</span>
</div>
<div class="player-name text-center">{{posState.top.name}}</div>
<div class="text-center player-status" v-if="posState.top.state === 2 && (roomState.state === 0 || roomState.state === 3)">准备</div>
</div>
<div class="player-wrapper player-left" v-if="posState.left.state">
<div class="player-photo" :class="{'player-photo-king':posState.left.isDizhu, 'player-photo-bot': posState.left.isBot}" :style="playerPhotoStyle(posState.left)">
<span class="bot-tag" v-if="posState.left.isBot">AI</span>
<span class="team-tag team-rival" v-if="gameType === 'guandan'">对手</span>
</div>
<div class="player-name text-center">{{posState.left.name}}</div>
<div class="text-center player-status" v-if="posState.left.state === 2 && (roomState.state === 0 || roomState.state === 3)">准备</div>
<!-- <div class="text-center" v-if="posState.left.isDizhu">
<img src="images/dizhu.png" alt="">
</div> -->
</div>
<div class="player-wrapper player-right" v-if="posState.right.state">
<div class="player-photo" :class="{'player-photo-king':posState.right.isDizhu, 'player-photo-bot': posState.right.isBot}" :style="playerPhotoStyle(posState.right)">
<span class="bot-tag" v-if="posState.right.isBot">AI</span>
<span class="team-tag team-rival" v-if="gameType === 'guandan'">对手</span>
</div>
<div class="player-name text-center">{{posState.right.name}}</div>
<div class="text-center player-status" v-if="posState.right.state === 2 && (roomState.state === 0 || roomState.state === 3)">准备</div>
<!-- <div class="text-center" v-if="posState.right.isDizhu">
<img src="images/dizhu.png" alt="">
</div> -->
</div>
</div>
<div class="player-wrapper player-self-ctx" v-if="!isSpec && roomState.state > 0 && !(roomState.state === 3 && posState.self.state === 2)">
<div class="player-photo" :class="{'player-photo-king':posState.self.isDizhu}" :style="playerPhotoStyle(posState.self)"></div>
<div class="player-name text-center">{{posState.self.name}}</div>
</div>
<div class="player-wrapper player-self" v-if="roomState.state === 0 || (roomState.state === 3 && posState.self.state === 2)">
<div class="player-photo" :class="{'player-photo-king':posState.self.isDizhu}" :style="playerPhotoStyle(posState.self)"></div>
<div class="player-name text-center">{{posState.self.name}}</div>
<div class="text-center player-status" v-if="posState.self.state === 2 && (roomState.state === 0 || roomState.state === 3)">准备</div>
<!-- <div class="text-center" v-if="posState.self.isDizhu">
<img src="images/dizhu.png" alt="">
</div> -->
</div>
</div>
<div class="msg-box" :class="{collapsed: chatCollapsed}">
<div class="msg-box-head">
<span class="msg-box-title">茶馆 · 闲话</span>
<button class="msg-box-toggle" type="button" @click="chatCollapsed = !chatCollapsed"
:title="chatCollapsed ? '展开聊天' : '收起聊天'">
<span v-if="chatCollapsed">▴</span><span v-else>▾</span>
</button>
</div>
<div class="msg-body">
<div class="msg-list scroll-bar" ref="msgBox">
<div class="msg-item"
v-for="msg in msgList" :key="msg.id"
:class="msg.type === 'SYS' ? 'msg-sys' : (msg.posId === posId ? 'msg-user msg-self' : 'msg-user msg-other')">
<template v-if="msg.type === 'SYS'">
<span class="msg-sys-stamp">系</span>
<span class="msg-sys-text">{{msg.content}}</span>
</template>
<template v-else>
<div class="msg-meta">
<span class="msg-name">{{msg.name}}</span>
<span class="msg-time">{{msg.time}}</span>
</div>
<div class="msg-bubble">{{msg.content}}</div>
</template>
</div>
</div>
<div class="msg-foot">
<input type="text" class="msg-input" ref="msgInput" placeholder="说点什么…" maxlength="120"
@keyup.enter="sendMessage(false)">
<button class="msg-send" type="button" @click="sendMessage(false)">发送</button>
</div>
</div>
</div>
</div>
<div class="landscape-lock" v-if="where === 2">
<div class="landscape-lock-panel">
<span class="landscape-lock-icon">↺</span>
<div class="landscape-lock-title">请横屏游戏</div>
<div class="landscape-lock-text">手机端牌桌只支持横屏布局,旋转屏幕后继续对局。</div>
</div>
</div>
</div>
<script>
function getURLParam(name) {
return new URLSearchParams(window.location.search).get(name);
}
</script>
<script src="/js/vue.min.js"></script>
<script src="socket.io/socket.io.js"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/layer/layer.js"></script>
<script src="/js/parser.js"></script>
<script src="/js/ai-suggest.js?v=20260626-1"></script>
<script src="/js/guandan-suggest.js?v=20260626-2"></script>
<script src="/js/effects.js?v=20260626-2"></script>
<script>
function _getCookie(name) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match) return decodeURIComponent(match[2]);
return null;
}
// 跨域 SSO:优先从 URL hash (#token=xxx) 拿,其次 localStorage,最后才是 cookie
function _getDiscuzToken() {
try {
var hash = location.hash || '';
var m = hash.match(/[#&]token=([^&]+)/);
if (m) {
var t = decodeURIComponent(m[1]);
try { localStorage.setItem('discuz_token', t); } catch (e) {}
// 从 URL 上抹掉 token,避免被复制分享
try {
var clean = hash.replace(/([#&])token=[^&]+&?/, '$1').replace(/[#&]$/, '');
history.replaceState(null, '', location.pathname + location.search + (clean && clean !== '#' ? clean : ''));
} catch (e) {}
return t;
}
var ls = null;
try { ls = localStorage.getItem('discuz_token'); } catch (e) {}
if (ls) return ls;
} catch (e) {}
return _getCookie('discuz_token') || '';
}
function createClient(url) {
var token = _getDiscuzToken();
// Let socket.io pick proper transport and protocol; pass token via `auth`
try {
var socket = io.connect(location.protocol + '//' + url, { auth: { token: token } });
} catch (e) {
// fallback to simple connect
var socket = io.connect('ws://' + url);
}
return socket;
}
var vm = new Vue({
el: "#app",
data: function () {
return {
msgList: [],//聊天消息
chatCollapsed: false,//聊天面板收起态
_msgSeq: 0,//本地消息序号兜底,避免 :key 冲突
isSpec: false,//是否处于观战模式
muted: false,//全局静音
scoreBoard: {},//本桌累计积分 { name: number }
scoreSeen: [],//本桌出现过的玩家名顺序,保证显示稳定
lastRoundDelta: null,//上一局的得分明细 [{name,delta}]
guandanScore: {
team0: 0,
team1: 0
},
guandanLastOrder: [],
where: 0,//0登录界面 1大厅 2房间,
isAutoLogin: false,
guestMode: false,// 选择以访客身份进入
loginError: '',//登录错误持久横幅
debugMode: /[?&]debug=1\b/.test(location.search),//?debug=1 显示调试信息
tokenSnippet: '',//最近一次握手用的 token 前后段(仅在 debug 显示)
// 跨域 SSO 桥接入口:论坛域名上的 bridge.php
discuzLoginUrl: 'https://zwwx.club/discuz-sso/bridge.php',
// 我的战绩
myScore: null,
// 当前登录用户信息(仅 SSO 自动登录时填充)
myUser: null,
topList: [],
topLists: { doudizhu: [], guandan: [] },
myScores: { doudizhu: null, guandan: null },
posId: '',//座位号
deskId: '',//桌号
roomCode: '',
gameType: 'doudizhu',
selectedGameType: 'doudizhu',
roomCodeInput: '',
guandanLevelLabel: '2',
guandanLevelRank: 15,
desks: [],
client: '',
viewportWidth: window.innerWidth || 1280,
cards: [],
//房间状态
roomState: {
state: 0,//0准备状态 1叫分状态 2打牌状态 3结束状态
ctxPos: '', //当前该哪个座位谁出牌或叫分 left right or self
ctxCard: { //上家玩家的牌型
len: 0,
key: '',
type: '',
ctxPos: ''
},
ctxScore: [],
timeout: 15,
},
//座位状态
posState: {
kitty: {
cards: []
},
top: {
state: 0,
cards: [],
ctxCards: [],
isPass: false,
isDizhu: false,
isBot: false,
callScore: -1,
avatarUrl: '',
name: '游客'
},
left: {
state: 0,//0没人,1未准备 2准备
cards: [],
ctxCards: [],
isPass: false,
isDizhu: false,
isBot: false,
callScore: -1,
avatarUrl: '',
name: '游客'
},
right: {
state: 0,//0没人,1未准备 2准备
cards: [],
ctxCards: [],
isPass: false,
isDizhu: false,
isBot: false,
callScore: -1,
avatarUrl: '',
name: '游客'
},
self: {
state: 0,//0没人,1未准备 2准备
cards: [],
ctxCards: [],
isPass: false,
isDizhu: false,
isBot: false,
callScore: -1,
avatarUrl: '',
name: ''
}
}
}
},
mounted: function () {
var self = this;
this.$nextTick(function () {
document.oncontextmenu = function (e) {
e.preventDefault();
self.playCards();
};
// 拖拽多选:松开鼠标/手指时结束本次选择
window.addEventListener('mouseup', function () { self.dragSelectEnd(); });
window.addEventListener('touchend', function () { self.dragSelectEnd(); });
window.addEventListener('touchcancel', function () { self.dragSelectEnd(); });
window.addEventListener('resize', function () {
self.viewportWidth = window.innerWidth || 1280;
});
// if Discuz token exists, mark as auto-login and the server will validate it
var _token = _getDiscuzToken();
if (_token) {
this.isAutoLogin = true;
// debug 模式记录 token 片段
this.tokenSnippet = _token.length > 24 ? (_token.slice(0, 12) + '...' + _token.slice(-8)) : _token;
// 控制台输出便于排查
console.log('[login] token detected, length=' + _token.length + ', snippet=' + this.tokenSnippet);
// fallback to manual login if token doesn't produce LOGIN_SUCCESS quickly
this._autoLoginTimer = setTimeout(function () {
if (this.where === 0 && this.isAutoLogin) {
this.cancelAutoLogin('登录超时(5 秒内服务器无响应)。可能原因:服务端 JWT_SECRET 与论坛侧不一致 / token 已过期 / 服务端未安装 jsonwebtoken。请查看服务端日志。');
}
}.bind(this), 5000);
}
this.client = createClient(location.host);
// socket 连接失败:避免无限"正在登录…"
this.client.on('connect_error', function (err) {
if (this.isAutoLogin) {
this.cancelAutoLogin('网络异常:' + (err && err.message ? err.message : '无法连接服务器'));
}
}.bind(this));
this.client.on('MESSAGE', function (data) {
layer.msg(data.msg);
}.bind(this));
this.client.on('LOGIN_SUCCESS', function (data) {
this.desks = data;
this.where = 1;
this.isAutoLogin = false;
if (this._autoLoginTimer) { clearTimeout(this._autoLoginTimer); this._autoLoginTimer = null; }
layer.closeAll();
}.bind(this));
// 服务端推送的个人战绩
this.client.on('MY_SCORE', function (row) {
this.myScore = row || null;
if (row && row.gameType) {
this.$set(this.myScores, row.gameType, row);
}
}.bind(this));
// SSO 自动登录后服务端会推送 WHOAMI
this.client.on('WHOAMI', function (data) {
this.myUser = data || null;
// 预填自己的座位名,坐下后头像名称、聊天等都会用这个
if (data && data.username) {
this.posState.self.name = data.username;
}
if (data && data.avatarUrl) {
this.posState.self.avatarUrl = data.avatarUrl;
}
}.bind(this));
this.client.on('LOGIN_FAIL', function (data) {
layer.closeAll();
if (this.isAutoLogin) {
this.cancelAutoLogin(data && data.msg ? data.msg : '自动登录失败');
} else {
layer.msg(data.msg);
}
}.bind(this));
this.client.on('ROOM_CREATED', function (data) {
if (data && data.isPrivate && data.roomCode) {
layer.msg('私密房已创建:' + data.roomCode, { time: 1400 });
}
}.bind(this));
this.client.on('QUICK_JOIN', function (data) {
if (data.success) {
this.client.emit('SITDOWN', { deskId: data.deskId, posId: data.posId })
} else {
layer.closeAll();
layer.msg('快速加入失败');
}
}.bind(this));
this.client.on('SITDOWN_SUCCESS', function (data) {
this.where = 2;
this.posId = data.posId;
this.deskId = data.deskId;
this.roomCode = data.roomCode || data.deskId;
this.gameType = data.gameType || 'doudizhu';
this.guandanLevelLabel = data.guandanLevelLabel || '2';
this.guandanLevelRank = data.guandanLevelRank || this.rankFromLabel(this.guandanLevelLabel);
(data.positions || data.posInfos || []).forEach(function (pos) {
this.updatePosStatus(pos.posId, pos.state, pos.userName, !!pos.isBot, pos.avatarUrl);
}.bind(this))
this.updatePosStatus(data.posId, 1, this.posState.self.name || (this.myUser && this.myUser.username) || '游客', false, (this.myUser && this.myUser.avatarUrl) || this.posState.self.avatarUrl || '');
this.posState.self.isDizhu = false;
//this.msgList = [];
this.$nextTick(function(){
this.$refs.msgSelect.value = '';
});
layer.closeAll();
}.bind(this));
this.client.on('SITDOWN_ERROR', function (data) {
layer.closeAll();
layer.msg(data.msg);
}.bind(this));
this.client.on('UNSITDOWN_SUCCESS', function (data) {
this.resetRoomStatus();
this.desks = data;
layer.closeAll();
}.bind(this));
// 观战进入成功
this.client.on('SPECTATE_SUCCESS', function (data) {
this.where = 2;
this.deskId = data.deskId;
this.roomCode = data.roomCode || data.deskId;
this.gameType = data.gameType || 'doudizhu';
this.guandanLevelLabel = data.guandanLevelLabel || '2';
this.guandanLevelRank = data.guandanLevelRank || this.rankFromLabel(this.guandanLevelLabel);
this.isSpec = true;
this.posId = 'spec';
// 初始化座位状态名字
(data.positions || []).forEach(function (p) {
this.updatePosStatus(p.posId, p.state, p.userName, !!p.isBot, p.avatarUrl);
}.bind(this));
this.posState.self.isDizhu = false;
this.$nextTick(function () {
if (this.$refs.msgSelect) this.$refs.msgSelect.value = '';
});
// 牌局已在进行中:套用快照恢复牌桌
if (data.gameInProgress && data.snapshot) {
this.applySpectateSnapshot(data.snapshot);
}
layer.closeAll();
layer.msg('已进入观战', { time: 1200 });
}.bind(this));
this.client.on('SPECTATE_ERROR', function (data) {
layer.closeAll();
layer.msg(data.msg || '观战失败');
}.bind(this));
this.client.on('REFRESH_LIST', function (data) {
this.desks = data;
}.bind(this));
this.client.on('STATUS_CHANGE', function (data) {
this.updateHouseStatus(data.deskId, data.posId, data.state);
}.bind(this));
this.client.on('POS_STATUS_CHANGE', function (data) {
var direct = this.getDirectionByPosId(data.posId);
this.updatePosStatus(data.posId, data.state, data.userName, data.isBot, data.avatarUrl);
}.bind(this));
this.client.on('POS_STATUS_RESET', function (data) {
data.pos.forEach(function (pos) {
this.updatePosStatus(pos.posId, data.state);
}.bind(this));
}.bind(this));
this.client.on('ROOM_STATUS_CHANGE', function (data) {
this.roomState.state = data.state;
}.bind(this));
this.client.on('FORCE_EXIT_EV', function (data) {
layer.msg(data.msg);
this.roomState.state = 3;
this.posState.left.callScore = -1;
this.posState.right.callScore = -1;
this.posState.self.callScore = -1;
var direct = this.getDirectionByPosId(data.posId);
this.posState[direct].ctxCards = [];
this.posState[direct].cards = [];
this.startTimer(false);
}.bind(this));
this.client.on('PREPARE_SUCCESS', function (data) {
this.posState.self.state = 2;
layer.closeAll();
}.bind(this));
//游戏开始
this.client.on('GAME_START', function (data) {
this.gameType = data.gameType || this.gameType || 'doudizhu';
this.roomState.state = this.gameType === 'guandan' ? 2 : 1;
if (this.gameType === 'guandan') {
this.guandanLevelLabel = data.levelLabel || this.guandanLevelLabel || '2';
this.guandanLevelRank = data.levelRank || this.rankFromLabel(this.guandanLevelLabel);
this.roomState.ctxPos = this.getDirectionByPosId(data.ctxPos);
this.roomState.ctxCard = { len: 0, key: '', type: '', ctxPos: '' };
}
this.initCards(data.cards);
this.posState.left.callScore = -1;
this.posState.right.callScore = -1;
this.posState.top.callScore = -1;
this.posState.self.callScore = -1;
this.posState.left.isPass = false;
this.posState.right.isPass = false;
this.posState.top.isPass = false;
this.posState.self.isPass = false;
this.posState.left.isDizhu = false;
this.posState.right.isDizhu = false;
this.posState.top.isDizhu = false;
this.posState.self.isDizhu = false;
this.posState.left.ctxCards = [];
this.posState.right.ctxCards = [];
this.posState.top.ctxCards = [];
this.posState.self.ctxCards = [];
// —— 发牌音效 ——
if (window.FX) {
FX.beep('deal');
setTimeout(function () { window.FX && FX.beep('deal'); }, 220);
}
}.bind(this));
//叫分事件
this.client.on('CTX_USER_CHANGE', function (data) {
this.updateCtxInfo(data);
}.bind(this));
//显示底牌事件
this.client.on('SHOW_TOP_CARD', function (data) {
this.roomState.state = 2;
var direct = this.getDirectionByPosId(data.dizhuPosId);
if (direct == 'self') {
data.topCards.forEach(function (card) {
card.selected = true;
})
}
this.posState[direct].cards = this.posState[direct].cards.concat(data.topCards).sort(function (a, b) {
return a.value - b.value;
});
this.posState.kitty.cards = data.topCards;
this.roomState.ctxPos = direct;
this.posState[direct].isDizhu = true;
this.roomState.timeout = data.timeout;
this.startTimer(this.autoPlayCards.bind(this));
// —— 身份登场特效(地主 / 农民 因人而异)——
if (window.FX) {
if (direct === 'self') {
FX.flash('地 主', { cls: 'fx-king-emerge', life: 1600 });
} else {
FX.flash('农 民', { cls: 'fx-farmer-emerge', life: 1600 });
}
FX.beep('call');
}
}.bind(this));
this.client.on('CTX_PLAY_CHANGE', function (data) {
var direct = this.getDirectionByPosId(data.ctxData.posId);
this.posState[direct].ctxCards = data.ctxData.cards;
this.posState[direct].isPass = data.isPass;
if (data.trickReset) {
this.roomState.ctxCard = { len: 0, key: '', type: '', ctxPos: '' };
this.posState.left.isPass = false;
this.posState.right.isPass = false;
this.posState.top.isPass = false;
this.posState.self.isPass = false;
}
if (!data.isPass) {
this.roomState.ctxCard.len = data.ctxData.len;
this.roomState.ctxCard.key = data.ctxData.key;
this.roomState.ctxCard.type = data.ctxData.type;
this.roomState.ctxCard.ctxPos = direct;
}
this.removeCards(direct, data.ctxData.cards);
this.roomState.ctxPos = this.getDirectionByPosId(data.posId);
//如果是自己出牌就清空上一轮自己出的牌
if (this.roomState.ctxPos === 'self') {
this.posState.self.ctxCards = [];
}
this.posState[this.roomState.ctxPos].isPass = false;
this.roomState.timeout = data.timeout;
this.startTimer(this.autoPlayCards.bind(this));
// —— 特效与音效 ——
if (window.FX) {
if (data.isPass) {
FX.play('PASS', { isPass: true });
} else if (data.ctxData.type) {
FX.play(data.ctxData.type, { posDir: direct });
}
}
}.bind(this));
this.client.on('PLAY_CARD_ERROR', function (data) {
layer.msg('你的牌不符合规则');
}.bind(this))
this.client.on('PLAY_CARD_SUCCESS', function (cards) {
this.removeCards('self', cards);
this.posState.self.ctxCards = cards;
}.bind(this))
this.client.on('GAME_OVER', function (data) {
if ((data && data.gameType) === 'guandan' || this.gameType === 'guandan') {
var myTeam = Number(this.posId) % 2;
var winTeam = data.winner && data.winner.length ? data.winner[0] % 2 : -1;
var iWonGd = this.isSpec ? false : myTeam === winTeam;
var orderText = (data.finishOrder || []).map(function (pid, idx) {
var direct = this.getDirectionByPosId(pid);
var name = this.posState[direct] && this.posState[direct].name || ('玩家' + (pid + 1));
return (idx + 1) + '. ' + name;
}.bind(this)).join('<br>');
var winKey = (winTeam === 0) ? 'team0' : 'team1';
this.guandanScore[winKey] += (data.rankDelta || 1);
this.guandanLastOrder = (data.finishOrder || []).map(function (pid) {
return this.getNameByPosId(pid);
}.bind(this));
this.guandanLevelLabel = data.nextLevelLabel || this.guandanLevelLabel;
layer.open({
icon: this.isSpec || iWonGd ? 6 : 5,
title: '本局结果',
content: '<div class="msg-title msg-' + (this.isSpec || iWonGd ? 'success' : 'fail') + '">' +
(this.isSpec ? '本局结束' : (iWonGd ? '恭喜你,你赢了' : '很遗憾,你输了')) +
'</div><div>头游队伍升级 +' + (data.rankDelta || 1) + '</div>' +
'<div style="margin-top:8px;line-height:1.7;">' + orderText + '</div>' +
'<div class="go-board-title">下一局</div><div>打 ' + (data.nextLevelLabel || this.guandanLevelLabel || '2') + '</div>'
});
this.startTimer(false);
this.roomState.state = 3;
['left', 'right', 'top', 'self'].forEach(function (direct) {
this.posState[direct].state = this.posState[direct].state ? 1 : 0;
this.posState[direct].isPass = false;
this.posState[direct].ctxCards = [];
}.bind(this));
if (window.FX) FX.beep(iWonGd || this.isSpec ? 'win' : 'lose');
return;
}
var iWon = !this.isSpec && data.winner.indexOf(this.posId) > - 1;
var msg = this.isSpec ? '本局结束' : (iWon ? '恭喜你,你赢了' : '很遗憾,你输了');
var icon = (this.isSpec || iWon) ? 6 : 5;
// —— 计算每位玩家本局得分(标准斗地主:地主双倍)——
var unit = data.score * data.ratio; // 单倍分
var dizhuWon = data.winner.length === 1;
var dizhuId = dizhuWon ? data.winner[0] : data.loser[0];
var roundDelta = [];
[0, 1, 2].forEach(function (pid) {
var direct = this.getDirectionByPosId(pid);
var name = this.posState[direct] && this.posState[direct].name;
if (!name) return;
var delta;
if (pid === dizhuId) delta = (dizhuWon ? 1 : -1) * unit * 2;
else delta = (dizhuWon ? -1 : 1) * unit;
this.bumpScore(name, delta);
roundDelta.push({ name: name, delta: delta, isDizhu: pid === dizhuId });
}.bind(this));
this.lastRoundDelta = roundDelta;
var content = '<div class="msg-title msg-' + (icon === 6 ? 'success' : 'fail') + '">' + msg + '</div><div>本局游戏统计如下:</div>';
var score = data.score * data.ratio * 2;
data.winner.forEach(function (id) {
var direct = this.getDirectionByPosId(id);
content += '<div>' + this.posState[direct].name + ':+' + (score / data.winner.length) + '分</div>';
}.bind(this));
data.loser.forEach(function (id) {
var direct = this.getDirectionByPosId(id);
content += '<div>' + this.posState[direct].name + ':-' + (score / data.loser.length) + '分</div>';
}.bind(this));
// —— 累计积分一览 ——
content += '<div class="go-board-title">本桌累计积分</div>';
this.scoreList.forEach(function (row) {
var sign = row.total > 0 ? '+' : '';
content += '<div class="go-board-row">' + row.name + ' <span class="go-board-num ' + (row.total >= 0 ? 'pos' : 'neg') + '">' + sign + row.total + '</span></div>';
});
layer.open({
icon: icon,
title: '本局结果',
content: content
});
// layer.alert(msg, {
// icon: icon,
// });
this.startTimer(false);//停止计时器
this.roomState.state = 3;
this.posState.left.state = 1;