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.
Files changed (235) hide show
  1. package/attributes.json +1 -1
  2. package/components/common/abstracts/variable.scss +353 -328
  3. package/components/common/util.ts +185 -32
  4. package/components/composables/index.ts +1 -0
  5. package/components/composables/usePopover.ts +24 -20
  6. package/components/composables/useVirtualScroll.ts +10 -9
  7. package/components/composables/useWindowResize.ts +35 -0
  8. package/components/oxy-action-sheet/index.scss +24 -11
  9. package/components/oxy-action-sheet/oxy-action-sheet.vue +27 -19
  10. package/components/oxy-action-sheet/types.ts +7 -0
  11. package/components/oxy-backtop/index.scss +3 -3
  12. package/components/oxy-backtop/oxy-backtop.vue +9 -6
  13. package/components/oxy-backtop/types.ts +7 -7
  14. package/components/oxy-badge/index.scss +4 -4
  15. package/components/oxy-badge/oxy-badge.vue +3 -3
  16. package/components/oxy-badge/types.ts +2 -2
  17. package/components/oxy-button/index.scss +5 -5
  18. package/components/oxy-button/oxy-button.vue +5 -1
  19. package/components/oxy-calendar/index.scss +11 -11
  20. package/components/oxy-calendar/oxy-calendar.vue +1 -0
  21. package/components/oxy-calendar/types.ts +5 -0
  22. package/components/oxy-calendar-view/month/index.scss +4 -4
  23. package/components/oxy-calendar-view/month/types.ts +36 -0
  24. package/components/oxy-calendar-view/monthPanel/index.scss +7 -7
  25. package/components/oxy-calendar-view/monthPanel/month-panel.vue +14 -8
  26. package/components/oxy-calendar-view/year/index.scss +4 -4
  27. package/components/oxy-calendar-view/yearPanel/index.scss +4 -4
  28. package/components/oxy-calendar-view/yearPanel/year-panel.vue +21 -5
  29. package/components/oxy-card/index.scss +2 -2
  30. package/components/oxy-cell/index.scss +8 -8
  31. package/components/oxy-checkbox/index.scss +7 -7
  32. package/components/oxy-checkbox-group/index.scss +2 -2
  33. package/components/oxy-circle/oxy-circle.vue +10 -7
  34. package/components/oxy-circle/types.ts +5 -5
  35. package/components/oxy-col/oxy-col.vue +2 -2
  36. package/components/oxy-col-picker/index.scss +4 -4
  37. package/components/oxy-col-picker/oxy-col-picker.vue +6 -5
  38. package/components/oxy-col-picker/types.ts +7 -2
  39. package/components/oxy-collapse/index.scss +2 -2
  40. package/components/oxy-collapse-item/oxy-collapse-item.vue +3 -3
  41. package/components/oxy-corner/index.scss +32 -32
  42. package/components/oxy-count-to/oxy-count-to.vue +3 -3
  43. package/components/oxy-curtain/index.scss +15 -15
  44. package/components/oxy-curtain/oxy-curtain.vue +4 -2
  45. package/components/oxy-curtain/types.ts +6 -1
  46. package/components/oxy-date-strip/oxy-date-strip.vue +2 -2
  47. package/components/oxy-date-strip/types.ts +1 -1
  48. package/components/oxy-date-strip-item/index.scss +3 -3
  49. package/components/oxy-datetime-picker/index.scss +11 -11
  50. package/components/oxy-datetime-picker/oxy-datetime-picker.vue +1 -0
  51. package/components/oxy-datetime-picker/types.ts +5 -0
  52. package/components/oxy-drop-menu/index.scss +3 -3
  53. package/components/oxy-drop-menu/oxy-drop-menu.vue +3 -3
  54. package/components/oxy-drop-menu-item/index.scss +1 -1
  55. package/components/oxy-drop-menu-item/oxy-drop-menu-item.vue +4 -3
  56. package/components/oxy-drop-menu-item/types.ts +5 -0
  57. package/components/oxy-echarts/types.ts +6 -0
  58. package/components/oxy-fab/index.scss +8 -8
  59. package/components/oxy-fab/oxy-fab.vue +22 -3
  60. package/components/oxy-file-list/index.scss +24 -23
  61. package/components/oxy-file-list/oxy-file-list.vue +2 -2
  62. package/components/oxy-floating-panel/oxy-floating-panel.vue +13 -9
  63. package/components/oxy-floating-panel/{type.ts → types.ts} +8 -8
  64. package/components/oxy-footer/index.scss +19 -0
  65. package/components/oxy-footer/oxy-footer.vue +78 -0
  66. package/components/oxy-footer/types.ts +17 -0
  67. package/components/oxy-form-item/types.ts +22 -1
  68. package/components/oxy-gap/oxy-gap.vue +2 -2
  69. package/components/oxy-gap/types.ts +2 -2
  70. package/components/oxy-grid/oxy-grid.vue +1 -1
  71. package/components/oxy-grid/types.ts +1 -1
  72. package/components/oxy-grid-item/index.scss +1 -1
  73. package/components/oxy-grid-item/oxy-grid-item.vue +7 -5
  74. package/components/oxy-grid-item/types.ts +1 -1
  75. package/components/oxy-guidance/index.scss +75 -0
  76. package/components/oxy-guidance/oxy-guidance.vue +201 -0
  77. package/components/oxy-guidance/types.ts +33 -0
  78. package/components/oxy-icon/oxy-icon.vue +2 -2
  79. package/components/oxy-icon/types.ts +1 -1
  80. package/components/oxy-img/oxy-img.vue +4 -4
  81. package/components/oxy-img/types.ts +3 -3
  82. package/components/oxy-img-cropper/index.scss +12 -12
  83. package/components/oxy-img-cropper/oxy-img-cropper.vue +97 -52
  84. package/components/oxy-img-cropper/types.ts +2 -2
  85. package/components/oxy-img-lazy/oxy-img-lazy.vue +3 -3
  86. package/components/oxy-img-lazy/types.ts +3 -3
  87. package/components/oxy-index-anchor/index.scss +2 -2
  88. package/components/oxy-index-anchor/oxy-index-anchor.vue +2 -2
  89. package/components/oxy-index-anchor/{type.ts → types.ts} +3 -0
  90. package/components/oxy-index-bar/index.scss +3 -3
  91. package/components/oxy-index-bar/oxy-index-bar.vue +3 -3
  92. package/components/oxy-index-bar/{type.ts → types.ts} +2 -2
  93. package/components/oxy-input/index.scss +1 -1
  94. package/components/oxy-input-number/index.scss +5 -5
  95. package/components/oxy-input-number/oxy-input-number.vue +2 -2
  96. package/components/oxy-input-number/types.ts +3 -2
  97. package/components/oxy-keyboard/index.scss +5 -5
  98. package/components/oxy-keyboard/key/index.scss +3 -3
  99. package/components/oxy-keyboard/key/index.vue +2 -2
  100. package/components/oxy-keyboard/key/types.ts +15 -0
  101. package/components/oxy-keyboard/oxy-keyboard.vue +1 -0
  102. package/components/oxy-keyboard/types.ts +5 -0
  103. package/components/oxy-link/index.scss +2 -2
  104. package/components/oxy-list/oxy-list.vue +4 -3
  105. package/components/oxy-loading/oxy-loading.vue +8 -4
  106. package/components/oxy-loading/types.ts +1 -1
  107. package/components/oxy-loadmore/index.scss +3 -3
  108. package/components/oxy-long-press-menu/index.scss +93 -0
  109. package/components/oxy-long-press-menu/oxy-long-press-menu.vue +338 -0
  110. package/components/oxy-long-press-menu/types.ts +34 -0
  111. package/components/oxy-message-box/index.scss +12 -11
  112. package/components/oxy-message-box/oxy-message-box.vue +11 -3
  113. package/components/oxy-message-box/types.ts +14 -0
  114. package/components/oxy-navbar/index.scss +2 -2
  115. package/components/oxy-navbar/oxy-navbar.vue +58 -13
  116. package/components/oxy-navbar/types.ts +8 -1
  117. package/components/oxy-navbar-capsule/types.ts +3 -0
  118. package/components/oxy-notice-bar/index.scss +3 -3
  119. package/components/oxy-notice-bar/oxy-notice-bar.vue +9 -5
  120. package/components/oxy-notice-bar/types.ts +3 -3
  121. package/components/oxy-notify/index.ts +1 -0
  122. package/components/oxy-notify/oxy-notify.vue +3 -2
  123. package/components/oxy-notify/types.ts +7 -0
  124. package/components/oxy-pagination/index.scss +1 -1
  125. package/components/oxy-password-input/oxy-password-input.vue +2 -2
  126. package/components/oxy-password-input/types.ts +1 -1
  127. package/components/oxy-picker/index.scss +45 -2
  128. package/components/oxy-picker/oxy-picker.vue +100 -14
  129. package/components/oxy-picker/types.ts +29 -1
  130. package/components/oxy-picker-view/index.scss +3 -3
  131. package/components/oxy-picker-view/oxy-picker-view.vue +4 -4
  132. package/components/oxy-popover/index.scss +9 -9
  133. package/components/oxy-popup/index.scss +2 -2
  134. package/components/oxy-popup/oxy-popup.vue +35 -2
  135. package/components/oxy-popup/types.ts +8 -1
  136. package/components/oxy-progress/index.scss +3 -3
  137. package/components/oxy-qrcode/draw.ts +398 -0
  138. package/components/oxy-qrcode/index.scss +2 -0
  139. package/components/oxy-qrcode/oxy-qrcode.vue +124 -0
  140. package/components/oxy-qrcode/qrcode.ts +936 -0
  141. package/components/oxy-qrcode/types.ts +42 -0
  142. package/components/oxy-radio/index.scss +10 -10
  143. package/components/oxy-radio-group/index.scss +2 -2
  144. package/components/oxy-rate/types.ts +4 -4
  145. package/components/oxy-resize/index.scss +2 -2
  146. package/components/oxy-resize/oxy-resize.vue +4 -4
  147. package/components/oxy-resize/types.ts +3 -0
  148. package/components/oxy-rich-text/index.scss +30 -29
  149. package/components/oxy-rich-text/mp-html/mp-html.vue +33 -24
  150. package/components/oxy-rich-text/mp-html/node/node.vue +30 -19
  151. package/components/oxy-rich-text/oxy-rich-text.vue +31 -31
  152. package/components/oxy-rich-text/types.ts +6 -1
  153. package/components/oxy-row/oxy-row.vue +3 -3
  154. package/components/oxy-row/types.ts +1 -1
  155. package/components/oxy-search/index.scss +3 -3
  156. package/components/oxy-segmented/index.scss +16 -16
  157. package/components/oxy-segmented/oxy-segmented.vue +23 -3
  158. package/components/oxy-select/index.scss +144 -68
  159. package/components/oxy-select/oxy-select.vue +85 -50
  160. package/components/oxy-select/types.ts +13 -1
  161. package/components/oxy-select-picker/index.scss +7 -7
  162. package/components/oxy-select-picker/oxy-select-picker.vue +1 -0
  163. package/components/oxy-select-picker/types.ts +2 -0
  164. package/components/oxy-sidebar-item/index.scss +1 -1
  165. package/components/oxy-signature/oxy-signature.vue +18 -10
  166. package/components/oxy-signature/types.ts +106 -13
  167. package/components/oxy-skeleton/oxy-skeleton.vue +6 -6
  168. package/components/oxy-skeleton/types.ts +1 -1
  169. package/components/oxy-slider/index.scss +3 -3
  170. package/components/oxy-sort-button/index.scss +8 -8
  171. package/components/oxy-status-tip/index.scss +4 -4
  172. package/components/oxy-status-tip/oxy-status-tip.vue +5 -5
  173. package/components/oxy-status-tip/types.ts +3 -3
  174. package/components/oxy-step/index.scss +14 -14
  175. package/components/oxy-sticky/oxy-sticky.vue +6 -6
  176. package/components/oxy-stream-render/types.ts +4 -1
  177. package/components/oxy-swipe-action/oxy-swipe-action.vue +27 -2
  178. package/components/oxy-swiper/oxy-swiper.vue +6 -6
  179. package/components/oxy-swiper/types.ts +5 -5
  180. package/components/oxy-switch/index.scss +8 -8
  181. package/components/oxy-switch/oxy-switch.vue +2 -2
  182. package/components/oxy-switch/types.ts +1 -1
  183. package/components/oxy-tab/index.scss +11 -1
  184. package/components/oxy-tabbar/index.scss +1 -1
  185. package/components/oxy-tabbar/oxy-tabbar.vue +39 -10
  186. package/components/oxy-table/index.scss +5 -5
  187. package/components/oxy-table/oxy-table.vue +8 -6
  188. package/components/oxy-table/types.ts +2 -2
  189. package/components/oxy-table-col/oxy-table-col.vue +3 -3
  190. package/components/oxy-table-col/types.ts +2 -2
  191. package/components/oxy-tabs/index.scss +43 -15
  192. package/components/oxy-tabs/oxy-tabs.vue +53 -19
  193. package/components/oxy-tabs/types.ts +15 -3
  194. package/components/oxy-tag/index.scss +15 -15
  195. package/components/oxy-text/index.scss +5 -1
  196. package/components/oxy-text/oxy-text.vue +76 -7
  197. package/components/oxy-text/types.ts +12 -0
  198. package/components/oxy-textarea/index.scss +6 -6
  199. package/components/oxy-toast/oxy-toast.vue +24 -8
  200. package/components/oxy-tooltip/index.scss +9 -9
  201. package/components/oxy-tree/index.scss +51 -15
  202. package/components/oxy-tree/oxy-tree.vue +13 -9
  203. package/components/oxy-tree/types.ts +12 -9
  204. package/components/oxy-upload/index.scss +21 -21
  205. package/components/oxy-upload/types.ts +2 -2
  206. package/components/oxy-verification-code/index.scss +6 -0
  207. package/components/oxy-verification-code/oxy-verification-code.vue +187 -0
  208. package/components/oxy-verification-code/types.ts +82 -0
  209. package/components/oxy-video-preview/index.scss +4 -4
  210. package/components/oxy-virtual-scroll/index.scss +4 -4
  211. package/components/oxy-virtual-scroll/oxy-virtual-scroll.vue +11 -7
  212. package/components/oxy-virtual-scroll/types.ts +14 -14
  213. package/components/oxy-voice-player/index.scss +908 -0
  214. package/components/oxy-voice-player/oxy-voice-player.vue +821 -0
  215. package/components/oxy-voice-player/types.ts +567 -0
  216. package/components/oxy-waterfall/oxy-waterfall.vue +6 -6
  217. package/components/oxy-waterfall/types.ts +6 -6
  218. package/components/oxy-watermark/oxy-watermark.vue +35 -13
  219. package/components/oxy-watermark/types.ts +14 -14
  220. package/global.d.ts +2 -0
  221. package/locale/lang/ar-SA.ts +3 -0
  222. package/locale/lang/en-US.ts +3 -0
  223. package/locale/lang/zh-CN.ts +3 -0
  224. package/package.json +97 -1
  225. package/tags.json +1 -1
  226. package/web-types.json +1 -1
  227. package/components/oxy-number-keyboard/index.scss +0 -78
  228. package/components/oxy-number-keyboard/key/index.scss +0 -81
  229. package/components/oxy-number-keyboard/key/index.vue +0 -78
  230. package/components/oxy-number-keyboard/key/types.ts +0 -11
  231. package/components/oxy-number-keyboard/oxy-number-keyboard.vue +0 -151
  232. package/components/oxy-number-keyboard/types.ts +0 -83
  233. package/components/oxy-tree/components/tree-node-content.vue +0 -72
  234. package/components/oxy-tree/index.ts +0 -51
  235. package/oxy-uni-ui.zip +0 -0
