@gmcb/uv-ui 0.2.26

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 (285) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/LICENSE +21 -0
  3. package/README.md +164 -0
  4. package/components/uv-action-sheet/props.js +50 -0
  5. package/components/uv-action-sheet/uv-action-sheet.vue +280 -0
  6. package/components/uv-album/uv-album.vue +312 -0
  7. package/components/uv-alert/props.js +45 -0
  8. package/components/uv-alert/uv-alert.vue +246 -0
  9. package/components/uv-avatar/props.js +85 -0
  10. package/components/uv-avatar/uv-avatar.vue +182 -0
  11. package/components/uv-avatar-group/props.js +53 -0
  12. package/components/uv-avatar-group/uv-avatar-group.vue +106 -0
  13. package/components/uv-back-top/props.js +58 -0
  14. package/components/uv-back-top/uv-back-top.vue +116 -0
  15. package/components/uv-badge/props.js +73 -0
  16. package/components/uv-badge/uv-badge.vue +176 -0
  17. package/components/uv-button/nvue.scss +46 -0
  18. package/components/uv-button/props.js +163 -0
  19. package/components/uv-button/uv-button.vue +529 -0
  20. package/components/uv-button/vue.scss +93 -0
  21. package/components/uv-calendar/calendar.js +546 -0
  22. package/components/uv-calendar/header.vue +104 -0
  23. package/components/uv-calendar/month.vue +616 -0
  24. package/components/uv-calendar/props.js +145 -0
  25. package/components/uv-calendar/uv-calendar.vue +390 -0
  26. package/components/uv-calendars/calendar-body.vue +376 -0
  27. package/components/uv-calendars/calendar-item.vue +248 -0
  28. package/components/uv-calendars/calendar.js +546 -0
  29. package/components/uv-calendars/i18n/en.json +12 -0
  30. package/components/uv-calendars/i18n/index.js +8 -0
  31. package/components/uv-calendars/i18n/zh-Hans.json +12 -0
  32. package/components/uv-calendars/i18n/zh-Hant.json +12 -0
  33. package/components/uv-calendars/util.js +435 -0
  34. package/components/uv-calendars/uv-calendars.vue +452 -0
  35. package/components/uv-cell/props.js +116 -0
  36. package/components/uv-cell/uv-cell.vue +209 -0
  37. package/components/uv-cell-group/props.js +15 -0
  38. package/components/uv-cell-group/uv-cell-group.vue +63 -0
  39. package/components/uv-checkbox/props.js +70 -0
  40. package/components/uv-checkbox/uv-checkbox.vue +371 -0
  41. package/components/uv-checkbox-group/props.js +84 -0
  42. package/components/uv-checkbox-group/uv-checkbox-group.vue +119 -0
  43. package/components/uv-code/props.js +35 -0
  44. package/components/uv-code/uv-code.vue +136 -0
  45. package/components/uv-code-input/props.js +83 -0
  46. package/components/uv-code-input/uv-code-input.vue +272 -0
  47. package/components/uv-col/props.js +30 -0
  48. package/components/uv-col/uv-col.vue +165 -0
  49. package/components/uv-collapse/props.js +20 -0
  50. package/components/uv-collapse/uv-collapse.vue +86 -0
  51. package/components/uv-collapse-item/props.js +60 -0
  52. package/components/uv-collapse-item/uv-collapse-item.vue +228 -0
  53. package/components/uv-column-notice/props.js +61 -0
  54. package/components/uv-column-notice/uv-column-notice.vue +176 -0
  55. package/components/uv-count-down/props.js +25 -0
  56. package/components/uv-count-down/utils.js +62 -0
  57. package/components/uv-count-down/uv-count-down.vue +169 -0
  58. package/components/uv-count-to/props.js +60 -0
  59. package/components/uv-count-to/uv-count-to.vue +187 -0
  60. package/components/uv-datetime-picker/props.js +130 -0
  61. package/components/uv-datetime-picker/uv-datetime-picker.vue +355 -0
  62. package/components/uv-divider/props.js +45 -0
  63. package/components/uv-divider/uv-divider.vue +113 -0
  64. package/components/uv-drop-down/uv-drop-down.vue +135 -0
  65. package/components/uv-drop-down-item/uv-drop-down-item.vue +169 -0
  66. package/components/uv-drop-down-popup/uv-drop-down-popup.vue +242 -0
  67. package/components/uv-empty/props.js +60 -0
  68. package/components/uv-empty/uv-empty.vue +126 -0
  69. package/components/uv-form/props.js +46 -0
  70. package/components/uv-form/uv-form.vue +209 -0
  71. package/components/uv-form/valid.js +1343 -0
  72. package/components/uv-form-item/props.js +49 -0
  73. package/components/uv-form-item/uv-form-item.vue +226 -0
  74. package/components/uv-gap/props.js +25 -0
  75. package/components/uv-gap/uv-gap.vue +36 -0
  76. package/components/uv-grid/props.js +20 -0
  77. package/components/uv-grid/uv-grid.vue +100 -0
  78. package/components/uv-grid-item/props.js +15 -0
  79. package/components/uv-grid-item/uv-grid-item.vue +223 -0
  80. package/components/uv-icon/icons.js +160 -0
  81. package/components/uv-icon/props.js +90 -0
  82. package/components/uv-icon/uv-icon.vue +226 -0
  83. package/components/uv-icon/uvicons.ttf +0 -0
  84. package/components/uv-image/props.js +100 -0
  85. package/components/uv-image/uv-image.vue +296 -0
  86. package/components/uv-index-anchor/props.js +30 -0
  87. package/components/uv-index-anchor/uv-index-anchor.vue +98 -0
  88. package/components/uv-index-item/uv-index-item.vue +87 -0
  89. package/components/uv-index-list/props.js +30 -0
  90. package/components/uv-index-list/uv-index-list.vue +461 -0
  91. package/components/uv-input/props.js +175 -0
  92. package/components/uv-input/uv-input.vue +348 -0
  93. package/components/uv-keyboard/props.js +95 -0
  94. package/components/uv-keyboard/uv-keyboard.vue +180 -0
  95. package/components/uv-keyboard-car/props.js +24 -0
  96. package/components/uv-keyboard-car/uv-keyboard-car.vue +347 -0
  97. package/components/uv-keyboard-number/props.js +19 -0
  98. package/components/uv-keyboard-number/uv-keyboard-number.vue +201 -0
  99. package/components/uv-line/props.js +34 -0
  100. package/components/uv-line/uv-line.vue +60 -0
  101. package/components/uv-line-progress/props.js +29 -0
  102. package/components/uv-line-progress/uv-line-progress.vue +146 -0
  103. package/components/uv-link/props.js +40 -0
  104. package/components/uv-link/uv-link.vue +83 -0
  105. package/components/uv-list/uv-list.vue +147 -0
  106. package/components/uv-list-item/uv-list-item.vue +535 -0
  107. package/components/uv-load-more/props.js +95 -0
  108. package/components/uv-load-more/uv-load-more.vue +152 -0
  109. package/components/uv-loading-icon/props.js +67 -0
  110. package/components/uv-loading-icon/uv-loading-icon.vue +347 -0
  111. package/components/uv-loading-page/props.js +55 -0
  112. package/components/uv-loading-page/uv-loading-page.vue +96 -0
  113. package/components/uv-modal/props.js +90 -0
  114. package/components/uv-modal/uv-modal.vue +245 -0
  115. package/components/uv-navbar/props.js +89 -0
  116. package/components/uv-navbar/uv-navbar.vue +245 -0
  117. package/components/uv-no-network/props.js +20 -0
  118. package/components/uv-no-network/uv-no-network.vue +222 -0
  119. package/components/uv-notice-bar/props.js +76 -0
  120. package/components/uv-notice-bar/uv-notice-bar.vue +110 -0
  121. package/components/uv-notify/props.js +45 -0
  122. package/components/uv-notify/uv-notify.vue +220 -0
  123. package/components/uv-number-box/props.js +118 -0
  124. package/components/uv-number-box/uv-number-box.vue +397 -0
  125. package/components/uv-overlay/props.js +25 -0
  126. package/components/uv-overlay/uv-overlay.vue +85 -0
  127. package/components/uv-parse/node/node.vue +576 -0
  128. package/components/uv-parse/parser.js +1335 -0
  129. package/components/uv-parse/uv-parse.vue +498 -0
  130. package/components/uv-pick-color/colors.js +217 -0
  131. package/components/uv-pick-color/props.js +47 -0
  132. package/components/uv-pick-color/uv-pick-color.vue +551 -0
  133. package/components/uv-picker/props.js +95 -0
  134. package/components/uv-picker/uv-picker.vue +329 -0
  135. package/components/uv-popup/keypress.js +45 -0
  136. package/components/uv-popup/uv-popup.vue +537 -0
  137. package/components/uv-preview-video/uv-preview-video.vue +52 -0
  138. package/components/uv-qrcode/cache.js +1 -0
  139. package/components/uv-qrcode/gcanvas/bridge/bridge-weex.js +241 -0
  140. package/components/uv-qrcode/gcanvas/context-2d/FillStyleLinearGradient.js +18 -0
  141. package/components/uv-qrcode/gcanvas/context-2d/FillStylePattern.js +8 -0
  142. package/components/uv-qrcode/gcanvas/context-2d/FillStyleRadialGradient.js +17 -0
  143. package/components/uv-qrcode/gcanvas/context-2d/RenderingContext.js +666 -0
  144. package/components/uv-qrcode/gcanvas/context-webgl/ActiveInfo.js +11 -0
  145. package/components/uv-qrcode/gcanvas/context-webgl/Buffer.js +21 -0
  146. package/components/uv-qrcode/gcanvas/context-webgl/Framebuffer.js +21 -0
  147. package/components/uv-qrcode/gcanvas/context-webgl/GLenum.js +298 -0
  148. package/components/uv-qrcode/gcanvas/context-webgl/GLmethod.js +142 -0
  149. package/components/uv-qrcode/gcanvas/context-webgl/GLtype.js +23 -0
  150. package/components/uv-qrcode/gcanvas/context-webgl/Program.js +21 -0
  151. package/components/uv-qrcode/gcanvas/context-webgl/Renderbuffer.js +21 -0
  152. package/components/uv-qrcode/gcanvas/context-webgl/RenderingContext.js +1191 -0
  153. package/components/uv-qrcode/gcanvas/context-webgl/Shader.js +22 -0
  154. package/components/uv-qrcode/gcanvas/context-webgl/ShaderPrecisionFormat.js +11 -0
  155. package/components/uv-qrcode/gcanvas/context-webgl/Texture.js +22 -0
  156. package/components/uv-qrcode/gcanvas/context-webgl/UniformLocation.js +22 -0
  157. package/components/uv-qrcode/gcanvas/context-webgl/classUtils.js +3 -0
  158. package/components/uv-qrcode/gcanvas/env/canvas.js +74 -0
  159. package/components/uv-qrcode/gcanvas/env/image.js +96 -0
  160. package/components/uv-qrcode/gcanvas/env/tool.js +24 -0
  161. package/components/uv-qrcode/gcanvas/index.js +39 -0
  162. package/components/uv-qrcode/props.js +85 -0
  163. package/components/uv-qrcode/qrcode.js +34 -0
  164. package/components/uv-qrcode/queue.js +41 -0
  165. package/components/uv-qrcode/uv-qrcode.vue +1038 -0
  166. package/components/uv-radio/props.js +65 -0
  167. package/components/uv-radio/uv-radio.vue +349 -0
  168. package/components/uv-radio-group/props.js +89 -0
  169. package/components/uv-radio-group/uv-radio-group.vue +115 -0
  170. package/components/uv-rate/props.js +73 -0
  171. package/components/uv-rate/uv-rate.vue +274 -0
  172. package/components/uv-read-more/props.js +62 -0
  173. package/components/uv-read-more/uv-read-more.vue +162 -0
  174. package/components/uv-row/props.js +20 -0
  175. package/components/uv-row/uv-row.vue +95 -0
  176. package/components/uv-row-notice/props.js +40 -0
  177. package/components/uv-row-notice/uv-row-notice.vue +341 -0
  178. package/components/uv-safe-bottom/uv-safe-bottom.vue +67 -0
  179. package/components/uv-scroll-list/nvue.js +29 -0
  180. package/components/uv-scroll-list/props.js +35 -0
  181. package/components/uv-scroll-list/scrollWxs.wxs +51 -0
  182. package/components/uv-scroll-list/uv-scroll-list.vue +218 -0
  183. package/components/uv-search/props.js +127 -0
  184. package/components/uv-search/uv-search.vue +311 -0
  185. package/components/uv-skeleton/props.js +65 -0
  186. package/components/uv-skeleton/uv-skeleton.vue +250 -0
  187. package/components/uv-skeletons/uv-skeletons.vue +247 -0
  188. package/components/uv-slider/props.js +58 -0
  189. package/components/uv-slider/uv-slider.vue +58 -0
  190. package/components/uv-status-bar/props.js +8 -0
  191. package/components/uv-status-bar/uv-status-bar.vue +54 -0
  192. package/components/uv-steps/props.js +40 -0
  193. package/components/uv-steps/uv-steps.vue +83 -0
  194. package/components/uv-steps-item/props.js +25 -0
  195. package/components/uv-steps-item/uv-steps-item.vue +347 -0
  196. package/components/uv-sticky/props.js +41 -0
  197. package/components/uv-sticky/uv-sticky.vue +223 -0
  198. package/components/uv-subsection/props.js +54 -0
  199. package/components/uv-subsection/uv-subsection.vue +269 -0
  200. package/components/uv-swipe-action/props.js +10 -0
  201. package/components/uv-swipe-action/uv-swipe-action.vue +65 -0
  202. package/components/uv-swipe-action-item/index - backup.wxs +256 -0
  203. package/components/uv-swipe-action-item/index.wxs +225 -0
  204. package/components/uv-swipe-action-item/nvue - backup.js +264 -0
  205. package/components/uv-swipe-action-item/nvue.js +182 -0
  206. package/components/uv-swipe-action-item/props.js +40 -0
  207. package/components/uv-swipe-action-item/uv-swipe-action-item.vue +200 -0
  208. package/components/uv-swipe-action-item/wxs.js +15 -0
  209. package/components/uv-swiper/props.js +136 -0
  210. package/components/uv-swiper/uv-swiper.vue +263 -0
  211. package/components/uv-swiper-indicator/props.js +30 -0
  212. package/components/uv-swiper-indicator/uv-swiper-indicator.vue +112 -0
  213. package/components/uv-switch/props.js +58 -0
  214. package/components/uv-switch/uv-switch.vue +182 -0
  215. package/components/uv-tabbar/props.js +50 -0
  216. package/components/uv-tabbar/uv-tabbar.vue +146 -0
  217. package/components/uv-tabbar-item/props.js +40 -0
  218. package/components/uv-tabbar-item/uv-tabbar-item.vue +146 -0
  219. package/components/uv-tabs/props.js +71 -0
  220. package/components/uv-tabs/uv-tabs.vue +391 -0
  221. package/components/uv-tags/props.js +104 -0
  222. package/components/uv-tags/uv-tags.vue +379 -0
  223. package/components/uv-text/props.js +113 -0
  224. package/components/uv-text/uv-text.vue +218 -0
  225. package/components/uv-text/value.js +87 -0
  226. package/components/uv-textarea/props.js +138 -0
  227. package/components/uv-textarea/uv-textarea.vue +238 -0
  228. package/components/uv-toast/uv-toast.vue +292 -0
  229. package/components/uv-toolbar/props.js +40 -0
  230. package/components/uv-toolbar/uv-toolbar.vue +109 -0
  231. package/components/uv-tooltip/props.js +60 -0
  232. package/components/uv-tooltip/uv-tooltip.vue +372 -0
  233. package/components/uv-transition/createAnimation.js +131 -0
  234. package/components/uv-transition/props.js +31 -0
  235. package/components/uv-transition/uv-transition.vue +320 -0
  236. package/components/uv-upload/mixin.js +22 -0
  237. package/components/uv-upload/props.js +130 -0
  238. package/components/uv-upload/utils.js +151 -0
  239. package/components/uv-upload/uv-upload.vue +488 -0
  240. package/components/uv-vtabs/props.js +79 -0
  241. package/components/uv-vtabs/uv-vtabs.vue +438 -0
  242. package/components/uv-vtabs-item/uv-vtabs-item.vue +68 -0
  243. package/components/uv-waterfall/props.js +69 -0
  244. package/components/uv-waterfall/uv-waterfall.vue +265 -0
  245. package/index.js +82 -0
  246. package/index.scss +7 -0
  247. package/libs/config/config.js +34 -0
  248. package/libs/css/color.scss +32 -0
  249. package/libs/css/common.scss +100 -0
  250. package/libs/css/components.scss +23 -0
  251. package/libs/css/variable.scss +111 -0
  252. package/libs/css/vue.scss +40 -0
  253. package/libs/function/colorGradient.js +134 -0
  254. package/libs/function/compress.js +27 -0
  255. package/libs/function/debounce.js +29 -0
  256. package/libs/function/digit.js +167 -0
  257. package/libs/function/index.js +734 -0
  258. package/libs/function/platform.js +75 -0
  259. package/libs/function/test.js +287 -0
  260. package/libs/function/throttle.js +30 -0
  261. package/libs/luch-request/adapters/index.js +132 -0
  262. package/libs/luch-request/core/InterceptorManager.js +51 -0
  263. package/libs/luch-request/core/Request.js +201 -0
  264. package/libs/luch-request/core/buildFullPath.js +20 -0
  265. package/libs/luch-request/core/defaults.js +33 -0
  266. package/libs/luch-request/core/dispatchRequest.js +6 -0
  267. package/libs/luch-request/core/mergeConfig.js +126 -0
  268. package/libs/luch-request/core/settle.js +16 -0
  269. package/libs/luch-request/helpers/buildURL.js +64 -0
  270. package/libs/luch-request/helpers/combineURLs.js +14 -0
  271. package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
  272. package/libs/luch-request/index.d.ts +197 -0
  273. package/libs/luch-request/index.js +2 -0
  274. package/libs/luch-request/utils/clone.js +264 -0
  275. package/libs/luch-request/utils.js +135 -0
  276. package/libs/mixin/button.js +13 -0
  277. package/libs/mixin/mixin.js +172 -0
  278. package/libs/mixin/mpMixin.js +8 -0
  279. package/libs/mixin/mpShare.js +13 -0
  280. package/libs/mixin/openType.js +47 -0
  281. package/libs/mixin/touch.js +59 -0
  282. package/libs/util/dayjs.js +216 -0
  283. package/libs/util/route.js +126 -0
  284. package/package.json +28 -0
  285. package/theme.scss +43 -0
