oxy-uni-ui 1.2.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/attributes.json +1 -1
- package/components/common/abstracts/variable.scss +353 -328
- package/components/common/util.ts +185 -32
- package/components/composables/index.ts +1 -0
- package/components/composables/usePopover.ts +24 -20
- package/components/composables/useVirtualScroll.ts +10 -9
- package/components/composables/useWindowResize.ts +35 -0
- package/components/oxy-action-sheet/index.scss +24 -11
- package/components/oxy-action-sheet/oxy-action-sheet.vue +27 -19
- package/components/oxy-action-sheet/types.ts +7 -0
- package/components/oxy-backtop/index.scss +3 -3
- package/components/oxy-backtop/oxy-backtop.vue +9 -6
- package/components/oxy-backtop/types.ts +7 -7
- package/components/oxy-badge/index.scss +4 -4
- package/components/oxy-badge/oxy-badge.vue +3 -3
- package/components/oxy-badge/types.ts +2 -2
- package/components/oxy-button/index.scss +5 -5
- package/components/oxy-button/oxy-button.vue +5 -1
- package/components/oxy-calendar/index.scss +11 -11
- package/components/oxy-calendar/oxy-calendar.vue +1 -0
- package/components/oxy-calendar/types.ts +5 -0
- package/components/oxy-calendar-view/month/index.scss +4 -4
- package/components/oxy-calendar-view/month/types.ts +36 -0
- package/components/oxy-calendar-view/monthPanel/index.scss +7 -7
- package/components/oxy-calendar-view/monthPanel/month-panel.vue +14 -8
- package/components/oxy-calendar-view/year/index.scss +4 -4
- package/components/oxy-calendar-view/yearPanel/index.scss +4 -4
- package/components/oxy-calendar-view/yearPanel/year-panel.vue +21 -5
- package/components/oxy-card/index.scss +2 -2
- package/components/oxy-cell/index.scss +8 -8
- package/components/oxy-checkbox/index.scss +7 -7
- package/components/oxy-checkbox-group/index.scss +2 -2
- package/components/oxy-circle/oxy-circle.vue +10 -7
- package/components/oxy-circle/types.ts +5 -5
- package/components/oxy-col/oxy-col.vue +2 -2
- package/components/oxy-col-picker/index.scss +4 -4
- package/components/oxy-col-picker/oxy-col-picker.vue +6 -5
- package/components/oxy-col-picker/types.ts +7 -2
- package/components/oxy-collapse/index.scss +2 -2
- package/components/oxy-collapse-item/oxy-collapse-item.vue +3 -3
- package/components/oxy-corner/index.scss +32 -32
- package/components/oxy-count-to/oxy-count-to.vue +3 -3
- package/components/oxy-curtain/index.scss +15 -15
- package/components/oxy-curtain/oxy-curtain.vue +4 -2
- package/components/oxy-curtain/types.ts +6 -1
- package/components/oxy-date-strip/oxy-date-strip.vue +2 -2
- package/components/oxy-date-strip/types.ts +1 -1
- package/components/oxy-date-strip-item/index.scss +3 -3
- package/components/oxy-datetime-picker/index.scss +11 -11
- package/components/oxy-datetime-picker/oxy-datetime-picker.vue +1 -0
- package/components/oxy-datetime-picker/types.ts +5 -0
- package/components/oxy-drop-menu/index.scss +3 -3
- package/components/oxy-drop-menu/oxy-drop-menu.vue +3 -3
- package/components/oxy-drop-menu-item/index.scss +1 -1
- package/components/oxy-drop-menu-item/oxy-drop-menu-item.vue +4 -3
- package/components/oxy-drop-menu-item/types.ts +5 -0
- package/components/oxy-echarts/types.ts +6 -0
- package/components/oxy-fab/index.scss +8 -8
- package/components/oxy-fab/oxy-fab.vue +22 -3
- package/components/oxy-file-list/index.scss +24 -23
- package/components/oxy-file-list/oxy-file-list.vue +2 -2
- package/components/oxy-floating-panel/oxy-floating-panel.vue +13 -9
- package/components/oxy-floating-panel/{type.ts → types.ts} +8 -8
- package/components/oxy-footer/index.scss +19 -0
- package/components/oxy-footer/oxy-footer.vue +78 -0
- package/components/oxy-footer/types.ts +17 -0
- package/components/oxy-form-item/types.ts +22 -1
- package/components/oxy-gap/oxy-gap.vue +2 -2
- package/components/oxy-gap/types.ts +2 -2
- package/components/oxy-grid/oxy-grid.vue +1 -1
- package/components/oxy-grid/types.ts +1 -1
- package/components/oxy-grid-item/index.scss +1 -1
- package/components/oxy-grid-item/oxy-grid-item.vue +7 -5
- package/components/oxy-grid-item/types.ts +1 -1
- package/components/oxy-guidance/index.scss +75 -0
- package/components/oxy-guidance/oxy-guidance.vue +201 -0
- package/components/oxy-guidance/types.ts +33 -0
- package/components/oxy-icon/oxy-icon.vue +2 -2
- package/components/oxy-icon/types.ts +1 -1
- package/components/oxy-img/oxy-img.vue +4 -4
- package/components/oxy-img/types.ts +3 -3
- package/components/oxy-img-cropper/index.scss +12 -12
- package/components/oxy-img-cropper/oxy-img-cropper.vue +97 -52
- package/components/oxy-img-cropper/types.ts +2 -2
- package/components/oxy-img-lazy/oxy-img-lazy.vue +3 -3
- package/components/oxy-img-lazy/types.ts +3 -3
- package/components/oxy-index-anchor/index.scss +2 -2
- package/components/oxy-index-anchor/oxy-index-anchor.vue +2 -2
- package/components/oxy-index-anchor/{type.ts → types.ts} +3 -0
- package/components/oxy-index-bar/index.scss +3 -3
- package/components/oxy-index-bar/oxy-index-bar.vue +3 -3
- package/components/oxy-index-bar/{type.ts → types.ts} +2 -2
- package/components/oxy-input/index.scss +1 -1
- package/components/oxy-input-number/index.scss +5 -5
- package/components/oxy-input-number/oxy-input-number.vue +2 -2
- package/components/oxy-input-number/types.ts +3 -2
- package/components/oxy-keyboard/index.scss +5 -5
- package/components/oxy-keyboard/key/index.scss +3 -3
- package/components/oxy-keyboard/key/index.vue +2 -2
- package/components/oxy-keyboard/key/types.ts +15 -0
- package/components/oxy-keyboard/oxy-keyboard.vue +1 -0
- package/components/oxy-keyboard/types.ts +5 -0
- package/components/oxy-link/index.scss +2 -2
- package/components/oxy-list/oxy-list.vue +4 -3
- package/components/oxy-loading/oxy-loading.vue +8 -4
- package/components/oxy-loading/types.ts +1 -1
- package/components/oxy-loadmore/index.scss +3 -3
- package/components/oxy-long-press-menu/index.scss +93 -0
- package/components/oxy-long-press-menu/oxy-long-press-menu.vue +338 -0
- package/components/oxy-long-press-menu/types.ts +34 -0
- package/components/oxy-message-box/index.scss +12 -11
- package/components/oxy-message-box/oxy-message-box.vue +11 -3
- package/components/oxy-message-box/types.ts +14 -0
- package/components/oxy-navbar/index.scss +2 -2
- package/components/oxy-navbar/oxy-navbar.vue +58 -13
- package/components/oxy-navbar/types.ts +8 -1
- package/components/oxy-navbar-capsule/types.ts +3 -0
- package/components/oxy-notice-bar/index.scss +3 -3
- package/components/oxy-notice-bar/oxy-notice-bar.vue +9 -5
- package/components/oxy-notice-bar/types.ts +3 -3
- package/components/oxy-notify/index.ts +1 -0
- package/components/oxy-notify/oxy-notify.vue +3 -2
- package/components/oxy-notify/types.ts +7 -0
- package/components/oxy-pagination/index.scss +1 -1
- package/components/oxy-password-input/oxy-password-input.vue +2 -2
- package/components/oxy-password-input/types.ts +1 -1
- package/components/oxy-picker/index.scss +45 -2
- package/components/oxy-picker/oxy-picker.vue +100 -14
- package/components/oxy-picker/types.ts +29 -1
- package/components/oxy-picker-view/index.scss +3 -3
- package/components/oxy-picker-view/oxy-picker-view.vue +4 -4
- package/components/oxy-popover/index.scss +9 -9
- package/components/oxy-popup/index.scss +2 -2
- package/components/oxy-popup/oxy-popup.vue +35 -2
- package/components/oxy-popup/types.ts +8 -1
- package/components/oxy-progress/index.scss +3 -3
- package/components/oxy-qrcode/draw.ts +398 -0
- package/components/oxy-qrcode/index.scss +2 -0
- package/components/oxy-qrcode/oxy-qrcode.vue +124 -0
- package/components/oxy-qrcode/qrcode.ts +936 -0
- package/components/oxy-qrcode/types.ts +42 -0
- package/components/oxy-radio/index.scss +10 -10
- package/components/oxy-radio-group/index.scss +2 -2
- package/components/oxy-rate/types.ts +4 -4
- package/components/oxy-resize/index.scss +2 -2
- package/components/oxy-resize/oxy-resize.vue +4 -4
- package/components/oxy-resize/types.ts +3 -0
- package/components/oxy-rich-text/index.scss +30 -29
- package/components/oxy-rich-text/mp-html/mp-html.vue +33 -24
- package/components/oxy-rich-text/mp-html/node/node.vue +30 -19
- package/components/oxy-rich-text/oxy-rich-text.vue +31 -31
- package/components/oxy-rich-text/types.ts +6 -1
- package/components/oxy-row/oxy-row.vue +3 -3
- package/components/oxy-row/types.ts +1 -1
- package/components/oxy-search/index.scss +3 -3
- package/components/oxy-segmented/index.scss +16 -16
- package/components/oxy-segmented/oxy-segmented.vue +23 -3
- package/components/oxy-select/index.scss +144 -68
- package/components/oxy-select/oxy-select.vue +85 -50
- package/components/oxy-select/types.ts +13 -1
- package/components/oxy-select-picker/index.scss +7 -7
- package/components/oxy-select-picker/oxy-select-picker.vue +1 -0
- package/components/oxy-select-picker/types.ts +2 -0
- package/components/oxy-sidebar-item/index.scss +1 -1
- package/components/oxy-signature/oxy-signature.vue +18 -10
- package/components/oxy-signature/types.ts +106 -13
- package/components/oxy-skeleton/oxy-skeleton.vue +6 -6
- package/components/oxy-skeleton/types.ts +1 -1
- package/components/oxy-slider/index.scss +3 -3
- package/components/oxy-sort-button/index.scss +8 -8
- package/components/oxy-status-tip/index.scss +4 -4
- package/components/oxy-status-tip/oxy-status-tip.vue +5 -5
- package/components/oxy-status-tip/types.ts +3 -3
- package/components/oxy-step/index.scss +14 -14
- package/components/oxy-sticky/oxy-sticky.vue +6 -6
- package/components/oxy-stream-render/types.ts +4 -1
- package/components/oxy-swipe-action/oxy-swipe-action.vue +27 -2
- package/components/oxy-swiper/oxy-swiper.vue +6 -6
- package/components/oxy-swiper/types.ts +5 -5
- package/components/oxy-switch/index.scss +8 -8
- package/components/oxy-switch/oxy-switch.vue +2 -2
- package/components/oxy-switch/types.ts +1 -1
- package/components/oxy-tab/index.scss +11 -1
- package/components/oxy-tabbar/index.scss +1 -1
- package/components/oxy-tabbar/oxy-tabbar.vue +39 -10
- package/components/oxy-table/index.scss +5 -5
- package/components/oxy-table/oxy-table.vue +8 -6
- package/components/oxy-table/types.ts +2 -2
- package/components/oxy-table-col/oxy-table-col.vue +3 -3
- package/components/oxy-table-col/types.ts +2 -2
- package/components/oxy-tabs/index.scss +43 -15
- package/components/oxy-tabs/oxy-tabs.vue +53 -19
- package/components/oxy-tabs/types.ts +15 -3
- package/components/oxy-tag/index.scss +15 -15
- package/components/oxy-text/index.scss +5 -1
- package/components/oxy-text/oxy-text.vue +76 -7
- package/components/oxy-text/types.ts +12 -0
- package/components/oxy-textarea/index.scss +6 -6
- package/components/oxy-toast/oxy-toast.vue +24 -8
- package/components/oxy-tooltip/index.scss +9 -9
- package/components/oxy-tree/index.scss +51 -15
- package/components/oxy-tree/oxy-tree.vue +13 -9
- package/components/oxy-tree/types.ts +12 -9
- package/components/oxy-upload/index.scss +21 -21
- package/components/oxy-upload/types.ts +2 -2
- package/components/oxy-verification-code/index.scss +6 -0
- package/components/oxy-verification-code/oxy-verification-code.vue +187 -0
- package/components/oxy-verification-code/types.ts +82 -0
- package/components/oxy-video-preview/index.scss +4 -4
- package/components/oxy-virtual-scroll/index.scss +4 -4
- package/components/oxy-virtual-scroll/oxy-virtual-scroll.vue +11 -7
- package/components/oxy-virtual-scroll/types.ts +14 -14
- package/components/oxy-voice-player/index.scss +908 -0
- package/components/oxy-voice-player/oxy-voice-player.vue +821 -0
- package/components/oxy-voice-player/types.ts +567 -0
- package/components/oxy-waterfall/oxy-waterfall.vue +6 -6
- package/components/oxy-waterfall/types.ts +6 -6
- package/components/oxy-watermark/oxy-watermark.vue +35 -13
- package/components/oxy-watermark/types.ts +14 -14
- package/global.d.ts +2 -0
- package/locale/lang/ar-SA.ts +3 -0
- package/locale/lang/en-US.ts +3 -0
- package/locale/lang/zh-CN.ts +3 -0
- package/package.json +97 -1
- package/tags.json +1 -1
- package/web-types.json +1 -1
- package/components/oxy-number-keyboard/index.scss +0 -78
- package/components/oxy-number-keyboard/key/index.scss +0 -81
- package/components/oxy-number-keyboard/key/index.vue +0 -78
- package/components/oxy-number-keyboard/key/types.ts +0 -11
- package/components/oxy-number-keyboard/oxy-number-keyboard.vue +0 -151
- package/components/oxy-number-keyboard/types.ts +0 -83
- package/components/oxy-tree/components/tree-node-content.vue +0 -72
- package/components/oxy-tree/index.ts +0 -51
- package/oxy-uni-ui.zip +0 -0
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
@refresherrestore="onRestore"
|
|
29
29
|
@refresherabort="onAbort"
|
|
30
30
|
>
|
|
31
|
-
<view class="oxy-virtual-scroll__container" :style="{ height: totalHeight
|
|
32
|
-
<view class="oxy-virtual-scroll__items" :style="{ transform: `translateY(${virtualOffsetY}
|
|
31
|
+
<view class="oxy-virtual-scroll__container" :style="{ height: unitConvert(totalHeight, 0, { output: 'px' }) }">
|
|
32
|
+
<view class="oxy-virtual-scroll__items" :style="{ transform: `translateY(${unitConvert(virtualOffsetY, 0, { output: 'px' })})` }">
|
|
33
33
|
<view v-for="(item, index) in virtualData" :key="index">
|
|
34
34
|
<slot name="item" :item="item" :index="startIndex + index"></slot>
|
|
35
35
|
</view>
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
|
|
55
55
|
<!-- 回到顶部按钮 -->
|
|
56
56
|
<view v-if="showBackToTop && showBackTopBtn" class="oxy-virtual-scroll__back-top" @click="scrollToTop">
|
|
57
|
-
<oxy-icon name="backtop" color="#fff" size="
|
|
57
|
+
<oxy-icon name="backtop" color="#fff" size="40rpx"></oxy-icon>
|
|
58
58
|
</view>
|
|
59
59
|
</view>
|
|
60
60
|
</template>
|
|
@@ -80,6 +80,7 @@ import type {
|
|
|
80
80
|
ScrollViewOnScrollEvent
|
|
81
81
|
} from '@uni-helper/uni-app-types/index'
|
|
82
82
|
import { useVirtualScroll } from '../composables/useVirtualScroll'
|
|
83
|
+
import { unitConvert } from '../common/util'
|
|
83
84
|
|
|
84
85
|
const props = defineProps(listProps)
|
|
85
86
|
|
|
@@ -19,7 +19,7 @@ export default {
|
|
|
19
19
|
<script lang="ts" setup>
|
|
20
20
|
import { computed, onBeforeMount, ref, watch, type CSSProperties } from 'vue'
|
|
21
21
|
import base64 from '../common/base64'
|
|
22
|
-
import { gradient, context, objToStyle,
|
|
22
|
+
import { withDefaultUnit, gradient, context, objToStyle, isDef } from '../common/util'
|
|
23
23
|
import { loadingProps } from './types'
|
|
24
24
|
|
|
25
25
|
const svgDefineId = context.id++
|
|
@@ -44,7 +44,11 @@ const iconSize = ref<string | number | null>(null)
|
|
|
44
44
|
watch(
|
|
45
45
|
() => props.size,
|
|
46
46
|
(newVal) => {
|
|
47
|
-
|
|
47
|
+
if (!isDef(newVal) || newVal === '') {
|
|
48
|
+
iconSize.value = null
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
iconSize.value = withDefaultUnit(newVal)
|
|
48
52
|
},
|
|
49
53
|
{
|
|
50
54
|
deep: true,
|
|
@@ -66,8 +70,8 @@ watch(
|
|
|
66
70
|
const rootStyle = computed(() => {
|
|
67
71
|
const style: CSSProperties = {}
|
|
68
72
|
if (isDef(iconSize.value)) {
|
|
69
|
-
style.height =
|
|
70
|
-
style.width =
|
|
73
|
+
style.height = iconSize.value
|
|
74
|
+
style.width = iconSize.value
|
|
71
75
|
}
|
|
72
76
|
return `${objToStyle(style)} ${props.customStyle}`
|
|
73
77
|
})
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
@include edeep(loading) {
|
|
17
17
|
display: inline-block;
|
|
18
|
-
margin-right:
|
|
18
|
+
margin-right: 16rpx;
|
|
19
19
|
vertical-align: middle;
|
|
20
20
|
width: $-loadmore-loading-size;
|
|
21
21
|
height: $-loadmore-loading-size;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
vertical-align: middle;
|
|
27
27
|
|
|
28
28
|
@include when(light) {
|
|
29
|
-
margin: 0
|
|
29
|
+
margin: 0 12rpx;
|
|
30
30
|
color: $-loadmore-error-color;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
vertical-align: middle;
|
|
37
37
|
font-size: $-loadmore-refresh-fs;
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
@import './../common/abstracts/_mixin.scss';
|
|
2
|
+
@import './../common/abstracts/variable.scss';
|
|
3
|
+
|
|
4
|
+
@include b(long-press-menu) {
|
|
5
|
+
position: relative;
|
|
6
|
+
display: inline-block; /* 让容器适应内容宽度 */
|
|
7
|
+
user-select: none;
|
|
8
|
+
-webkit-user-select: none;
|
|
9
|
+
|
|
10
|
+
@include e(trigger) {
|
|
11
|
+
position: relative;
|
|
12
|
+
transition: background-color 0.2s;
|
|
13
|
+
border-radius: $-long-press-menu-radius;
|
|
14
|
+
/* 默认为 inline-block,减少空白占据 */
|
|
15
|
+
display: inline-block;
|
|
16
|
+
width: 100%;
|
|
17
|
+
|
|
18
|
+
@include when(active) {
|
|
19
|
+
background-color: rgba(0, 0, 0, 0.05); /* 长按时的高亮背景 */
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@include e(mask) {
|
|
24
|
+
position: fixed;
|
|
25
|
+
top: 0;
|
|
26
|
+
left: 0;
|
|
27
|
+
right: 0;
|
|
28
|
+
bottom: 0;
|
|
29
|
+
z-index: 998;
|
|
30
|
+
background-color: transparent; /* 透明遮罩,点击关闭 */
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@include e(popover) {
|
|
34
|
+
position: fixed;
|
|
35
|
+
z-index: $-long-press-menu-z-index;
|
|
36
|
+
background-color: $-long-press-menu-bg;
|
|
37
|
+
border-radius: $-long-press-menu-radius;
|
|
38
|
+
padding: $-long-press-menu-padding;
|
|
39
|
+
min-width: 200rpx;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@include e(content) {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
flex-wrap: nowrap;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@include e(item) {
|
|
49
|
+
padding: $-long-press-menu-item-padding;
|
|
50
|
+
position: relative;
|
|
51
|
+
&:not(:last-child)::after {
|
|
52
|
+
content: '';
|
|
53
|
+
position: absolute;
|
|
54
|
+
right: 0;
|
|
55
|
+
top: 24rpx;
|
|
56
|
+
bottom: 24rpx;
|
|
57
|
+
width: 1px;
|
|
58
|
+
background-color: rgba(255, 255, 255, 0.2);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@include e(text) {
|
|
63
|
+
color: $-long-press-menu-color;
|
|
64
|
+
font-size: $-long-press-menu-fs;
|
|
65
|
+
white-space: nowrap;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@include e(arrow) {
|
|
69
|
+
left: 24rpx;
|
|
70
|
+
}
|
|
71
|
+
@include triangleArrow($-long-press-menu-arrow-size, $-long-press-menu-bg);
|
|
72
|
+
|
|
73
|
+
@include when(selectable) {
|
|
74
|
+
/* 移除 user-select,改为控制 trigger */
|
|
75
|
+
.oxy-long-press-menu__trigger {
|
|
76
|
+
user-select: text;
|
|
77
|
+
-webkit-user-select: text;
|
|
78
|
+
-webkit-touch-callout: none; /* 禁用系统默认长按菜单 */
|
|
79
|
+
cursor: text;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@keyframes fadeIn {
|
|
85
|
+
from {
|
|
86
|
+
opacity: 0;
|
|
87
|
+
transform: translateX(-50%) scale(0.9);
|
|
88
|
+
}
|
|
89
|
+
to {
|
|
90
|
+
opacity: 1;
|
|
91
|
+
transform: translateX(-50%) scale(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :id="elId" :data-id="elId" :class="`oxy-long-press-menu ${mode === 'selection' ? 'is-selectable' : ''} ${customClass}`" :style="customStyle">
|
|
3
|
+
<!-- 触发区域 -->
|
|
4
|
+
<!-- mode='normal': 使用 longpress 事件 -->
|
|
5
|
+
<!-- mode='selection': 不使用 longpress,依靠 renderjs/js 监听 selection -->
|
|
6
|
+
<view
|
|
7
|
+
class="oxy-long-press-menu__trigger"
|
|
8
|
+
@longpress="mode === 'normal' ? onLongPress($event) : null"
|
|
9
|
+
:class="{ 'is-active': isVisible && mode === 'normal' }"
|
|
10
|
+
>
|
|
11
|
+
<slot></slot>
|
|
12
|
+
</view>
|
|
13
|
+
|
|
14
|
+
<!-- 遮罩层 (Normal模式使用,Selection模式不需要遮罩,依靠原生行为关闭) -->
|
|
15
|
+
<view v-if="isVisible && mode === 'normal'" class="oxy-long-press-menu__mask" @click="hideMenu" @touchmove.stop.prevent></view>
|
|
16
|
+
|
|
17
|
+
<!-- 气泡菜单 -->
|
|
18
|
+
<view v-if="isVisible" class="oxy-long-press-menu__popover" :style="popoverStyle" @click.stop>
|
|
19
|
+
<view
|
|
20
|
+
v-if="visibleArrow"
|
|
21
|
+
:class="`oxy-long-press-menu__arrow oxy-long-press-menu__${arrowBottom ? 'arrow-down' : 'arrow-up'}`"
|
|
22
|
+
:style="arrowStyle"
|
|
23
|
+
></view>
|
|
24
|
+
<view class="oxy-long-press-menu__content">
|
|
25
|
+
<view v-for="(item, index) in menus" :key="index" class="oxy-long-press-menu__item" @click="onMenuClick(item)">
|
|
26
|
+
<text class="oxy-long-press-menu__text">{{ item.text }}</text>
|
|
27
|
+
</view>
|
|
28
|
+
</view>
|
|
29
|
+
</view>
|
|
30
|
+
|
|
31
|
+
<!-- #ifdef APP-PLUS || H5 -->
|
|
32
|
+
<view :prop="selectionProp" :change:prop="selection.propObserver"></view>
|
|
33
|
+
<!-- #endif -->
|
|
34
|
+
</view>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script>
|
|
38
|
+
import { uuid, getRect, unitConvert } from '../common/util'
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
name: 'oxy-long-press-menu',
|
|
42
|
+
props: {
|
|
43
|
+
customClass: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: ''
|
|
46
|
+
},
|
|
47
|
+
customStyle: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: ''
|
|
50
|
+
},
|
|
51
|
+
mode: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: 'normal'
|
|
54
|
+
},
|
|
55
|
+
menus: {
|
|
56
|
+
type: Array,
|
|
57
|
+
default: () => []
|
|
58
|
+
},
|
|
59
|
+
content: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: ''
|
|
62
|
+
},
|
|
63
|
+
visibleArrow: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
data() {
|
|
69
|
+
return {
|
|
70
|
+
elId: `long-press-menu${uuid()}`,
|
|
71
|
+
isVisible: false,
|
|
72
|
+
popoverStyle: {},
|
|
73
|
+
arrowStyle: {},
|
|
74
|
+
rect: null,
|
|
75
|
+
selectedText: '', // 存储选中的文本
|
|
76
|
+
selectionProp: '', // 用于与 renderjs 通信
|
|
77
|
+
arrowBottom: true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
watch: {
|
|
81
|
+
// 监听外部 content 变化
|
|
82
|
+
content(val) {
|
|
83
|
+
if (this.mode === 'normal') {
|
|
84
|
+
this.selectedText = val
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
created() {
|
|
89
|
+
if (this.mode === 'normal') {
|
|
90
|
+
this.selectedText = this.content
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
methods: {
|
|
94
|
+
// --- RenderJS 通信方法 ---
|
|
95
|
+
// 接收 renderjs 发来的选中区域信息
|
|
96
|
+
onSelectionChange(data) {
|
|
97
|
+
if (this.mode !== 'selection') return
|
|
98
|
+
|
|
99
|
+
if (!data) {
|
|
100
|
+
// 清除选中
|
|
101
|
+
if (this.mode === 'selection') {
|
|
102
|
+
this.isVisible = false
|
|
103
|
+
}
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const { text, rect } = data
|
|
108
|
+
if (text && rect) {
|
|
109
|
+
this.selectedText = text
|
|
110
|
+
this.showMenu(rect)
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
// --- 现有逻辑 ---
|
|
115
|
+
onLongPress(e) {
|
|
116
|
+
if (this.mode !== 'normal') return
|
|
117
|
+
|
|
118
|
+
// 获取触发元素的位置
|
|
119
|
+
getRect('.oxy-long-press-menu__trigger', false, this)
|
|
120
|
+
.then((rect) => {
|
|
121
|
+
if (rect) {
|
|
122
|
+
this.showMenu(rect)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.catch(() => {})
|
|
126
|
+
this.$emit('longpress', e)
|
|
127
|
+
},
|
|
128
|
+
showMenu(rect) {
|
|
129
|
+
this.rect = rect
|
|
130
|
+
// 计算气泡位置
|
|
131
|
+
// 默认显示在元素上方
|
|
132
|
+
this.arrowBottom = true // 箭头在底部(气泡在上方)
|
|
133
|
+
let top = rect.top - (this.mode !== 'normal' ? 60 : 10) // 预估气泡高度 + 箭头 + 间距
|
|
134
|
+
let left = rect.left + rect.width / 2
|
|
135
|
+
// 如果上方空间不足,显示在下方
|
|
136
|
+
if (top < 50) {
|
|
137
|
+
// 顶部留一些安全距离
|
|
138
|
+
top = rect.bottom + (this.mode !== 'normal' ? 20 : 60)
|
|
139
|
+
this.arrowBottom = false // 箭头在顶部(气泡在下方)
|
|
140
|
+
}
|
|
141
|
+
this.popoverStyle = {
|
|
142
|
+
top: unitConvert(top, 0, { output: 'px' }),
|
|
143
|
+
left: unitConvert(left, 0, { output: 'px' }),
|
|
144
|
+
animation: 'fadeIn 0.2s ease-out'
|
|
145
|
+
}
|
|
146
|
+
this.arrowStyle = {
|
|
147
|
+
left: unitConvert(rect.width / 2, 0, { output: 'px' })
|
|
148
|
+
}
|
|
149
|
+
this.isVisible = true
|
|
150
|
+
this.$nextTick(() => {
|
|
151
|
+
getRect('.oxy-long-press-menu__popover', false, this)
|
|
152
|
+
.then((prect) => {
|
|
153
|
+
if (prect) {
|
|
154
|
+
const windowWidth = uni.getSystemInfoSync().windowWidth
|
|
155
|
+
let pLeft = left - prect.width / 2
|
|
156
|
+
let arrowLeft = rect.width / 2
|
|
157
|
+
let arrowRight = 'auto'
|
|
158
|
+
if (pLeft < 0) {
|
|
159
|
+
pLeft = rect.left
|
|
160
|
+
} else if (pLeft + prect.width > windowWidth) {
|
|
161
|
+
pLeft = rect.left + rect.width - prect.width
|
|
162
|
+
arrowLeft = 'auto'
|
|
163
|
+
arrowRight = rect.width / 2
|
|
164
|
+
} else {
|
|
165
|
+
arrowLeft = '50%'
|
|
166
|
+
}
|
|
167
|
+
this.popoverStyle.left = unitConvert(pLeft, 0, { output: 'px' })
|
|
168
|
+
this.arrowStyle.left = unitConvert(arrowLeft, 0, { output: 'px' })
|
|
169
|
+
this.arrowStyle.right = unitConvert(arrowRight, 0, { output: 'px' })
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
.catch(() => {})
|
|
173
|
+
})
|
|
174
|
+
// 振动反馈 (仅 Normal 模式或首次显示时)
|
|
175
|
+
if (this.mode === 'normal') {
|
|
176
|
+
uni.vibrateShort()
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
hideMenu() {
|
|
180
|
+
this.isVisible = false
|
|
181
|
+
// 通知 renderjs 清除状态 (可选)
|
|
182
|
+
this.selectionProp = 'clear-' + Date.now()
|
|
183
|
+
},
|
|
184
|
+
onMenuClick(item) {
|
|
185
|
+
// 不要立即 hideMenu,因为可能要操作 selection
|
|
186
|
+
// 但对于 copy,我们通常会操作完后隐藏
|
|
187
|
+
|
|
188
|
+
// 内置复制功能
|
|
189
|
+
if (item.value === 'copy') {
|
|
190
|
+
const textToCopy = this.selectedText || this.content
|
|
191
|
+
if (textToCopy) {
|
|
192
|
+
uni.setClipboardData({
|
|
193
|
+
data: textToCopy,
|
|
194
|
+
success: () => {
|
|
195
|
+
uni.showToast({
|
|
196
|
+
title: '已复制',
|
|
197
|
+
icon: 'none'
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
this.$emit('menu-click', { ...item, content: this.selectedText })
|
|
205
|
+
this.hideMenu()
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
</script>
|
|
210
|
+
|
|
211
|
+
<!-- #ifdef APP-PLUS || H5 -->
|
|
212
|
+
<script module="selection" lang="renderjs">
|
|
213
|
+
module.exports = {
|
|
214
|
+
data() {
|
|
215
|
+
return {
|
|
216
|
+
isSelecting: false,
|
|
217
|
+
ownerId: null,
|
|
218
|
+
selectionDebounce: null
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
mounted() {
|
|
222
|
+
// 获取组件ID
|
|
223
|
+
this.ownerId = this.$el.getAttribute('data-id')
|
|
224
|
+
|
|
225
|
+
// 监听 selectionchange
|
|
226
|
+
document.addEventListener('selectionchange', this.handleSelectionChange)
|
|
227
|
+
// 监听 touchend 用于确定选择结束
|
|
228
|
+
document.addEventListener('touchend', this.handleTouchEnd)
|
|
229
|
+
// 同时也监听当前元素的 touchend,以防冒泡问题
|
|
230
|
+
this.$el.addEventListener('touchend', this.handleTouchEnd)
|
|
231
|
+
document.addEventListener('mouseup', this.handleTouchEnd)
|
|
232
|
+
|
|
233
|
+
// 阻止默认上下文菜单(防止系统菜单冲突)
|
|
234
|
+
this.$el.addEventListener('contextmenu', (e) => {
|
|
235
|
+
// 在 selectable 模式下,如果选区在本组件内,阻止默认菜单
|
|
236
|
+
// 在 normal 模式下,也阻止默认菜单
|
|
237
|
+
e.preventDefault()
|
|
238
|
+
return false
|
|
239
|
+
})
|
|
240
|
+
},
|
|
241
|
+
beforeDestroy() {
|
|
242
|
+
document.removeEventListener('selectionchange', this.handleSelectionChange)
|
|
243
|
+
document.removeEventListener('touchend', this.handleTouchEnd)
|
|
244
|
+
if (this.$el) {
|
|
245
|
+
this.$el.removeEventListener('touchend', this.handleTouchEnd)
|
|
246
|
+
}
|
|
247
|
+
document.removeEventListener('mouseup', this.handleTouchEnd)
|
|
248
|
+
},
|
|
249
|
+
methods: {
|
|
250
|
+
propObserver(newValue, oldValue) {
|
|
251
|
+
if (newValue && newValue.startsWith('clear')) {
|
|
252
|
+
const selection = window.getSelection()
|
|
253
|
+
if (selection) {
|
|
254
|
+
selection.removeAllRanges()
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
handleSelectionChange() {
|
|
259
|
+
// 清除之前的定时器
|
|
260
|
+
if (this.selectionDebounce) clearTimeout(this.selectionDebounce)
|
|
261
|
+
|
|
262
|
+
// 增加防抖检测,以防 touchend 被系统吞掉或未触发
|
|
263
|
+
// 600ms 后如果没有新的 selectionchange,尝试检查选区
|
|
264
|
+
this.selectionDebounce = setTimeout(() => {
|
|
265
|
+
this.checkSelection()
|
|
266
|
+
}, 600)
|
|
267
|
+
},
|
|
268
|
+
handleTouchEnd() {
|
|
269
|
+
// 立即清除防抖,改用短延时检查
|
|
270
|
+
if (this.selectionDebounce) clearTimeout(this.selectionDebounce)
|
|
271
|
+
|
|
272
|
+
// 延时一下确保 selection 状态已更新
|
|
273
|
+
setTimeout(() => {
|
|
274
|
+
this.checkSelection()
|
|
275
|
+
}, 100)
|
|
276
|
+
},
|
|
277
|
+
checkSelection() {
|
|
278
|
+
const selection = window.getSelection()
|
|
279
|
+
// 如果没有选区或选区为空,清除菜单
|
|
280
|
+
if (!selection || selection.rangeCount === 0 || selection.isCollapsed) {
|
|
281
|
+
this.$ownerInstance.callMethod('onSelectionChange', null)
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const text = selection.toString()
|
|
286
|
+
if (!text || !text.trim()) {
|
|
287
|
+
this.$ownerInstance.callMethod('onSelectionChange', null)
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 检查选区是否在这个组件内
|
|
292
|
+
if (!this.isSelectionInThisElement(selection)) {
|
|
293
|
+
// 不属于本组件的选区,应该清除本组件的菜单
|
|
294
|
+
// 这样点击外部或者选择了其他组件的文字时,当前菜单会自动消失
|
|
295
|
+
this.$ownerInstance.callMethod('onSelectionChange', null)
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// 获取选区坐标
|
|
300
|
+
const range = selection.getRangeAt(0)
|
|
301
|
+
const rect = range.getBoundingClientRect()
|
|
302
|
+
|
|
303
|
+
// 转换为纯对象传递
|
|
304
|
+
this.$ownerInstance.callMethod('onSelectionChange', {
|
|
305
|
+
text: text,
|
|
306
|
+
rect: {
|
|
307
|
+
top: rect.top,
|
|
308
|
+
bottom: rect.bottom,
|
|
309
|
+
left: rect.left,
|
|
310
|
+
right: rect.right,
|
|
311
|
+
width: rect.width,
|
|
312
|
+
height: rect.height
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
},
|
|
316
|
+
isSelectionInThisElement(selection) {
|
|
317
|
+
if (!selection) selection = window.getSelection()
|
|
318
|
+
if (selection.rangeCount === 0) return false
|
|
319
|
+
|
|
320
|
+
const range = selection.getRangeAt(0)
|
|
321
|
+
let container = range.commonAncestorContainer
|
|
322
|
+
|
|
323
|
+
// 如果容器是文本节点,取其父元素
|
|
324
|
+
if (container.nodeType === 3) {
|
|
325
|
+
container = container.parentNode
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// 使用 contains 判断选区是否在当前组件根元素内
|
|
329
|
+
return this.$el.contains(container)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
</script>
|
|
334
|
+
<!-- #endif -->
|
|
335
|
+
|
|
336
|
+
<style lang="scss" scoped>
|
|
337
|
+
@import './index.scss';
|
|
338
|
+
</style>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PropType } from 'vue'
|
|
2
|
+
import { baseProps, makeStringProp } from '../common/props'
|
|
3
|
+
|
|
4
|
+
export type LongPressMenuType = 'normal' | 'selection'
|
|
5
|
+
|
|
6
|
+
export type MenusItem = {
|
|
7
|
+
[key: string]: any
|
|
8
|
+
text: string
|
|
9
|
+
value: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const longPressMenuProps = {
|
|
13
|
+
...baseProps,
|
|
14
|
+
/**
|
|
15
|
+
* 模式,'normal' (长按直接弹) | 'selection' (选文后弹 - 仅H5/App)
|
|
16
|
+
* 类型: string
|
|
17
|
+
* 默认值: 'normal'
|
|
18
|
+
*/
|
|
19
|
+
mode: makeStringProp<LongPressMenuType>('normal'),
|
|
20
|
+
/**
|
|
21
|
+
* 菜单项
|
|
22
|
+
* 类型: array
|
|
23
|
+
* 默认值: [{ text: '复制', value: 'copy' }]
|
|
24
|
+
*/
|
|
25
|
+
menus: {
|
|
26
|
+
type: Array as PropType<MenusItem[]>,
|
|
27
|
+
default: () => [{ text: '复制', value: 'copy' }]
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* 要复制的内容,如果不传则不自动处理复制
|
|
31
|
+
* 类型: string
|
|
32
|
+
*/
|
|
33
|
+
content: makeStringProp('')
|
|
34
|
+
}
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
overflow: hidden;
|
|
32
32
|
|
|
33
33
|
@include e(container) {
|
|
34
|
-
width: $-message-box-width;
|
|
35
34
|
box-sizing: border-box;
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -40,7 +39,7 @@
|
|
|
40
39
|
padding: $-message-box-padding;
|
|
41
40
|
|
|
42
41
|
@include when(no-title) {
|
|
43
|
-
padding:
|
|
42
|
+
padding: 50rpx 48rpx 0rpx;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -48,10 +47,10 @@
|
|
|
48
47
|
text-align: center;
|
|
49
48
|
font-size: $-message-box-title-fs;
|
|
50
49
|
color: $-message-box-title-color;
|
|
51
|
-
line-height:
|
|
50
|
+
line-height: 40rpx;
|
|
52
51
|
font-weight: 500;
|
|
53
|
-
padding-top:
|
|
54
|
-
padding-bottom:
|
|
52
|
+
padding-top: 10rpx;
|
|
53
|
+
padding-bottom: 20rpx;
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
@include e(content) {
|
|
@@ -60,7 +59,7 @@
|
|
|
60
59
|
font-size: $-message-box-content-fs;
|
|
61
60
|
text-align: center;
|
|
62
61
|
overflow: auto;
|
|
63
|
-
line-height:
|
|
62
|
+
line-height: 40rpx;
|
|
64
63
|
|
|
65
64
|
&::-webkit-scrollbar {
|
|
66
65
|
width: $-message-box-content-scrollbar-width;
|
|
@@ -74,8 +73,8 @@
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
@include e(input-error) {
|
|
77
|
-
min-height:
|
|
78
|
-
margin-top:
|
|
76
|
+
min-height: 36rpx;
|
|
77
|
+
margin-top: 4rpx;
|
|
79
78
|
color: $-message-box-input-error-color;
|
|
80
79
|
text-align: left;
|
|
81
80
|
|
|
@@ -85,17 +84,19 @@
|
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
@include e(actions) {
|
|
88
|
-
padding:
|
|
87
|
+
padding: 48rpx;
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
@include edeep(actions-btn) {
|
|
92
91
|
&:not(:last-child) {
|
|
93
|
-
margin-right:
|
|
92
|
+
margin-right: 32rpx;
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
@include e(flex) {
|
|
98
97
|
display: flex;
|
|
98
|
+
justify-content: center;
|
|
99
|
+
align-items: center;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
@include e(block) {
|
|
@@ -103,6 +104,6 @@
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
@include e(cancel) {
|
|
106
|
-
margin-right:
|
|
107
|
+
margin-right: 32rpx;
|
|
107
108
|
}
|
|
108
109
|
}
|