@@ -48,10 +48,10 @@
48
48
  }
49
49
 
50
50
  &__prefix-icon:not(:empty) + &__content:not(:empty) {
51
- padding-left: 4px;
51
+ padding-left: 8rpx;
52
52
  }
53
53
 
54
54
  &__content:not(:empty) + &__suffix-icon:not(:empty) {
55
- padding-left: 4px;
55
+ padding-left: 8rpx;
56
56
  }
57
57
  }
@@ -28,8 +28,8 @@
28
28
  @refresherrestore="onRestore"
29
29
  @refresherabort="onAbort"
30
30
  >
31
- <view class="oxy-virtual-scroll__container" :style="{ height: totalHeight + 'px' }">
32
- <view class="oxy-virtual-scroll__items" :style="{ transform: `translateY(${virtualOffsetY}px)` }">
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="20px"></oxy-icon>
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, addUnit, isDef } from '../common/util'
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
- iconSize.value = addUnit(newVal)
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 = addUnit(iconSize.value)
70
- style.width = addUnit(iconSize.value)
73
+ style.height = iconSize.value
74
+ style.width = iconSize.value
71
75
  }
72
76
  return `${objToStyle(style)} ${props.customStyle}`
73
77
  })
@@ -14,7 +14,7 @@ export const loadingProps = {
14
14
  */
15
15
  color: makeStringProp('#4D80F0'),
16
16
  /**
17
- * 设置加载指示器大小
17
+ * 设置加载指示器大小,number 类型按 `rpx` 语义处理
18
18
  */
19
19
  size: makeNumericProp('')
20
20
  }
@@ -15,7 +15,7 @@
15
15
 
16
16
  @include edeep(loading) {
17
17
  display: inline-block;
18
- margin-right: 8px;
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 6px;
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: 25px 24px 0px;
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: 20px;
50
+ line-height: 40rpx;
52
51
  font-weight: 500;
53
- padding-top: 5px;
54
- padding-bottom: 10px;
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: 20px;
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: 18px;
78
- margin-top: 2px;
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: 24px;
87
+ padding: 48rpx;
89
88
  }
90
89
 
91
90
  @include edeep(actions-btn) {
92
91
  &:not(:last-child) {
93
- margin-right: 16px;
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: 16px;
107
+ margin-right: 32rpx;
107
108
  }
108
109
  }