@@ -0,0 +1,264 @@
1
+ // nvue操作dom的库,用于获取dom的尺寸信息
2
+ const dom = uni.requireNativePlugin('dom')
3
+ // nvue中用于操作元素动画的库,类似于uni.animation,只不过uni.animation不能用于nvue
4
+ const animation = uni.requireNativePlugin('animation')
5
+ import { sleep } from '../../libs/function/index.js'
6
+ export default {
7
+ data() {
8
+ return {
9
+ // 是否滑动中
10
+ moving: false,
11
+ // 状态,open-打开状态,close-关闭状态
12
+ status: 'close',
13
+ // 开始触摸点的X和Y轴坐标
14
+ startX: 0,
15
+ startY: 0,
16
+ // 所有隐藏按钮的尺寸信息数组
17
+ buttons: [],
18
+ // 所有按钮的总宽度
19
+ buttonsWidth: 0,
20
+ // 记录上一次移动的位置值
21
+ moveX: 0,
22
+ // 记录上一次滑动的位置,用于前后两次做对比,如果移动的距离小于某一阈值,则认为前后之间没有移动,为了解决可能存在的通信阻塞问题
23
+ lastX: 0
24
+ }
25
+ },
26
+ computed: {
27
+ // 获取过渡时间
28
+ getDuratin() {
29
+ let duration = String(this.duration)
30
+ // 如果ms为单位,返回ms的数值部分
31
+ if (duration.indexOf('ms') >= 0) return parseInt(duration)
32
+ // 如果s为单位,为了得到ms的数值,需要乘以1000
33
+ if (duration.indexOf('s') >= 0) return parseInt(duration) * 1000
34
+ // 如果值传了数值,且小于30,认为是s单位
35
+ duration = Number(duration)
36
+ return duration < 30 ? duration * 1000 : duration
37
+ }
38
+ },
39
+ watch: {
40
+ show: {
41
+ immediate: true,
42
+ handler(n) {
43
+
44
+ }
45
+ }
46
+ },
47
+ mounted() {
48
+ sleep(20).then(() => {
49
+ this.queryRect()
50
+ })
51
+ },
52
+ methods: {
53
+ close() {
54
+ this.closeSwipeAction()
55
+ },
56
+ // 触摸单元格
57
+ touchstart(event) {
58
+ if (this.disabled) return
59
+ this.closeOther()
60
+ const { touches } = event
61
+ // 记录触摸开始点的坐标值
62
+ this.startX = touches[0].pageX
63
+ this.startY = touches[0].pageY
64
+ },
65
+ // // 触摸滑动
66
+ touchmove(event) {
67
+ if (this.disabled) return
68
+ const { touches } = event
69
+ const { pageX } = touches[0]
70
+ const { pageY } = touches[0]
71
+ let moveX = pageX - this.startX
72
+ const moveY = pageY - this.startY
73
+ const { buttonsWidth } = this
74
+ const len = this.buttons.length
75
+
76
+ // 判断前后两次的移动距离,如果小于一定值,则不进行移动处理
77
+ if (Math.abs(pageX - this.lastX) < 0.3) return
78
+ this.lastX = pageX
79
+
80
+ // 移动的X轴距离大于Y轴距离,也即终点与起点位置连线,与X轴夹角小于45度时,禁止页面滚动
81
+ if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > this.threshold) {
82
+ event.stopPropagation()
83
+ }
84
+ // 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
85
+ if (Math.abs(moveX) < Math.abs(moveY)) return
86
+
87
+ // 限制右滑的距离,不允许内容部分往右偏移,右滑会导致X轴偏移值大于0,以此做判断
88
+ // 此处不能直接return,因为滑动过程中会缺失某些关键点坐标,会导致错乱,最好的办法就是
89
+ // 在超出后,设置为0
90
+ if (this.status === 'open') {
91
+ // 在开启状态下,向左滑动,需忽略
92
+ if (moveX < 0) moveX = 0
93
+ // 想要收起菜单,最大能移动的距离为按钮的总宽度
94
+ if (moveX > buttonsWidth) moveX = buttonsWidth
95
+ // 如果是已经打开了的状态,向左滑动时,移动收起菜单
96
+ this.moveSwipeAction(-buttonsWidth + moveX)
97
+ } else {
98
+ // 关闭状态下,右滑动需忽略
99
+ if (moveX > 0) moveX = 0
100
+ // 滑动的距离不允许超过所有按钮的总宽度,此时只能是左滑,最终设置按钮的总宽度,同时为负数
101
+ if (Math.abs(moveX) > buttonsWidth) moveX = -buttonsWidth
102
+ // 只要是在滑过程中,就不断移动菜单的内容部分,从而使隐藏的菜单显示出来
103
+ this.moveSwipeAction(moveX)
104
+ }
105
+ },
106
+ // 单元格结束触摸
107
+ touchend(event) {
108
+ if (this.disabled) return
109
+ const touches = event.changedTouches ? event.changedTouches[0] : {}
110
+ const { pageX } = touches
111
+ const { pageY } = touches
112
+ const { buttonsWidth } = this
113
+ this.moveX = pageX - this.startX
114
+ if (this.status === 'open') {
115
+ // 在展开的状态下,继续左滑,无需操作
116
+ if (this.moveX < 0) this.moveX = 0
117
+ if (this.moveX > buttonsWidth) this.moveX = buttonsWidth
118
+ // 在开启状态下,点击一下内容区域,moveX为0,也即没有进行移动,这时执行收起菜单逻辑
119
+ if (this.moveX === 0) {
120
+ return this.closeSwipeAction()
121
+ }
122
+ // 在开启状态下,滑动距离小于阈值,则默认为不关闭,同时恢复原来的打开状态
123
+ if (Math.abs(this.moveX) < this.threshold) {
124
+ this.openSwipeAction()
125
+ } else {
126
+ // 如果滑动距离大于阈值,则执行收起逻辑
127
+ this.closeSwipeAction()
128
+ }
129
+ } else {
130
+ // 在关闭的状态下,右滑,无需操作
131
+ if (this.moveX >= 0) this.moveX = 0
132
+ if (this.moveX <= -buttonsWidth) this.moveX = -buttonsWidth
133
+ // 理由同上
134
+ if (Math.abs(this.moveX) < this.threshold) {
135
+ this.closeSwipeAction()
136
+ } else {
137
+ this.openSwipeAction()
138
+ }
139
+ }
140
+ },
141
+ // 移动滑动选择器内容区域,同时显示出其隐藏的菜单
142
+ moveSwipeAction(moveX) {
143
+ if (this.moving) return
144
+ this.moving = true
145
+
146
+ let previewButtonsMoveX = 0
147
+ const len = this.buttons.length
148
+ animation.transition(this.$refs['uv-swipe-action-item__content'].ref, {
149
+ styles: {
150
+ transform: `translateX(${moveX}px)`
151
+ },
152
+ timingFunction: 'linear'
153
+ }, () => {
154
+ this.moving = false
155
+ })
156
+ // 按钮的组的长度
157
+ for (let i = len - 1; i >= 0; i--) {
158
+ const buttonRef = this.$refs[`uv-swipe-action-item__right__button-${i}`][0].ref
159
+ // 通过比例,得出元素自身该移动的距离
160
+ const translateX = this.buttons[i].width / this.buttonsWidth * moveX
161
+ // 最终移动的距离,是通过自身比例算出的距离,再加上在它之前所有按钮移动的距离之和
162
+ const realTranslateX = translateX + previewButtonsMoveX
163
+ animation.transition(buttonRef, {
164
+ styles: {
165
+ transform: `translateX(${realTranslateX}px)`
166
+ },
167
+ duration: 0,
168
+ delay: 0,
169
+ timingFunction: 'linear'
170
+ }, () => {})
171
+ // 记录本按钮之前的所有按钮的移动距离之和
172
+ previewButtonsMoveX += translateX
173
+ }
174
+ },
175
+ // 关闭菜单
176
+ closeSwipeAction() {
177
+ if (this.status === 'close') return
178
+ this.moving = true
179
+ const { buttonsWidth } = this
180
+ animation.transition(this.$refs['uv-swipe-action-item__content'].ref, {
181
+ styles: {
182
+ transform: 'translateX(0px)'
183
+ },
184
+ duration: this.getDuratin,
185
+ timingFunction: 'ease-in-out'
186
+ }, () => {
187
+ this.status = 'close'
188
+ this.moving = false
189
+ this.closeHandler()
190
+ })
191
+ // 按钮的组的长度
192
+ const len = this.buttons.length
193
+ for (let i = len - 1; i >= 0; i--) {
194
+ const buttonRef = this.$refs[`uv-swipe-action-item__right__button-${i}`][0].ref
195
+ // 如果不满足边界条件,返回
196
+ if (this.buttons.length === 0 || !this.buttons[i] || !this.buttons[i].width) return
197
+
198
+ animation.transition(buttonRef, {
199
+ styles: {
200
+ transform: 'translateX(0px)'
201
+ },
202
+ duration: this.getDuratin,
203
+ timingFunction: 'ease-in-out'
204
+ }, () => {})
205
+ }
206
+ },
207
+ // 打开菜单
208
+ openSwipeAction() {
209
+ if (this.status === 'open') return
210
+ this.moving = true
211
+ const buttonsWidth = -this.buttonsWidth
212
+ let previewButtonsMoveX = 0
213
+ animation.transition(this.$refs['uv-swipe-action-item__content'].ref, {
214
+ styles: {
215
+ transform: `translateX(${buttonsWidth}px)`
216
+ },
217
+ duration: this.getDuratin,
218
+ timingFunction: 'ease-in-out'
219
+ }, () => {
220
+ this.status = 'open'
221
+ this.moving = false
222
+ this.openHandler()
223
+ })
224
+ // 按钮的组的长度
225
+ const len = this.buttons.length
226
+ for (let i = len - 1; i >= 0; i--) {
227
+ const buttonRef = this.$refs[`uv-swipe-action-item__right__button-${i}`][0].ref
228
+ // 如果不满足边界条件,返回
229
+ if (this.buttons.length === 0 || !this.buttons[i] || !this.buttons[i].width) return
230
+ // 通过比例,得出元素自身该移动的距离
231
+ const translateX = this.buttons[i].width / this.buttonsWidth * buttonsWidth
232
+ // 最终移动的距离,是通过自身比例算出的距离,再加上在它之前所有按钮移动的距离之和
233
+ const realTranslateX = translateX + previewButtonsMoveX
234
+ animation.transition(buttonRef, {
235
+ styles: {
236
+ transform: `translateX(${realTranslateX}px)`
237
+ },
238
+ duration: this.getDuratin,
239
+ timingFunction: 'ease-in-out'
240
+ }, () => {})
241
+ previewButtonsMoveX += translateX
242
+ }
243
+ },
244
+ // 查询按钮节点信息
245
+ queryRect() {
246
+ // 历遍所有按钮数组,通过getRectByDom返回一个promise
247
+ const promiseAll = this.rightOptions.map((item, index) => this.getRectByDom(this.$refs[`uv-swipe-action-item__right__button-${index}`][0]))
248
+ // 通过promise.all方法,让所有按钮的查询结果返回一个数组的形式
249
+ Promise.all(promiseAll).then((sizes) => {
250
+ this.buttons = sizes
251
+ // 计算所有按钮总宽度
252
+ this.buttonsWidth = sizes.reduce((sum, cur) => sum + cur.width, 0)
253
+ })
254
+ },
255
+ // 通过nvue的dom模块,查询节点信息
256
+ getRectByDom(ref) {
257
+ return new Promise((resolve) => {
258
+ dom.getComponentRect(ref, (res) => {
259
+ resolve(res.size)
260
+ })
261
+ })
262
+ }
263
+ }
264
+ }
@@ -0,0 +1,182 @@
1
+ // nvue操作dom的库,用于获取dom的尺寸信息
2
+ const dom = uni.requireNativePlugin('dom');
3
+ const bindingX = uni.requireNativePlugin('bindingx');
4
+ const animation = uni.requireNativePlugin('animation');
5
+ import { getDuration, getPx } from '../../libs/function/index.js'
6
+ export default {
7
+ data() {
8
+ return {
9
+ // 所有按钮的总宽度
10
+ buttonsWidth: 0,
11
+ // 是否正在移动中
12
+ moving: false
13
+ }
14
+ },
15
+ computed: {
16
+ // 获取过渡时间
17
+ getDuratin() {
18
+ let duration = String(this.duration)
19
+ // 如果ms为单位,返回ms的数值部分
20
+ if (duration.indexOf('ms') >= 0) return parseInt(duration)
21
+ // 如果s为单位,为了得到ms的数值,需要乘以1000
22
+ if (duration.indexOf('s') >= 0) return parseInt(duration) * 1000
23
+ // 如果值传了数值,且小于30,认为是s单位
24
+ duration = Number(duration)
25
+ return duration < 30 ? duration * 1000 : duration
26
+ }
27
+ },
28
+ watch: {
29
+ show(n) {
30
+ if(n) {
31
+ this.moveCellByAnimation('open')
32
+ } else {
33
+ this.moveCellByAnimation('close')
34
+ }
35
+ }
36
+ },
37
+ mounted() {
38
+ setTimeout(()=>{
39
+ this.initialize()
40
+ },20)
41
+ },
42
+ methods: {
43
+ initialize() {
44
+ this.queryRect()
45
+ },
46
+ // 关闭单元格,用于打开一个,自动关闭其他单元格的场景
47
+ closeHandler() {
48
+ if(this.status === 'open') {
49
+ // 如果在打开状态下,进行点击的话,直接关闭单元格
50
+ return this.moveCellByAnimation('close') && this.unbindBindingX()
51
+ }
52
+ },
53
+ // 点击单元格
54
+ clickHandler() {
55
+ // 如果在移动中被点击,进行忽略
56
+ if(this.moving) return
57
+ // 尝试关闭其他打开的单元格
58
+ this.parent && this.parent.closeOther(this)
59
+ if(this.status === 'open') {
60
+ // 如果在打开状态下,进行点击的话,直接关闭单元格
61
+ return this.moveCellByAnimation('close') && this.unbindBindingX()
62
+ }
63
+ },
64
+ // 滑动单元格
65
+ onTouchstart(e) {
66
+ // 如果当前正在移动中,或者disabled状态,则返回
67
+ if(this.moving || this.disabled) {
68
+ return this.unbindBindingX()
69
+ }
70
+ if(this.status === 'open') {
71
+ // 如果在打开状态下,进行点击的话,直接关闭单元格
72
+ return this.moveCellByAnimation('close') && this.unbindBindingX()
73
+ }
74
+ // 特殊情况下,e可能不为一个对象
75
+ e?.stopPropagation && e.stopPropagation()
76
+ e?.preventDefault && e.preventDefault()
77
+ this.moving = true
78
+ // 获取元素ref
79
+ const content = this.getContentRef()
80
+ let expression = `min(max(${-this.buttonsWidth}, x), 0)`
81
+ // 尝试关闭其他打开的单元格
82
+ this.parent && this.parent.closeOther(this)
83
+ // 阿里为了KPI而开源的BindingX
84
+ this.panEvent = bindingX.bind({
85
+ anchor: content,
86
+ eventType: 'pan',
87
+ props: [{
88
+ element: content,
89
+ // 绑定width属性,设置其宽度值
90
+ property: 'transform.translateX',
91
+ expression
92
+ }]
93
+ }, (res) => {
94
+ this.moving = false
95
+ if (res.state === 'end' || res.state === 'exit') {
96
+ const deltaX = res.deltaX
97
+ if(deltaX <= -this.buttonsWidth || deltaX >= 0) {
98
+ // 如果触摸滑动的过程中,大于单元格的总宽度,或者大于0,意味着已经动过滑动达到了打开或者关闭的状态
99
+ // 这里直接进行状态的标记
100
+ this.$nextTick(() => {
101
+ this.status = deltaX <= -this.buttonsWidth ? 'open' : 'close'
102
+ })
103
+ } else if(Math.abs(deltaX) > getPx(this.threshold)) {
104
+ // 在移动大于阈值、并且小于总按钮宽度时,进行自动打开或者关闭
105
+ // 移动距离大于0时,意味着需要关闭状态
106
+ if(Math.abs(deltaX) < this.buttonsWidth) {
107
+ this.moveCellByAnimation(deltaX > 0 ? 'close' : 'open')
108
+ }
109
+ } else {
110
+ // 在小于阈值时,进行关闭操作(如果在打开状态下,将不会执行bindingX)
111
+ this.moveCellByAnimation('close')
112
+ }
113
+ }
114
+ })
115
+ },
116
+ // 释放bindingX
117
+ unbindBindingX() {
118
+ // 释放上一次的资源
119
+ if (this?.panEvent?.token != 0) {
120
+ bindingX.unbind({
121
+ token: this.panEvent?.token,
122
+ // pan为手势事件
123
+ eventType: 'pan'
124
+ })
125
+ }
126
+ },
127
+ // 查询按钮节点信息
128
+ queryRect() {
129
+ // 历遍所有按钮数组,通过getRectByDom返回一个promise
130
+ const promiseAll = this.options.map(async(item, index) => {
131
+ return await this.getRectByDom(this.$refs[`uv-swipe-action-item__right__button-${index}`][0])
132
+ })
133
+ // 通过promise.all方法,让所有按钮的查询结果返回一个数组的形式
134
+ Promise.all(promiseAll).then(sizes => {
135
+ this.buttons = sizes
136
+ // 计算所有按钮总宽度
137
+ this.buttonsWidth = sizes.reduce((sum, cur) => sum + cur.width, 0)
138
+ })
139
+ },
140
+ // 通过nvue的dom模块,查询节点信息
141
+ getRectByDom(ref) {
142
+ return new Promise(resolve => {
143
+ dom.getComponentRect(ref, res => {
144
+ resolve(res.size)
145
+ })
146
+ })
147
+ },
148
+ // 移动单元格到左边或者右边尽头
149
+ moveCellByAnimation(status = 'open') {
150
+ if(this.moving) return
151
+ // 标识当前状态
152
+ this.moveing = true
153
+ const content = this.getContentRef()
154
+ const x = status === 'open' ? -this.buttonsWidth : 0
155
+ animation.transition(content, {
156
+ styles: {
157
+ transform: `translateX(${x}px)`,
158
+ },
159
+ duration: getDuration(this.duration, false),
160
+ timingFunction: 'ease-in-out'
161
+ }, () => {
162
+ this.moving = false
163
+ this.status = status
164
+ this.unbindBindingX()
165
+ })
166
+ },
167
+ // 获取元素ref
168
+ getContentRef() {
169
+ return this.$refs['uv-swipe-action-item__content'].ref
170
+ }
171
+ },
172
+ // #ifdef VUE2
173
+ beforeDestroy() {
174
+ this.unbindBindingX()
175
+ },
176
+ // #endif
177
+ // #ifdef VUE3
178
+ unmounted() {
179
+ this.unbindBindingX()
180
+ }
181
+ // #endif
182
+ }
@@ -0,0 +1,40 @@
1
+ export default {
2
+ props: {
3
+ // 控制打开或者关闭
4
+ show: {
5
+ type: Boolean,
6
+ default: false
7
+ },
8
+ // 标识符,如果是v-for,可用index索引值
9
+ name: {
10
+ type: [String, Number],
11
+ default: ''
12
+ },
13
+ // 是否禁用
14
+ disabled: {
15
+ type: Boolean,
16
+ default: false
17
+ },
18
+ // 是否自动关闭其他swipe按钮组
19
+ autoClose: {
20
+ type: Boolean,
21
+ default: true
22
+ },
23
+ // 滑动距离阈值,只有大于此值,才被认为是要打开菜单
24
+ threshold: {
25
+ type: Number,
26
+ default: 20
27
+ },
28
+ // 右侧按钮内容
29
+ options: {
30
+ type: Array,
31
+ default: () => []
32
+ },
33
+ // 动画过渡时间,单位ms
34
+ duration: {
35
+ type: [String, Number],
36
+ default: 300
37
+ },
38
+ ...uni.$uv?.props?.swipeActionItem
39
+ }
40
+ }
@@ -0,0 +1,200 @@
1
+ <template>
2
+ <view class="uv-swipe-action-item" ref="uv-swipe-action-item">
3
+ <view class="uv-swipe-action-item__right">
4
+ <slot name="button">
5
+ <view v-for="(item,index) in options" :key="index" class="uv-swipe-action-item__right__button"
6
+ :ref="`uv-swipe-action-item__right__button-${index}`" :style="[{
7
+ alignItems: item.style && item.style.borderRadius ? 'center' : 'stretch'
8
+ }]" @tap="buttonClickHandler(item, index)">
9
+ <view class="uv-swipe-action-item__right__button__wrapper" :style="[{
10
+ backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
11
+ borderRadius: item.style && item.style.borderRadius ? item.style.borderRadius : '0',
12
+ padding: item.style && item.style.borderRadius ? '0' : '0 15px',
13
+ }, item.style]">
14
+ <uv-icon v-if="item.icon" :name="item.icon"
15
+ :color="item.style && item.style.color ? item.style.color : '#ffffff'"
16
+ :size="item.iconSize ? $uv.addUnit(item.iconSize) : item.style && item.style.fontSize ? $uv.getPx(item.style.fontSize) * 1.2 : 17"
17
+ :customStyle="{
18
+ marginRight: item.text ? '2px' : 0
19
+ }"></uv-icon>
20
+ <text v-if="item.text" class="uv-swipe-action-item__right__button__wrapper__text uv-line-1"
21
+ :style="[{
22
+ color: item.style && item.style.color ? item.style.color : '#ffffff',
23
+ fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px',
24
+ lineHeight: item.style && item.style.fontSize ? item.style.fontSize : '16px',
25
+ }]">{{ item.text }}</text>
26
+ </view>
27
+ </view>
28
+ </slot>
29
+ </view>
30
+ <!-- #ifndef APP-NVUE -->
31
+ <view class="uv-swipe-action-item__content" @touchstart="wxs.touchstart" @touchmove="wxs.touchmove"
32
+ @touchend="wxs.touchend" :status="status" :change:status="wxs.statusChange" :size="size"
33
+ :change:size="wxs.sizeChange">
34
+ <!-- #endif -->
35
+ <!-- #ifdef APP-NVUE -->
36
+ <view class="uv-swipe-action-item__content" ref="uv-swipe-action-item__content" @panstart="onTouchstart"
37
+ @tap="clickHandler">
38
+ <!-- #endif -->
39
+ <slot />
40
+ </view>
41
+ </view>
42
+ </template>
43
+ <!-- #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ -->
44
+ <script src="./index.wxs" module="wxs" lang="wxs"></script>
45
+ <!-- #endif -->
46
+ <script>
47
+ import touch from '../../libs/mixin/touch.js'
48
+ import mpMixin from '../../libs/mixin/mpMixin.js'
49
+ import mixin from '../../libs/mixin/mixin.js'
50
+ import props from './props.js';
51
+ // #ifdef APP-NVUE
52
+ import nvue from './nvue.js';
53
+ // #endif
54
+ // #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ
55
+ import wxs from './wxs.js';
56
+ // #endif
57
+ /**
58
+ * SwipeActionItem 滑动单元格子组件
59
+ * @description 该组件一般用于左滑唤出操作菜单的场景,用的最多的是左滑删除操作
60
+ * @tutorial https://www.uvui.cn/components/swipeAction.html
61
+ * @property {Boolean} show 控制打开或者关闭(默认 false )
62
+ * @property {String | Number} index 标识符,如果是v-for,可用index索引
63
+ * @property {Boolean} disabled 是否禁用(默认 false )
64
+ * @property {Boolean} autoClose 是否自动关闭其他swipe按钮组(默认 true )
65
+ * @property {Number} threshold 滑动距离阈值,只有大于此值,才被认为是要打开菜单(默认 30 )
66
+ * @property {Array} options 右侧按钮内容
67
+ * @property {String | Number} duration 动画过渡时间,单位ms(默认 350 )
68
+ * @event {Function(index)} open 组件打开时触发
69
+ * @event {Function(index)} close 组件关闭时触发
70
+ * @example <uv-swipe-action><uv-swipe-action-item :options="options1" ></uv-swipe-action-item></uv-swipe-action>
71
+ */
72
+ export default {
73
+ name: 'uv-swipe-action-item',
74
+ emits: ['click'],
75
+ // #ifndef APP-NVUE
76
+ mixins: [mpMixin, mixin, props, touch],
77
+ // #endif
78
+ // #ifdef APP-NVUE
79
+ mixins: [mpMixin, mixin, props, nvue , touch],
80
+ // #endif
81
+ // #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ
82
+ mixins: [mpMixin, mixin, props, touch, wxs],
83
+ // #endif
84
+ data() {
85
+ return {
86
+ // 按钮的尺寸信息
87
+ size: {},
88
+ // 父组件uv-swipe-action的参数
89
+ parentData: {
90
+ autoClose: true,
91
+ },
92
+ // 当前状态,open-打开,close-关闭
93
+ status: 'close',
94
+ }
95
+ },
96
+ watch: {
97
+ // 由于wxs无法直接读取外部的值,需要在外部值变化时,重新执行赋值逻辑
98
+ wxsInit(newValue, oldValue) {
99
+ this.queryRect()
100
+ }
101
+ },
102
+ computed: {
103
+ wxsInit() {
104
+ return [this.disabled, this.autoClose, this.threshold, this.options, this.duration]
105
+ }
106
+ },
107
+ mounted() {
108
+ // #ifdef MP-TOUTIAO
109
+ this.$uv.error('抖音小程序暂不支持wxs,故该组件暂不支持抖音小程序');
110
+ // #endif
111
+ this.init()
112
+ },
113
+ methods: {
114
+ init() {
115
+ // 初始化父组件数据
116
+ this.updateParentData()
117
+ // #ifndef APP-NVUE
118
+ this.$uv.sleep().then(() => {
119
+ this.queryRect()
120
+ })
121
+ // #endif
122
+ },
123
+ updateParentData() {
124
+ // 此方法在mixin中
125
+ this.getParentData('uv-swipe-action')
126
+ },
127
+ // #ifndef APP-NVUE
128
+ // 查询节点
129
+ queryRect() {
130
+ this.$uvGetRect('.uv-swipe-action-item__right__button', true).then(buttons => {
131
+ this.size = {
132
+ buttons,
133
+ show: this.show,
134
+ disabled: this.disabled,
135
+ threshold: this.threshold,
136
+ duration: this.duration
137
+ }
138
+ })
139
+ },
140
+ // #endif
141
+ // 按钮被点击
142
+ buttonClickHandler(item, index) {
143
+ this.$emit('click', {
144
+ index,
145
+ name: this.name
146
+ })
147
+ }
148
+ },
149
+ }
150
+ </script>
151
+
152
+ <style lang="scss" scoped>
153
+ $show-lines: 1;
154
+ @import '../../libs/css/variable.scss';
155
+ @import '../../libs/css/components.scss';
156
+
157
+ .uv-swipe-action-item {
158
+ position: relative;
159
+ overflow: hidden;
160
+ /* #ifndef APP-NVUE || MP-WEIXIN */
161
+ touch-action: pan-y;
162
+ /* #endif */
163
+
164
+ &__content {
165
+ background-color: #FFFFFF;
166
+ z-index: 10;
167
+ }
168
+
169
+ &__right {
170
+ position: absolute;
171
+ top: 0;
172
+ bottom: 0;
173
+ right: 0;
174
+ @include flex;
175
+
176
+ &__button {
177
+ @include flex;
178
+ justify-content: center;
179
+ overflow: hidden;
180
+ align-items: center;
181
+
182
+ &__wrapper {
183
+ @include flex;
184
+ align-items: center;
185
+ justify-content: center;
186
+ padding: 0 15px;
187
+
188
+ &__text {
189
+ @include flex;
190
+ align-items: center;
191
+ color: #FFFFFF;
192
+ font-size: 15px;
193
+ text-align: center;
194
+ justify-content: center;
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ </style>