ToolBox.uvue
31 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
<template>
<view class="tool-box" :style="toolBoxVars">
<!-- 使用 un-popup 实现弹窗 -->
<un-popup
v-model:show="show"
:mode="isLandscapeMode ? 'right' : 'bottom'"
round="24px"
:closeable="false"
:safe-area-inset-bottom="!isLandscapeMode"
:custom-style="popupCustomStyle">
<view class="popup-content" :class="[isLandscapeMode ? 'popup-landscape' : 'popup-portrait']">
<view class="list-wrapper">
<view class="panel-head">
<view style="display: flex; flex-direction: row; align-items: center; justify-content: space-between; width: 100%;">
<text style="font-size: 14px; color: #7b8086; letter-spacing: 0.5px;">文件夹</text>
<view class="panel-close" @click="hide">
<un-icon name="close-circle-fill" size="20" color="#94a3b8"></un-icon>
</view>
</view>
</view>
<scroll-view class="panel-body"
:style="scrollContainerStyle"
:show-scrollbar="false"
scroll-y="true"
@touchstart.stop
@touchmove.stop
@touchend.stop>
<!-- 快捷操作区域 -->
<view style="margin-bottom: 8px; padding: 8px; background-color: rgba(102, 126, 234, 0.04); border-radius: 10px;">
<view style="display: flex; flex-direction: row; align-items: center; margin-bottom: 8px;">
<view style="width: 4px; height: 18px; border-radius: 2px; background-color: #667eea; margin-right: 10px;"></view>
<text style="font-size: 13px; font-weight: 700; letter-spacing: 1.5px; color: #1e293b;">快捷操作</text>
</view>
<view class="fixed-group">
<view class="action-grid" style="margin-top: 8px;">
<view class="action-item" v-for="(action, idx) in fixedActionSlots" :key="'fixed-' + idx">
<view class="fab-item fixed-item"
:class="{ 'fab-item-active': activeItemId == 'fixed-' + idx }"
@touchstart="handleActionTouchStart('fixed-' + idx)"
@touchend="handleActionTouchEnd"
@touchcancel="handleActionTouchEnd"
@click="onActionClick(action as ToolAction)">
<view :class="['icon-box', (action as ToolAction).kind == 'pay' ? 'fixed-pay' : 'fixed-finish']">
<image v-if="(action as ToolAction).iconUrl != ''"
class="btn-icon"
mode="aspectFill"
:src="(action as ToolAction).iconUrl" />
<view :class="['sprite-icon', (action as ToolAction).iconClass]"></view>
</view>
<text class="item-text">{{ (action as ToolAction).label }}</text>
</view>
</view>
</view>
</view>
</view>
<!-- 分隔线 -->
<view style="width: 60%; height: 1px; background-color: rgba(226, 232, 240, 0.4); margin: 8px auto;"></view>
<!-- 功能工具区域 -->
<view style="margin-top: 8px; padding: 8px; background-color: rgba(148, 163, 184, 0.04); border-radius: 10px;">
<view style="display: flex; flex-direction: row; align-items: center; margin-bottom: 8px;">
<view style="width: 4px; height: 18px; border-radius: 2px; background-color: #64748b; margin-right: 10px;"></view>
<text style="font-size: 13px; font-weight: 700; letter-spacing: 1.5px; color: #334155;">功能工具</text>
</view>
<template v-for="(sec, sidx) in dynamicSections" :key="'dynsec-' + sidx + '-' + sec.folderCode">
<view v-if="sec.folderTitle !== ''" class="tool-subsection-title">
<text class="tool-subsection-title-text">{{ sec.folderTitle }}</text>
</view>
<view class="dynamic-group">
<view class="action-grid" style="margin-top: 8px;">
<view class="action-item" v-for="action in sec.actions" :key="(action as ToolAction).key" :style="actionItemStyle">
<view class="fab-item dynamic-item"
:class="{ 'fab-item-active': activeItemId == (action as ToolAction).key || isDynamicMaterialActive(action as ToolAction) }"
@touchstart="handleActionTouchStart((action as ToolAction).key)"
@touchend="handleActionTouchEnd"
@touchcancel="handleActionTouchEnd"
@click="onActionClick(action as ToolAction)">
<view class="icon-box">
<image v-if="(action as ToolAction).iconUrl != ''"
class="btn-icon"
mode="aspectFill"
:src="(action as ToolAction).iconUrl" />
<view v-else-if="(action as ToolAction).iconClass != ''"
:class="['sprite-icon', (action as ToolAction).iconClass]"></view>
</view>
<text class="item-text">{{ (action as ToolAction).label }}</text>
</view>
</view>
</view>
</view>
</template>
</view>
</scroll-view>
</view>
</view>
</un-popup>
<!-- FAB 触发按钮 -->
<un-fab v-model:active="show"
:expandable="false"
inactive-icon="folder"
:offset-right="10"
:offset-top="120"
position="right-center"
:size="56"
type="primary"
@click="handleFabClick">
<template #trigger>
<view class="custom-trigger">
<!-- 外层光晕层 -->
<view class="trigger-glow"></view>
<!-- 主按钮核心 -->
<view class="trigger-core">
<!-- 顶部高光层 -->
<view class="trigger-highlight"></view>
<!-- 图标和文字 -->
<view class="trigger-content">
<un-icon name="folder" size="22" color="#fff"></un-icon>
<text class="trigger-text">文件夹</text>
</view>
</view>
</view>
</template>
</un-fab>
</view>
</template>
<script setup lang="uts">
import type { ToolItem } from "@/types/tool-item.uts";
/**
* ToolBox 工具栏组件
* 用于展示可展开的工具选项列表
*/
// ============================================================================
// 类型定义
// ============================================================================
type ToolAction = {
key: string
kind: string
item: ToolItem | null
label: string
iconUrl: string
iconClass: string
}
// ============================================================================
// Props 定义
// ============================================================================
interface Props {
data: Array<any>
id: string | number | null
type: string
showPayBtn: boolean
idKey: string
toolStyle: string
direction: string
position: string
offsetTop: number
offsetRight: number
fabSize: number
triggerText: string
}
const props = withDefaults(defineProps<Props>(), {
data: () => [],
id: null,
type: '',
showPayBtn: false,
idKey: 'id',
toolStyle: '',
direction: 'bottom',
position: 'top-center',
offsetTop: 120,
offsetRight: 20,
fabSize: 56,
triggerText: '文件夹'
});
// ============================================================================
// Events 定义(与 uni-app x 文档一致:使用函数签名重载,勿用 defineEmits([...]))
// ============================================================================
const emit = defineEmits<{
(e : 'choose', item : ToolItem) : void
(e : 'finish') : void
(e : 'toPay') : void
}>();
// ============================================================================
// 响应式状态
// ============================================================================
const show = ref<boolean>(false); // 初始收起
const triggerText = computed<string>(() => props.triggerText);
const windowWidth = ref<number>(uni.getWindowInfo().windowWidth);
const windowHeight = ref<number>(uni.getWindowInfo().windowHeight);
const currentOffsetTop = ref<number>(props.offsetTop);
const currentOffsetRight = ref<number>(props.offsetRight);
const dragStartX = ref<number>(0);
const dragStartY = ref<number>(0);
const dragOriginTop = ref<number>(0);
const dragOriginRight = ref<number>(0);
const triggerDragging = ref<boolean>(false);
const triggerMoved = ref<boolean>(false);
const syncWindowMetrics = (): void => {
const info = uni.getWindowInfo();
windowWidth.value = info.windowWidth;
windowHeight.value = info.windowHeight;
};
// ============================================================================
// 计算属性
// ============================================================================
function isTreeToolData(arr: Array<any>): boolean {
// ✅ UTS 避免 Number === Int 比较,使用 ==
if (arr == null || arr.length == 0) {
return false;
}
const first = arr[0] as UTSJSONObject;
const ch = first["children"];
return first["folderCode"] != null && ch != null && Array.isArray(ch);
}
function materialRowToToolItem(child: UTSJSONObject, folderCodeStr: string): ToolItem {
const idVal = child["id"];
const fcSelf = child["folderCode"];
const fc = fcSelf != null && `${fcSelf}` !== "" ? `${fcSelf}` : folderCodeStr;
let titleStr = "";
const dt = child["detailTitle"];
if (dt != null && `${dt}` !== "") {
titleStr = `${dt}`;
} else if (child["materialName"] != null && `${child["materialName"]}` !== "") {
titleStr = `${child["materialName"]}`;
} else if (child["shortTitle"] != null && `${child["shortTitle"]}` !== "") {
titleStr = `${child["shortTitle"]}`;
} else if (child["title"] != null && `${child["title"]}` !== "") {
titleStr = `${child["title"]}`;
}
let coverStr = "";
const stu = child["shortTitleUrl"];
if (stu != null && `${stu}` !== "") {
coverStr = `${stu}`;
}
if (coverStr === "") {
const mu = child["materialUrl"];
if (mu != null && `${mu}` !== "") {
coverStr = `${mu}`;
}
}
if (coverStr === "") {
const src = child["receptionSourceDetailList"] as UTSJSONObject | null;
if (src != null && typeof src === "object" && !Array.isArray(src)) {
const du = src["detailUrl"];
if (du != null && `${du}` !== "") {
coverStr = `${du}`;
}
}
}
if (coverStr === "") {
const th = child["thumbnail"];
if (th != null && `${th}` !== "") {
coverStr = `${th}`;
}
}
return {
id: idVal,
folderCode: fc,
shortTitle: titleStr,
shortTitleUrl: coverStr,
title: titleStr
} as ToolItem;
}
/** 功能工具区:文件夹名为只读分组标题,仅下方素材可点(对齐 simgle 列表语义,避免把文件夹当成可点「分组」) */
type ToolDynamicSection = {
folderTitle: string
folderCode: string
actions: Array<ToolAction>
}
function toolItemToDynamicAction(item: ToolItem, key: string): ToolAction {
return {
key: key,
kind: "dynamic",
item: item,
label: `${item.shortTitle ?? ""}`,
iconUrl: `${item.shortTitleUrl ?? ""}`,
iconClass: ""
} as ToolAction;
}
const dynamicSections = computed<Array<ToolDynamicSection>>(() => {
const out: Array<ToolDynamicSection> = [];
const arr = props.data;
// ✅ UTS 避免 Number === Int 比较,使用 ==
if (arr == null || arr.length == 0) {
console.log("[ToolBox] data is empty.");
return out;
}
if (isTreeToolData(arr)) {
for (let i = 0; i < arr.length; i++) {
const folder = arr[i] as UTSJSONObject;
const folderCode = folder["folderCode"];
const fcStr = folderCode != null ? `${folderCode}` : "";
const fnRaw = folder["folderName"] as string | null;
const dirRaw = folder["directoryName"] as string | null;
const fnStr =
fnRaw != null && `${fnRaw}` !== ""
? `${fnRaw}`
: (dirRaw != null && `${dirRaw}` !== "" ? `${dirRaw}` : fcStr);
const children = folder["children"] as Array<any> | null;
const actions: Array<ToolAction> = [];
if (children != null) {
for (let j = 0; j < children.length; j++) {
const mat = materialRowToToolItem(children[j] as UTSJSONObject, fcStr);
const idPart = mat.id != null ? `${mat.id}` : `${j}`;
actions.push(toolItemToDynamicAction(mat, `mat-${i}-${j}-${idPart}`));
}
}
out.push({
folderTitle: fnStr,
folderCode: fcStr,
actions: actions
} as ToolDynamicSection);
}
return out;
}
const actionsFlat: Array<ToolAction> = [];
for (let i = 0; i < arr.length; i++) {
const element = arr[i] as UTSJSONObject;
const ti = {
id: element["id"] as string | number | null,
shortTitleUrl: element["shortTitleUrl"] as string | null,
shortTitle: element["shortTitle"] as string | null
} as ToolItem;
const idPart = ti.id != null ? `${ti.id}` : `${i}`;
actionsFlat.push(toolItemToDynamicAction(ti, `flat-${i}-${idPart}`));
}
out.push({
folderTitle: "",
folderCode: "",
actions: actionsFlat
} as ToolDynamicSection);
return out;
});
function isDynamicMaterialActive(action: ToolAction): boolean {
if (action.kind != "dynamic") {
return false;
}
const it = action.item;
if (it == null) {
return false;
}
const pid = props.id;
return it.id == pid || `${it.id}` === `${pid}`;
}
/**
* 根据状态动态选择图标
*/
const iconName = computed<string>(() => {
return show.value ? 'close' : 'folder';
});
const isLandscapeMode = computed<boolean>(() => {
return windowWidth.value > windowHeight.value;
});
const isPadLike = computed<boolean>(() => {
return Math.max(windowWidth.value, windowHeight.value) >= 1024;
});
const visualFabSize = computed<number>(() => {
const base = props.fabSize > 0 ? props.fabSize : 56;
if (isPadLike.value && isLandscapeMode.value) {
return Math.max(base, 64);
}
return base;
});
const panelWidth = computed<number>(() => {
if (isPadLike.value) {
return 246;
}
return 224;
});
const itemGap = computed<number>(() => {
return isPadLike.value ? 20 : 16;
});
const panelPaddingV = computed<number>(() => {
return isPadLike.value ? 18 : 14;
});
const visibleItemCount = computed<number>(() => {
if (isPadLike.value && isLandscapeMode.value) {
return 8;
}
if (isLandscapeMode.value) {
return 6;
}
return 6;
});
const fixedActionSlots = computed<Array<ToolAction>>(() => {
const left = props.showPayBtn
? {
key: "fixed-pay",
kind: "pay",
item: null,
label: "付款方式",
iconUrl: "../../static/images/reception/toolbox/tool-pay.png",
iconClass: "icon-tool-pay"
} as ToolAction
: null;
const right = props.type !== "preview"
? {
key: "fixed-finish",
kind: "finish",
item: null,
label: "完成接待",
iconUrl: "../../static/images/reception/toolbox/tool-finish.png",
iconClass: "icon-tool-finish"
} as ToolAction
: null;
const slots: Array<ToolAction> = [];
if (left != null) {
slots.push(left);
}
if (right != null) {
slots.push(right);
}
return slots;
});
const viewportBasedMaxHeight = computed<number>(() => {
const rate = isLandscapeMode.value ? 0.7 : 0.52;
return Math.floor(windowHeight.value * rate);
});
const panelHeight = computed<number>(() => {
if (!isLandscapeMode.value) {
// 竖屏:半抽屉,不限制绝对高度,留给内容撑开,最高不超过屏幕 60%
return Math.floor(windowHeight.value * 0.6);
}
const edgeInset = isPadLike.value ? 24 : 20;
const fullHeight = windowHeight.value - (edgeInset * 2);
const minHeight = isPadLike.value ? 420 : 320;
if (fullHeight < minHeight) {
return minHeight;
}
return fullHeight;
});
const popupCustomStyle = computed<UTSJSONObject>(() => {
if (!isLandscapeMode.value) {
// ✅ UVUE 不支持 vh 单位,使用 JavaScript 计算像素值
const maxHeightPx = Math.floor(windowHeight.value * 0.6);
return {
"max-height": `${maxHeightPx}px`
} as UTSJSONObject;
}
// 横屏下垂直居中
const edgeInset = isPadLike.value ? 24 : 20;
return {
"top": `${edgeInset}px`,
"bottom": `${edgeInset}px`,
"height": "auto"
} as UTSJSONObject;
});
const scrollContainerStyle = computed<UTSJSONObject>(() => {
if (!isLandscapeMode.value) {
// 竖屏下高度自适应内容
return {
"max-height": `${panelHeight.value - 52}px`
} as UTSJSONObject;
}
const bodyHeight = Math.max(240, panelHeight.value - 52);
return {
"height": `${bodyHeight}px`, // ✅ 使用固定高度
"flex-shrink": "0" // ✅ 防止被压缩
} as UTSJSONObject;
});
// ✅ UVUE 不支持 aspect-ratio,动态计算正方形高度
const actionItemStyle = computed<UTSJSONObject>(() => {
// action-grid 有 gap: 32px,所以每个 item 的宽度是 (containerWidth - 32) / 2
// 为了简化,我们直接使用一个固定的高度值
// 或者可以根据窗口宽度动态计算
const info = uni.getWindowInfo();
const containerWidth = isLandscapeMode.value ? Math.min(400, info.windowWidth * 0.6) : info.windowWidth;
const itemWidth = (containerWidth - 32 - 32) / 2; // 减去左右 padding 和 gap
return {
"height": `${itemWidth}px` // height = width,实现正方形
} as UTSJSONObject;
});
const toolBoxVars = computed<UTSJSONObject>(() => {
const textSize = isPadLike.value ? 12 : 11;
return {
"--fab-size": `${visualFabSize.value}px`,
"--panel-width": `${panelWidth.value}px`,
"--fab-gap": `${itemGap.value}px`,
"--fab-panel-padding-v": `${panelPaddingV.value}px`,
"--fab-panel-padding-h": `${isPadLike.value ? 14 : 12}px`,
"--fab-text-size": `${textSize}px`,
"--fab-panel-height": `${panelHeight.value}px`
} as UTSJSONObject;
});
const triggerPositionStyle = computed<UTSJSONObject>(() => {
if (!isLandscapeMode.value) {
// 竖屏下,展开时触发器通常保持不动或隐藏,这里为了简单起见,展开时隐藏触发器,依靠遮罩关闭
return {
top: `${currentOffsetTop.value}px`,
right: `0px`,
display: show.value ? 'none' : 'block'
} as UTSJSONObject;
}
const rightOffset = show.value ? panelWidth.value : 0;
return {
top: `${currentOffsetTop.value}px`,
right: `${rightOffset}px`
} as UTSJSONObject;
});
const panelPositionStyle = computed<UTSJSONObject>(() => {
// un-popup 已处理定位,此样式不再需要
return {} as UTSJSONObject;
});
// ============================================================================
// 方法
// ============================================================================
/**
* 切换展开/收起状态
*/
const toggle = (): void => {
show.value = !show.value;
};
/**
* 处理 FAB 按钮点击
*/
const handleFabClick = (): void => {
if (triggerMoved.value) {
triggerMoved.value = false;
return;
}
syncWindowMetrics();
toggle();
};
const readTouchPoint = (event: TouchEvent): number[] => {
let touches = event.touches;
if (touches == null || touches.length == 0) {
touches = event.changedTouches;
}
if (touches != null && touches.length > 0) {
const first = touches[0];
const x = first.clientX;
const y = first.clientY;
return [x, y];
}
return [0, 0];
};
const handleTriggerTouchStart = (event: TouchEvent): void => {
if (show.value) {
triggerDragging.value = false;
triggerMoved.value = false;
return;
}
syncWindowMetrics();
const point = readTouchPoint(event);
dragStartX.value = point[0];
dragStartY.value = point[1];
dragOriginTop.value = currentOffsetTop.value;
dragOriginRight.value = currentOffsetRight.value;
triggerDragging.value = true;
triggerMoved.value = false;
};
const handleTriggerTouchMove = (event: TouchEvent): void => {
if (show.value) {
return;
}
if (!triggerDragging.value) {
return;
}
const point = readTouchPoint(event);
const deltaY = point[1] - dragStartY.value;
if (Math.abs(deltaY) > 2) {
triggerMoved.value = true;
}
const fabSize = visualFabSize.value;
const maxTop = Math.max(8, windowHeight.value - fabSize - 8);
const nextTop = Math.max(8, Math.min(maxTop, dragOriginTop.value + deltaY));
currentOffsetTop.value = nextTop;
currentOffsetRight.value = 0;
};
/**
* 隐藏工具栏
*/
const hide = (): void => {
show.value = false;
};
/** 与历史页面约定一致:父级通过 $callMethod('closeAllPopup') 统一收起弹层 */
const closeAllPopup = (): void => {
hide();
};
const handleTriggerTouchEnd = (): void => {
triggerDragging.value = false;
};
/**
* 选择工具项
* @param item - 选中的工具项
*/
const selectItem = (item: ToolItem): void => {
console.log('selectItem', item);
// show.value = false; // 自动收起
emit('choose', item);
};
/**
* 完成接待
*/
const finish = (): void => {
emit('finish');
};
/**
* 前往支付
*/
const toPay = (): void => {
emit('toPay');
};
const activeItemId = ref<string>('');
const handleActionTouchStart = (id: string): void => {
activeItemId.value = id;
};
const handleActionTouchEnd = (): void => {
activeItemId.value = '';
};
const onActionClick = (action: ToolAction): void => {
if (action.kind == "dynamic") {
if (action.item != null) {
selectItem(action.item);
}
return;
}
if (action.kind == "pay") {
toPay();
return;
}
if (action.kind == "finish") {
finish();
hide();
}
};
syncWindowMetrics();
// ============================================================================
// 暴露给父组件的方法
// ==========================================================================
defineExpose({
hide,
closeAllPopup
});
</script>
<style scoped lang="scss">
.tool-box {
position: relative;
width: 100%;
height: 100%;
pointer-events: none;
.popup-content {
pointer-events: auto;
}
.popup-landscape {
width: var(--panel-width);
height: var(--fab-panel-height);
border-radius: 24px 0 0 24px;
display: flex; // ✅ 添加 flex 布局
flex-direction: column; // ✅ 垂直排列
overflow: hidden; // ✅ 防止内容溢出
}
.popup-portrait {
width: 100%;
height: auto;
// ✅ UVUE 不支持 vh 单位,max-height 通过 popupCustomStyle 动态计算
border-radius: 24px 24px 0 0;
display: flex; // ✅ 添加 flex 布局
flex-direction: column; // ✅ 垂直排列
overflow: hidden; // ✅ 防止内容溢出
}
.custom-trigger {
position: relative;
width: 62px;
height: 62px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
}
/* 外层光晕 - 使用纯色背景模拟 */
.trigger-glow {
position: absolute;
top: -8px;
left: -8px;
right: -8px;
bottom: -8px;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.08);
}
/* 核心按钮 - 纯色背景 + 多层阴影 */
.trigger-core {
position: relative;
width: 56px;
height: 56px;
border-radius: 50%;
// background-color: #718096;
background-image: linear-gradient(to bottom, rgba(30, 58, 138, 0), rgba(30, 58, 138, 0.35));
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(255, 255, 255, 0.15);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
overflow: hidden;
}
/* 顶部高光层 - 用独立 view 实现 */
.trigger-highlight {
position: absolute;
top: 0;
left: 0;
width: 56px;
height: 28px;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, transparent 100%);
border-radius: 28px 28px 0 0;
}
/* 内容容器 */
.trigger-content {
position: relative;
z-index: 2;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* 文字标签 */
.trigger-text {
font-size: 10px;
color: rgba(255, 255, 255, 0.95);
text-align: center;
white-space: normal;
width: 40px;
line-height: 11px;
font-weight: 600;
letter-spacing: 0.5px;
margin-top: 2px;
}
.list-wrapper {
box-sizing: border-box;
display: flex;
flex-direction: column;
padding: var(--fab-panel-padding-v) var(--fab-panel-padding-h);
margin-bottom: 0;
align-items: stretch;
background-color: var(--bg-card, #FFFFFF); // ✅ 移除 backdrop-filter
// ✅ UVUE 不支持 backdrop-filter,低端机性能优化
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08); // ✅ 简化阴影
border: 1px solid rgba(255, 255, 255, 0.6);
overflow: hidden; // ✅ 已有
flex: 1; // ✅ 添加 flex: 1 占满父容器
min-height: 0; // ✅ 添加 min-height: 0 防止溢出
}
.panel-head {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
height: 28px;
padding: 0 2px 0 8px;
margin-bottom: 4px;
}
.panel-title {
font-size: 14px;
font-weight: 600;
color: #1e293b;
letter-spacing: 0.5px;
}
.panel-close {
width: 24px;
height: 24px;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(102, 126, 234, 0.08);
border: 1px solid rgba(102, 126, 234, 0.15);
transition: all 0.2s ease;
&:active {
background: rgba(102, 126, 234, 0.15);
transform: scale(0.95);
}
}
.panel-close-text {
font-size: 16px;
font-weight: 400; // ✅ UVUE 不支持 300,改为 400 (normal)
color: #667eea;
line-height: 16px;
}
.panel-body {
width: 100%;
flex: 1;
flex-direction: column;
display: flex;
overflow: hidden;
}
.section-title {
display: flex;
flex-direction: row;
width: 100%;
font-size: 9px;
font-weight: 400;
letter-spacing: 0.5px;
color: #cfd6dfff; /* 进一步弱化区域标题颜色 */
padding: 0 6px;
margin-bottom: 2px;
// ✅ UVUE 不支持 text-transform,如需大写请在数据层转换
}
.tool-subsection-title {
display: flex;
flex-direction: row;
width: 100%;
padding: 8px 6px 4px;
margin-top: 2px;
box-sizing: border-box;
}
.tool-subsection-title-text {
font-size: 12px;
font-weight: 600;
color: #475569;
line-height: 16px;
}
.dynamic-group {
display: flex;
flex-direction: column;
padding-bottom: 8px;
width: 100%;
}
.fixed-group {
display: flex;
flex-direction: column;
padding: 6px 0 4px;
width: 100%;
}
.action-grid {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
margin-top: 16px;
margin-left: -16px;
margin-right: -16px;
}
.action-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-bottom: 6px;
margin-left: 16px;
margin-right: 16px;
}
.tool-panel-portrait .action-item {
width: 50%; /* 竖屏改为 2个一行,尺寸翻倍 */
// ✅ UVUE 不支持 aspect-ratio,通过 height 与 width 相等实现正方形
// 由于 width 是 50%,我们需要动态计算 height
}
.tool-panel-landscape .action-item {
width: 50%; /* 横屏也改为 2个一行,确保足够大 */
// ✅ UVUE 不支持 aspect-ratio,通过 height 与 width 相等实现正方形
}
.fab-item {
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
// ✅ UVUE 不支持 cursor,移动端无鼠标指针
// ✅ 移除 transition,低端机上减少重绘
width: 100%;
padding: 4px 4px 2px; /* 上4px 左右4px 下2px,更紧凑 */
border-radius: 8px;
background-color: transparent;
position: relative;
&:active {
background-color: rgba(102, 126, 234, 0.06);
transform: scale(0.97);
transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
}
.fab-item-active {
transform: scale(0.95);
background: rgba(102, 126, 234, 0.08);
}
.icon-box {
position: relative;
width: 72px;
height: 72px;
border-radius: 20px;
background-color: #ffffff;
box-shadow:
0 4px 16px rgba(102, 126, 234, 0.08),
0 2px 8px rgba(0, 0, 0, 0.04);
border: 1px solid rgba(226, 232, 240, 0.6);
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
.btn-icon,
.sprite-icon {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
}
.item-text {
display: none;
}
}
/* 快捷操作图标:精致品牌色 */
.fixed-item .icon-box {
width: 56px;
height: 56px;
border-radius: 16px;
background-color: rgba(102, 126, 234, 0.08);
border: 1px solid rgba(102, 126, 234, 0.15);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.08);
}
/* 功能工具图标:大气简约 */
.dynamic-item .icon-box {
width: 140px;
height: 140px;
border-radius: 24px;
background-color: #ffffff;
border: 1px solid rgba(226, 232, 240, 0.5);
box-shadow:
0 8px 24px rgba(102, 126, 234, 0.06),
0 4px 12px rgba(0, 0, 0, 0.03);
}
/* ✅ UVUE 不支持后代选择器 + 伪类组合,移除复杂的 :active 效果 */
/* 简单的按压反馈已通过 .fab-item:active 实现 */
.item-text {
margin-left: 0;
margin-top: 10px; /* 减小与图标的间距 */
margin-bottom: 4px; /* 减小底部留白 */
font-size: 11px;
color: #444b53ff;
font-weight: 400;
line-height: 13px;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
// ✅ UVUE 不支持 max-width: 100%,移除后由 flex 布局自适应
}
.fixed-item {
width: 100%;
}
.dynamic-item {
width: 100%;
}
.fixed-pay {
background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
border: 1px solid rgba(59, 130, 246, 0.2);
}
.fixed-finish {
background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
border: 1px solid rgba(245, 158, 11, 0.2);
}
}
</style>