uview-ui-wjf 1.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/LICENSE +21 -0
- package/README.md +71 -0
- package/changelog.md +388 -0
- package/components/u--form/u--form.vue +92 -0
- package/components/u--image/u--image.vue +73 -0
- package/components/u--input/u--input.vue +115 -0
- package/components/u--text/u--text.vue +72 -0
- package/components/u--textarea/u--textarea.vue +85 -0
- package/components/u-action-sheet/props.js +54 -0
- package/components/u-action-sheet/u-action-sheet.vue +278 -0
- package/components/u-album/props.js +59 -0
- package/components/u-album/u-album.vue +259 -0
- package/components/u-alert/props.js +44 -0
- package/components/u-alert/u-alert.vue +243 -0
- package/components/u-avatar/props.js +78 -0
- package/components/u-avatar/u-avatar.vue +173 -0
- package/components/u-avatar-group/props.js +52 -0
- package/components/u-avatar-group/u-avatar-group.vue +103 -0
- package/components/u-back-top/props.js +54 -0
- package/components/u-back-top/u-back-top.vue +129 -0
- package/components/u-badge/props.js +72 -0
- package/components/u-badge/u-badge.vue +171 -0
- package/components/u-button/nvue.scss +46 -0
- package/components/u-button/props.js +161 -0
- package/components/u-button/u-button.vue +495 -0
- package/components/u-button/vue.scss +80 -0
- package/components/u-calendar/header.vue +99 -0
- package/components/u-calendar/month.vue +579 -0
- package/components/u-calendar/props.js +144 -0
- package/components/u-calendar/u-calendar.vue +384 -0
- package/components/u-calendar/util.js +85 -0
- package/components/u-car-keyboard/props.js +14 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +311 -0
- package/components/u-cell/props.js +110 -0
- package/components/u-cell/u-cell.vue +229 -0
- package/components/u-cell-group/props.js +14 -0
- package/components/u-cell-group/u-cell-group.vue +61 -0
- package/components/u-checkbox/props.js +69 -0
- package/components/u-checkbox/u-checkbox.vue +344 -0
- package/components/u-checkbox-group/props.js +82 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +103 -0
- package/components/u-circle-progress/props.js +8 -0
- package/components/u-circle-progress/u-circle-progress.vue +198 -0
- package/components/u-code/props.js +34 -0
- package/components/u-code/u-code.vue +129 -0
- package/components/u-code-input/props.js +79 -0
- package/components/u-code-input/u-code-input.vue +252 -0
- package/components/u-col/props.js +29 -0
- package/components/u-col/u-col.vue +162 -0
- package/components/u-collapse/props.js +19 -0
- package/components/u-collapse/u-collapse.vue +90 -0
- package/components/u-collapse-item/props.js +59 -0
- package/components/u-collapse-item/u-collapse-item.vue +225 -0
- package/components/u-column-notice/props.js +55 -0
- package/components/u-column-notice/u-column-notice.vue +160 -0
- package/components/u-count-down/props.js +24 -0
- package/components/u-count-down/u-count-down.vue +163 -0
- package/components/u-count-down/utils.js +62 -0
- package/components/u-count-to/props.js +59 -0
- package/components/u-count-to/u-count-to.vue +184 -0
- package/components/u-datetime-picker/props.js +120 -0
- package/components/u-datetime-picker/u-datetime-picker.vue +361 -0
- package/components/u-divider/props.js +44 -0
- package/components/u-divider/u-divider.vue +116 -0
- package/components/u-dropdown/props.js +65 -0
- package/components/u-dropdown/u-dropdown.vue +127 -0
- package/components/u-dropdown-item/props.js +36 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +127 -0
- package/components/u-empty/props.js +59 -0
- package/components/u-empty/u-empty.vue +128 -0
- package/components/u-form/props.js +45 -0
- package/components/u-form/u-form.vue +214 -0
- package/components/u-form-item/props.js +48 -0
- package/components/u-form-item/u-form-item.vue +235 -0
- package/components/u-gap/props.js +24 -0
- package/components/u-gap/u-gap.vue +38 -0
- package/components/u-grid/props.js +19 -0
- package/components/u-grid/u-grid.vue +97 -0
- package/components/u-grid-item/props.js +14 -0
- package/components/u-grid-item/u-grid-item.vue +209 -0
- package/components/u-icon/icons.js +214 -0
- package/components/u-icon/props.js +89 -0
- package/components/u-icon/u-icon.vue +237 -0
- package/components/u-image/props.js +84 -0
- package/components/u-image/u-image.vue +232 -0
- package/components/u-index-anchor/props.js +29 -0
- package/components/u-index-anchor/u-index-anchor.vue +91 -0
- package/components/u-index-item/props.js +5 -0
- package/components/u-index-item/u-index-item.vue +87 -0
- package/components/u-index-list/props.js +29 -0
- package/components/u-index-list/u-index-list.vue +440 -0
- package/components/u-input/props.js +187 -0
- package/components/u-input/u-input.vue +369 -0
- package/components/u-keyboard/props.js +84 -0
- package/components/u-keyboard/u-keyboard.vue +164 -0
- package/components/u-line/props.js +33 -0
- package/components/u-line/u-line.vue +62 -0
- package/components/u-line-progress/props.js +28 -0
- package/components/u-line-progress/u-line-progress.vue +144 -0
- package/components/u-link/props.js +39 -0
- package/components/u-link/u-link.vue +83 -0
- package/components/u-list/props.js +76 -0
- package/components/u-list/u-list.vue +157 -0
- package/components/u-list-item/props.js +9 -0
- package/components/u-list-item/u-list-item.vue +116 -0
- package/components/u-loading-icon/props.js +59 -0
- package/components/u-loading-icon/u-loading-icon.vue +343 -0
- package/components/u-loading-page/props.js +49 -0
- package/components/u-loading-page/u-loading-page.vue +115 -0
- package/components/u-loadmore/props.js +94 -0
- package/components/u-loadmore/u-loadmore.vue +150 -0
- package/components/u-modal/props.js +89 -0
- package/components/u-modal/u-modal.vue +228 -0
- package/components/u-navbar/props.js +84 -0
- package/components/u-navbar/u-navbar.vue +186 -0
- package/components/u-no-network/props.js +19 -0
- package/components/u-no-network/u-no-network.vue +220 -0
- package/components/u-notice-bar/props.js +70 -0
- package/components/u-notice-bar/u-notice-bar.vue +101 -0
- package/components/u-notify/props.js +49 -0
- package/components/u-notify/u-notify.vue +211 -0
- package/components/u-number-box/props.js +109 -0
- package/components/u-number-box/u-number-box.vue +416 -0
- package/components/u-number-keyboard/props.js +19 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +196 -0
- package/components/u-overlay/props.js +24 -0
- package/components/u-overlay/u-overlay.vue +68 -0
- package/components/u-parse/node/node.vue +499 -0
- package/components/u-parse/parser.js +1075 -0
- package/components/u-parse/props.js +45 -0
- package/components/u-parse/u-parse.vue +366 -0
- package/components/u-picker/props.js +79 -0
- package/components/u-picker/u-picker.vue +286 -0
- package/components/u-picker-column/props.js +5 -0
- package/components/u-picker-column/u-picker-column.vue +27 -0
- package/components/u-popup/props.js +79 -0
- package/components/u-popup/u-popup.vue +304 -0
- package/components/u-radio/props.js +64 -0
- package/components/u-radio/u-radio.vue +339 -0
- package/components/u-radio-group/props.js +85 -0
- package/components/u-radio-group/u-radio-group.vue +108 -0
- package/components/u-rate/props.js +69 -0
- package/components/u-rate/u-rate.vue +306 -0
- package/components/u-read-more/props.js +61 -0
- package/components/u-read-more/u-read-more.vue +157 -0
- package/components/u-row/props.js +19 -0
- package/components/u-row/u-row.vue +93 -0
- package/components/u-row-notice/props.js +39 -0
- package/components/u-row-notice/u-row-notice.vue +330 -0
- package/components/u-safe-bottom/props.js +5 -0
- package/components/u-safe-bottom/u-safe-bottom.vue +56 -0
- package/components/u-scroll-list/nvue.js +28 -0
- package/components/u-scroll-list/other.js +0 -0
- package/components/u-scroll-list/props.js +34 -0
- package/components/u-scroll-list/scrollWxs.wxs +50 -0
- package/components/u-scroll-list/u-scroll-list.vue +224 -0
- package/components/u-search/props.js +118 -0
- package/components/u-search/u-search.vue +303 -0
- package/components/u-skeleton/props.js +59 -0
- package/components/u-skeleton/u-skeleton.vue +244 -0
- package/components/u-slider/mpother.js +113 -0
- package/components/u-slider/mpwxs.js +42 -0
- package/components/u-slider/mpwxs.wxs +121 -0
- package/components/u-slider/nvue - /345/211/257/346/234/254.js" +180 -0
- package/components/u-slider/nvue.js +193 -0
- package/components/u-slider/props.js +54 -0
- package/components/u-slider/u-slider.vue +55 -0
- package/components/u-status-bar/props.js +8 -0
- package/components/u-status-bar/u-status-bar.vue +46 -0
- package/components/u-steps/props.js +39 -0
- package/components/u-steps/u-steps.vue +80 -0
- package/components/u-steps-item/props.js +24 -0
- package/components/u-steps-item/u-steps-item.vue +316 -0
- package/components/u-sticky/props.js +40 -0
- package/components/u-sticky/u-sticky.vue +212 -0
- package/components/u-subsection/props.js +49 -0
- package/components/u-subsection/u-subsection.vue +299 -0
- package/components/u-swipe-action/props.js +9 -0
- package/components/u-swipe-action/u-swipe-action.vue +67 -0
- package/components/u-swipe-action-item/index - backup.wxs +256 -0
- package/components/u-swipe-action-item/index.wxs +225 -0
- package/components/u-swipe-action-item/nvue - backup.js +270 -0
- package/components/u-swipe-action-item/nvue.js +174 -0
- package/components/u-swipe-action-item/props.js +41 -0
- package/components/u-swipe-action-item/u-swipe-action-item.vue +190 -0
- package/components/u-swipe-action-item/wxs.js +15 -0
- package/components/u-swiper/props.js +125 -0
- package/components/u-swiper/u-swiper.vue +255 -0
- package/components/u-swiper-indicator/props.js +29 -0
- package/components/u-swiper-indicator/u-swiper-indicator.vue +110 -0
- package/components/u-switch/props.js +54 -0
- package/components/u-switch/u-switch.vue +177 -0
- package/components/u-tabbar/props.js +44 -0
- package/components/u-tabbar/u-tabbar.vue +141 -0
- package/components/u-tabbar-item/props.js +35 -0
- package/components/u-tabbar-item/u-tabbar-item.vue +142 -0
- package/components/u-table/props.js +5 -0
- package/components/u-table/u-table.vue +29 -0
- package/components/u-tabs/props.js +64 -0
- package/components/u-tabs/u-tabs.vue +363 -0
- package/components/u-tabs-item/props.js +5 -0
- package/components/u-tabs-item/u-tabs-item.vue +29 -0
- package/components/u-tag/props.js +84 -0
- package/components/u-tag/u-tag.vue +358 -0
- package/components/u-td/props.js +5 -0
- package/components/u-td/u-td.vue +31 -0
- package/components/u-text/props.js +110 -0
- package/components/u-text/u-text.vue +223 -0
- package/components/u-text/value.js +85 -0
- package/components/u-textarea/props.js +119 -0
- package/components/u-textarea/u-textarea.vue +239 -0
- package/components/u-toast/u-toast.vue +291 -0
- package/components/u-toolbar/props.js +34 -0
- package/components/u-toolbar/u-toolbar.vue +102 -0
- package/components/u-tooltip/clipboard.min.js +58 -0
- package/components/u-tooltip/props.js +59 -0
- package/components/u-tooltip/u-tooltip.vue +366 -0
- package/components/u-tr/props.js +5 -0
- package/components/u-tr/u-tr.vue +31 -0
- package/components/u-transition/nvue.ani-map.js +68 -0
- package/components/u-transition/props.js +24 -0
- package/components/u-transition/transition.js +157 -0
- package/components/u-transition/u-transition.vue +92 -0
- package/components/u-transition/vue.ani-style.scss +113 -0
- package/components/u-upload/mixin.js +21 -0
- package/components/u-upload/props.js +124 -0
- package/components/u-upload/u-upload.vue +566 -0
- package/components/u-upload/utils.js +151 -0
- package/components/uview-ui/uview-ui.vue +15 -0
- package/index.js +79 -0
- package/index.scss +23 -0
- package/libs/config/color.js +17 -0
- package/libs/config/config.js +34 -0
- package/libs/config/props/actionSheet.js +25 -0
- package/libs/config/props/album.js +25 -0
- package/libs/config/props/alert.js +22 -0
- package/libs/config/props/avatar.js +28 -0
- package/libs/config/props/avatarGroup.js +23 -0
- package/libs/config/props/backtop.js +27 -0
- package/libs/config/props/badge.js +27 -0
- package/libs/config/props/button.js +42 -0
- package/libs/config/props/calendar.js +42 -0
- package/libs/config/props/carKeyboard.js +15 -0
- package/libs/config/props/cell.js +35 -0
- package/libs/config/props/cellGroup.js +17 -0
- package/libs/config/props/checkbox.js +27 -0
- package/libs/config/props/checkboxGroup.js +29 -0
- package/libs/config/props/circleProgress.js +15 -0
- package/libs/config/props/code.js +21 -0
- package/libs/config/props/codeInput.js +29 -0
- package/libs/config/props/col.js +19 -0
- package/libs/config/props/collapse.js +17 -0
- package/libs/config/props/collapseItem.js +25 -0
- package/libs/config/props/columnNotice.js +24 -0
- package/libs/config/props/countDown.js +18 -0
- package/libs/config/props/countTo.js +25 -0
- package/libs/config/props/datetimePicker.js +37 -0
- package/libs/config/props/divider.js +23 -0
- package/libs/config/props/empty.js +26 -0
- package/libs/config/props/form.js +22 -0
- package/libs/config/props/formItem.js +23 -0
- package/libs/config/props/gap.js +19 -0
- package/libs/config/props/grid.js +17 -0
- package/libs/config/props/gridItem.js +16 -0
- package/libs/config/props/icon.js +36 -0
- package/libs/config/props/image.js +30 -0
- package/libs/config/props/indexAnchor.js +19 -0
- package/libs/config/props/indexList.js +19 -0
- package/libs/config/props/input.js +48 -0
- package/libs/config/props/keyboard.js +30 -0
- package/libs/config/props/line.js +20 -0
- package/libs/config/props/lineProgress.js +19 -0
- package/libs/config/props/link.js +26 -0
- package/libs/config/props/list.js +28 -0
- package/libs/config/props/listItem.js +15 -0
- package/libs/config/props/loadingIcon.js +30 -0
- package/libs/config/props/loadingPage.js +23 -0
- package/libs/config/props/loadmore.js +32 -0
- package/libs/config/props/modal.js +31 -0
- package/libs/config/props/navbar.js +32 -0
- package/libs/config/props/noNetwork.js +18 -0
- package/libs/config/props/noticeBar.js +27 -0
- package/libs/config/props/notify.js +22 -0
- package/libs/config/props/numberBox.js +35 -0
- package/libs/config/props/numberKeyboard.js +17 -0
- package/libs/config/props/overlay.js +18 -0
- package/libs/config/props/parse.js +22 -0
- package/libs/config/props/picker.js +29 -0
- package/libs/config/props/popup.js +29 -0
- package/libs/config/props/radio.js +27 -0
- package/libs/config/props/radioGroup.js +30 -0
- package/libs/config/props/rate.js +26 -0
- package/libs/config/props/readMore.js +22 -0
- package/libs/config/props/row.js +17 -0
- package/libs/config/props/rowNotice.js +21 -0
- package/libs/config/props/scrollList.js +20 -0
- package/libs/config/props/search.js +37 -0
- package/libs/config/props/section.js +24 -0
- package/libs/config/props/skeleton.js +25 -0
- package/libs/config/props/slider.js +25 -0
- package/libs/config/props/statusBar.js +15 -0
- package/libs/config/props/steps.js +21 -0
- package/libs/config/props/stepsItem.js +18 -0
- package/libs/config/props/sticky.js +20 -0
- package/libs/config/props/subsection.js +23 -0
- package/libs/config/props/swipeAction.js +15 -0
- package/libs/config/props/swipeActionItem.js +21 -0
- package/libs/config/props/swiper.js +39 -0
- package/libs/config/props/swipterIndicator.js +19 -0
- package/libs/config/props/switch.js +24 -0
- package/libs/config/props/tabbar.js +22 -0
- package/libs/config/props/tabbarItem.js +20 -0
- package/libs/config/props/tabs.js +32 -0
- package/libs/config/props/tag.js +29 -0
- package/libs/config/props/text.js +38 -0
- package/libs/config/props/textarea.js +36 -0
- package/libs/config/props/toast.js +30 -0
- package/libs/config/props/toolbar.js +21 -0
- package/libs/config/props/tooltip.js +25 -0
- package/libs/config/props/transition.js +18 -0
- package/libs/config/props/upload.js +36 -0
- package/libs/config/props.js +190 -0
- package/libs/config/zIndex.js +20 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +97 -0
- package/libs/css/components.scss +15 -0
- package/libs/css/flex.scss +257 -0
- package/libs/css/h5.scss +0 -0
- package/libs/css/mixin.scss +8 -0
- package/libs/css/mp.scss +0 -0
- package/libs/css/nvue.scss +0 -0
- package/libs/css/vue.scss +27 -0
- package/libs/function/colorGradient.js +134 -0
- package/libs/function/debounce.js +29 -0
- package/libs/function/digit.js +167 -0
- package/libs/function/index.js +731 -0
- package/libs/function/platform.js +75 -0
- package/libs/function/test.js +288 -0
- package/libs/function/throttle.js +30 -0
- package/libs/luch-request/adapters/index.js +97 -0
- package/libs/luch-request/core/InterceptorManager.js +50 -0
- package/libs/luch-request/core/Request.js +198 -0
- package/libs/luch-request/core/buildFullPath.js +20 -0
- package/libs/luch-request/core/defaults.js +29 -0
- package/libs/luch-request/core/dispatchRequest.js +3 -0
- package/libs/luch-request/core/mergeConfig.js +103 -0
- package/libs/luch-request/core/settle.js +16 -0
- package/libs/luch-request/helpers/buildURL.js +69 -0
- package/libs/luch-request/helpers/combineURLs.js +14 -0
- package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/libs/luch-request/index.d.ts +116 -0
- package/libs/luch-request/index.js +3 -0
- package/libs/luch-request/utils/clone.js +264 -0
- package/libs/luch-request/utils.js +131 -0
- package/libs/mixin/button.js +13 -0
- package/libs/mixin/mixin.js +160 -0
- package/libs/mixin/mpMixin.js +8 -0
- package/libs/mixin/mpShare.js +13 -0
- package/libs/mixin/openType.js +25 -0
- package/libs/mixin/style.js +228 -0
- package/libs/mixin/touch.js +59 -0
- package/libs/util/async-validator.js +1343 -0
- package/libs/util/calendar.js +546 -0
- package/libs/util/dayjs.js +308 -0
- package/libs/util/emitter.js +51 -0
- package/libs/util/route.js +124 -0
- package/package.json +83 -0
- package/theme.scss +44 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 此为wxs模块,只支持APP-VUE,微信和QQ小程序以及H5平台
|
|
3
|
+
* wxs内部不支持es6语法,变量只能使用var定义,无法使用解构,箭头函数等特性
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// 开始触摸
|
|
7
|
+
function touchstart(event, ownerInstance) {
|
|
8
|
+
// 触发事件的组件的ComponentDescriptor实例
|
|
9
|
+
var instance = event.instance
|
|
10
|
+
// wxs内的局部变量快照,此快照是属于整个组件的,在touchstart和touchmove事件中都能获取到相同的结果
|
|
11
|
+
var state = instance.getState()
|
|
12
|
+
if (state.disabled) return
|
|
13
|
+
var touches = event.touches
|
|
14
|
+
// 如果进行的是多指触控,不允许进行操作
|
|
15
|
+
if (touches && touches.length > 1) return
|
|
16
|
+
// 标识当前为滑动中状态
|
|
17
|
+
state.moving = true
|
|
18
|
+
// 记录触摸开始点的坐标值
|
|
19
|
+
state.startX = touches[0].pageX
|
|
20
|
+
state.startY = touches[0].pageY
|
|
21
|
+
|
|
22
|
+
ownerInstance.callMethod('closeOther')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 触摸滑动
|
|
26
|
+
function touchmove(event, ownerInstance) {
|
|
27
|
+
// 触发事件的组件的ComponentDescriptor实例
|
|
28
|
+
var instance = event.instance
|
|
29
|
+
// wxs内的局部变量快照
|
|
30
|
+
var state = instance.getState()
|
|
31
|
+
if (state.disabled || !state.moving) return
|
|
32
|
+
var touches = event.touches
|
|
33
|
+
var pageX = touches[0].pageX
|
|
34
|
+
var pageY = touches[0].pageY
|
|
35
|
+
var moveX = pageX - state.startX
|
|
36
|
+
var moveY = pageY - state.startY
|
|
37
|
+
var buttonsWidth = state.buttonsWidth
|
|
38
|
+
|
|
39
|
+
// 移动的X轴距离大于Y轴距离,也即终点与起点位置连线,与X轴夹角小于45度时,禁止页面滚动
|
|
40
|
+
if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > state.threshold) {
|
|
41
|
+
event.preventDefault && event.preventDefault()
|
|
42
|
+
event.stopPropagation && event.stopPropagation()
|
|
43
|
+
}
|
|
44
|
+
// 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
|
|
45
|
+
if (Math.abs(moveX) < Math.abs(moveY)) return
|
|
46
|
+
|
|
47
|
+
// 限制右滑的距离,不允许内容部分往右偏移,右滑会导致X轴偏移值大于0,以此做判断
|
|
48
|
+
// 此处不能直接return,因为滑动过程中会缺失某些关键点坐标,会导致错乱,最好的办法就是
|
|
49
|
+
// 在超出后,设置为0
|
|
50
|
+
if (state.status === 'open') {
|
|
51
|
+
// 在开启状态下,向左滑动,需忽略
|
|
52
|
+
if (moveX < 0) moveX = 0
|
|
53
|
+
// 想要收起菜单,最大能移动的距离为按钮的总宽度
|
|
54
|
+
if (moveX > buttonsWidth) moveX = buttonsWidth
|
|
55
|
+
// 如果是已经打开了的状态,向左滑动时,移动收起菜单
|
|
56
|
+
moveSwipeAction(-buttonsWidth + moveX, instance, ownerInstance)
|
|
57
|
+
} else {
|
|
58
|
+
// 关闭状态下,右滑动需忽略
|
|
59
|
+
if (moveX > 0) moveX = 0
|
|
60
|
+
// 滑动的距离不允许超过所有按钮的总宽度,此时只能是左滑,最终设置按钮的总宽度,同时为负数
|
|
61
|
+
if (Math.abs(moveX) > buttonsWidth) moveX = -buttonsWidth
|
|
62
|
+
// 只要是在滑过程中,就不断移动单元格内容部分,从而使隐藏的菜单显示出来
|
|
63
|
+
moveSwipeAction(moveX, instance, ownerInstance)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 触摸结束
|
|
68
|
+
function touchend(event, ownerInstance) {
|
|
69
|
+
// 触发事件的组件的ComponentDescriptor实例
|
|
70
|
+
var instance = event.instance
|
|
71
|
+
// wxs内的局部变量快照
|
|
72
|
+
var state = instance.getState()
|
|
73
|
+
if (!state.moving || state.disabled) return
|
|
74
|
+
var touches = event.changedTouches ? event.changedTouches[0] : {}
|
|
75
|
+
var pageX = touches.pageX
|
|
76
|
+
var pageY = touches.pageY
|
|
77
|
+
var moveX = pageX - state.startX
|
|
78
|
+
if (state.status === 'open') {
|
|
79
|
+
// 在展开的状态下,继续左滑,无需操作
|
|
80
|
+
if (moveX < 0) return
|
|
81
|
+
// 在开启状态下,点击一下内容区域,moveX为0,也即没有进行移动,这时执行收起菜单逻辑
|
|
82
|
+
if (moveX === 0) {
|
|
83
|
+
return closeSwipeAction(instance, ownerInstance)
|
|
84
|
+
}
|
|
85
|
+
// 在开启状态下,滑动距离小于阈值,则默认为不关闭,同时恢复原来的打开状态
|
|
86
|
+
if (Math.abs(moveX) < state.threshold) {
|
|
87
|
+
openSwipeAction(instance, ownerInstance)
|
|
88
|
+
} else {
|
|
89
|
+
// 如果滑动距离大于阈值,则执行收起逻辑
|
|
90
|
+
closeSwipeAction(instance, ownerInstance)
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
// 在关闭的状态下,右滑,无需操作
|
|
94
|
+
if (moveX > 0) return
|
|
95
|
+
// 理由同上
|
|
96
|
+
if (Math.abs(moveX) < state.threshold) {
|
|
97
|
+
closeSwipeAction(instance, ownerInstance)
|
|
98
|
+
} else {
|
|
99
|
+
openSwipeAction(instance, ownerInstance)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 获取过渡时间
|
|
105
|
+
function getDuration(value) {
|
|
106
|
+
if (value.toString().indexOf('s') >= 0) return value
|
|
107
|
+
return value > 30 ? value + 'ms' : value + 's'
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 滑动结束时判断滑动的方向
|
|
111
|
+
function getMoveDirection(instance, ownerInstance) {
|
|
112
|
+
var state = instance.getState()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 移动滑动选择器内容区域,同时显示出其隐藏的菜单
|
|
116
|
+
function moveSwipeAction(moveX, instance, ownerInstance) {
|
|
117
|
+
var state = instance.getState()
|
|
118
|
+
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
119
|
+
var buttons = ownerInstance.selectAllComponents('.u-swipe-action-item__right__button')
|
|
120
|
+
|
|
121
|
+
// 设置菜单内容部分的偏移
|
|
122
|
+
instance.requestAnimationFrame(function() {
|
|
123
|
+
instance.setStyle({
|
|
124
|
+
// 设置translateX的值
|
|
125
|
+
'transition': 'none',
|
|
126
|
+
transform: 'translateX(' + moveX + 'px)',
|
|
127
|
+
'-webkit-transform': 'translateX(' + moveX + 'px)'
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 一次性展开滑动菜单
|
|
133
|
+
function openSwipeAction(instance, ownerInstance) {
|
|
134
|
+
var state = instance.getState()
|
|
135
|
+
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
136
|
+
var buttons = ownerInstance.selectAllComponents('.u-swipe-action-item__right__button')
|
|
137
|
+
// 处理duration单位问题
|
|
138
|
+
var duration = getDuration(state.duration)
|
|
139
|
+
// 展开过程中,是向左移动,所以X的偏移应该为负值
|
|
140
|
+
var buttonsWidth = -state.buttonsWidth
|
|
141
|
+
instance.requestAnimationFrame(function() {
|
|
142
|
+
// 设置菜单主体内容
|
|
143
|
+
instance.setStyle({
|
|
144
|
+
'transition': 'transform ' + duration,
|
|
145
|
+
'transform': 'translateX(' + buttonsWidth + 'px)',
|
|
146
|
+
'-webkit-transform': 'translateX(' + buttonsWidth + 'px)',
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
setStatus('open', instance, ownerInstance)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 标记菜单的当前状态,open-已经打开,close-已经关闭
|
|
153
|
+
function setStatus(status, instance, ownerInstance) {
|
|
154
|
+
var state = instance.getState()
|
|
155
|
+
state.status = status
|
|
156
|
+
ownerInstance.callMethod('setState', status)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 一次性收起滑动菜单
|
|
160
|
+
function closeSwipeAction(instance, ownerInstance) {
|
|
161
|
+
var state = instance.getState()
|
|
162
|
+
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
163
|
+
var buttons = ownerInstance.selectAllComponents('.u-swipe-action-item__right__button')
|
|
164
|
+
var len = buttons.length
|
|
165
|
+
// 处理duration单位问题
|
|
166
|
+
var duration = getDuration(state.duration)
|
|
167
|
+
instance.requestAnimationFrame(function() {
|
|
168
|
+
// 设置菜单主体内容
|
|
169
|
+
instance.setStyle({
|
|
170
|
+
'transition': 'transform ' + duration,
|
|
171
|
+
'transform': 'translateX(0px)',
|
|
172
|
+
'-webkit-transform': 'translateX(0px)'
|
|
173
|
+
})
|
|
174
|
+
// 设置各个隐藏的按钮为收起的状态
|
|
175
|
+
for (var i = len - 1; i >= 0; i--) {
|
|
176
|
+
buttons[i].setStyle({
|
|
177
|
+
'transition': 'transform ' + duration,
|
|
178
|
+
'transform': 'translateX(0px)',
|
|
179
|
+
'-webkit-transform': 'translateX(0px)'
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
setStatus('close', instance, ownerInstance)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// status的状态发生变化
|
|
187
|
+
function statusChange(newValue, oldValue, ownerInstance, instance) {
|
|
188
|
+
var state = instance.getState()
|
|
189
|
+
if (state.disabled) return
|
|
190
|
+
// 打开或关闭单元格
|
|
191
|
+
if (newValue === 'close' && state.status === 'open') {
|
|
192
|
+
closeSwipeAction(instance, ownerInstance)
|
|
193
|
+
} else if(newValue === 'open' && state.status === 'close') {
|
|
194
|
+
openSwipeAction(instance, ownerInstance)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 菜单尺寸发生变化
|
|
199
|
+
function sizeChange(newValue, oldValue, ownerInstance, instance) {
|
|
200
|
+
// wxs内的局部变量快照
|
|
201
|
+
var state = instance.getState()
|
|
202
|
+
state.disabled = newValue.disabled
|
|
203
|
+
state.duration = newValue.duration
|
|
204
|
+
state.show = newValue.show
|
|
205
|
+
state.threshold = newValue.threshold
|
|
206
|
+
state.buttons = newValue.buttons
|
|
207
|
+
|
|
208
|
+
if (state.buttons) {
|
|
209
|
+
var len = state.buttons.length
|
|
210
|
+
var buttonsWidth = 0
|
|
211
|
+
var buttons = newValue.buttons
|
|
212
|
+
for (var i = 0; i < len; i++) {
|
|
213
|
+
buttonsWidth += buttons[i].width
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
state.buttonsWidth = buttonsWidth
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
module.exports = {
|
|
220
|
+
touchstart: touchstart,
|
|
221
|
+
touchmove: touchmove,
|
|
222
|
+
touchend: touchend,
|
|
223
|
+
sizeChange: sizeChange,
|
|
224
|
+
statusChange: statusChange
|
|
225
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// nvue操作dom的库,用于获取dom的尺寸信息
|
|
2
|
+
const dom = uni.requireNativePlugin('dom')
|
|
3
|
+
// nvue中用于操作元素动画的库,类似于uni.animation,只不过uni.animation不能用于nvue
|
|
4
|
+
const animation = uni.requireNativePlugin('animation')
|
|
5
|
+
|
|
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
|
+
// if(n === true) {
|
|
44
|
+
// uni.$u.sleep(50).then(() => {
|
|
45
|
+
// this.openSwipeAction()
|
|
46
|
+
// })
|
|
47
|
+
// } else {
|
|
48
|
+
// this.closeSwipeAction()
|
|
49
|
+
// }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
mounted() {
|
|
54
|
+
uni.$u.sleep(20).then(() => {
|
|
55
|
+
this.queryRect()
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
methods: {
|
|
59
|
+
close() {
|
|
60
|
+
this.closeSwipeAction()
|
|
61
|
+
},
|
|
62
|
+
// 触摸单元格
|
|
63
|
+
touchstart(event) {
|
|
64
|
+
if (this.disabled) return
|
|
65
|
+
this.closeOther()
|
|
66
|
+
const { touches } = event
|
|
67
|
+
// 记录触摸开始点的坐标值
|
|
68
|
+
this.startX = touches[0].pageX
|
|
69
|
+
this.startY = touches[0].pageY
|
|
70
|
+
},
|
|
71
|
+
// // 触摸滑动
|
|
72
|
+
touchmove(event) {
|
|
73
|
+
if (this.disabled) return
|
|
74
|
+
const { touches } = event
|
|
75
|
+
const { pageX } = touches[0]
|
|
76
|
+
const { pageY } = touches[0]
|
|
77
|
+
let moveX = pageX - this.startX
|
|
78
|
+
const moveY = pageY - this.startY
|
|
79
|
+
const { buttonsWidth } = this
|
|
80
|
+
const len = this.buttons.length
|
|
81
|
+
|
|
82
|
+
// 判断前后两次的移动距离,如果小于一定值,则不进行移动处理
|
|
83
|
+
if (Math.abs(pageX - this.lastX) < 0.3) return
|
|
84
|
+
this.lastX = pageX
|
|
85
|
+
|
|
86
|
+
// 移动的X轴距离大于Y轴距离,也即终点与起点位置连线,与X轴夹角小于45度时,禁止页面滚动
|
|
87
|
+
if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > this.threshold) {
|
|
88
|
+
event.stopPropagation()
|
|
89
|
+
}
|
|
90
|
+
// 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
|
|
91
|
+
if (Math.abs(moveX) < Math.abs(moveY)) return
|
|
92
|
+
|
|
93
|
+
// 限制右滑的距离,不允许内容部分往右偏移,右滑会导致X轴偏移值大于0,以此做判断
|
|
94
|
+
// 此处不能直接return,因为滑动过程中会缺失某些关键点坐标,会导致错乱,最好的办法就是
|
|
95
|
+
// 在超出后,设置为0
|
|
96
|
+
if (this.status === 'open') {
|
|
97
|
+
// 在开启状态下,向左滑动,需忽略
|
|
98
|
+
if (moveX < 0) moveX = 0
|
|
99
|
+
// 想要收起菜单,最大能移动的距离为按钮的总宽度
|
|
100
|
+
if (moveX > buttonsWidth) moveX = buttonsWidth
|
|
101
|
+
// 如果是已经打开了的状态,向左滑动时,移动收起菜单
|
|
102
|
+
this.moveSwipeAction(-buttonsWidth + moveX)
|
|
103
|
+
} else {
|
|
104
|
+
// 关闭状态下,右滑动需忽略
|
|
105
|
+
if (moveX > 0) moveX = 0
|
|
106
|
+
// 滑动的距离不允许超过所有按钮的总宽度,此时只能是左滑,最终设置按钮的总宽度,同时为负数
|
|
107
|
+
if (Math.abs(moveX) > buttonsWidth) moveX = -buttonsWidth
|
|
108
|
+
// 只要是在滑过程中,就不断移动菜单的内容部分,从而使隐藏的菜单显示出来
|
|
109
|
+
this.moveSwipeAction(moveX)
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
// 单元格结束触摸
|
|
113
|
+
touchend(event) {
|
|
114
|
+
if (this.disabled) return
|
|
115
|
+
const touches = event.changedTouches ? event.changedTouches[0] : {}
|
|
116
|
+
const { pageX } = touches
|
|
117
|
+
const { pageY } = touches
|
|
118
|
+
const { buttonsWidth } = this
|
|
119
|
+
this.moveX = pageX - this.startX
|
|
120
|
+
if (this.status === 'open') {
|
|
121
|
+
// 在展开的状态下,继续左滑,无需操作
|
|
122
|
+
if (this.moveX < 0) this.moveX = 0
|
|
123
|
+
if (this.moveX > buttonsWidth) this.moveX = buttonsWidth
|
|
124
|
+
// 在开启状态下,点击一下内容区域,moveX为0,也即没有进行移动,这时执行收起菜单逻辑
|
|
125
|
+
if (this.moveX === 0) {
|
|
126
|
+
return this.closeSwipeAction()
|
|
127
|
+
}
|
|
128
|
+
// 在开启状态下,滑动距离小于阈值,则默认为不关闭,同时恢复原来的打开状态
|
|
129
|
+
if (Math.abs(this.moveX) < this.threshold) {
|
|
130
|
+
this.openSwipeAction()
|
|
131
|
+
} else {
|
|
132
|
+
// 如果滑动距离大于阈值,则执行收起逻辑
|
|
133
|
+
this.closeSwipeAction()
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
// 在关闭的状态下,右滑,无需操作
|
|
137
|
+
if (this.moveX >= 0) this.moveX = 0
|
|
138
|
+
if (this.moveX <= -buttonsWidth) this.moveX = -buttonsWidth
|
|
139
|
+
// 理由同上
|
|
140
|
+
if (Math.abs(this.moveX) < this.threshold) {
|
|
141
|
+
this.closeSwipeAction()
|
|
142
|
+
} else {
|
|
143
|
+
this.openSwipeAction()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
// 移动滑动选择器内容区域,同时显示出其隐藏的菜单
|
|
148
|
+
moveSwipeAction(moveX) {
|
|
149
|
+
if (this.moving) return
|
|
150
|
+
this.moving = true
|
|
151
|
+
|
|
152
|
+
let previewButtonsMoveX = 0
|
|
153
|
+
const len = this.buttons.length
|
|
154
|
+
animation.transition(this.$refs['u-swipe-action-item__content'].ref, {
|
|
155
|
+
styles: {
|
|
156
|
+
transform: `translateX(${moveX}px)`
|
|
157
|
+
},
|
|
158
|
+
timingFunction: 'linear'
|
|
159
|
+
}, () => {
|
|
160
|
+
this.moving = false
|
|
161
|
+
})
|
|
162
|
+
// 按钮的组的长度
|
|
163
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
164
|
+
const buttonRef = this.$refs[`u-swipe-action-item__right__button-${i}`][0].ref
|
|
165
|
+
// 通过比例,得出元素自身该移动的距离
|
|
166
|
+
const translateX = this.buttons[i].width / this.buttonsWidth * moveX
|
|
167
|
+
// 最终移动的距离,是通过自身比例算出的距离,再加上在它之前所有按钮移动的距离之和
|
|
168
|
+
const realTranslateX = translateX + previewButtonsMoveX
|
|
169
|
+
animation.transition(buttonRef, {
|
|
170
|
+
styles: {
|
|
171
|
+
transform: `translateX(${realTranslateX}px)`
|
|
172
|
+
},
|
|
173
|
+
duration: 0,
|
|
174
|
+
delay: 0,
|
|
175
|
+
timingFunction: 'linear'
|
|
176
|
+
}, () => {})
|
|
177
|
+
// 记录本按钮之前的所有按钮的移动距离之和
|
|
178
|
+
previewButtonsMoveX += translateX
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
// 关闭菜单
|
|
182
|
+
closeSwipeAction() {
|
|
183
|
+
if (this.status === 'close') return
|
|
184
|
+
this.moving = true
|
|
185
|
+
const { buttonsWidth } = this
|
|
186
|
+
animation.transition(this.$refs['u-swipe-action-item__content'].ref, {
|
|
187
|
+
styles: {
|
|
188
|
+
transform: 'translateX(0px)'
|
|
189
|
+
},
|
|
190
|
+
duration: this.getDuratin,
|
|
191
|
+
timingFunction: 'ease-in-out'
|
|
192
|
+
}, () => {
|
|
193
|
+
this.status = 'close'
|
|
194
|
+
this.moving = false
|
|
195
|
+
this.closeHandler()
|
|
196
|
+
})
|
|
197
|
+
// 按钮的组的长度
|
|
198
|
+
const len = this.buttons.length
|
|
199
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
200
|
+
const buttonRef = this.$refs[`u-swipe-action-item__right__button-${i}`][0].ref
|
|
201
|
+
// 如果不满足边界条件,返回
|
|
202
|
+
if (this.buttons.length === 0 || !this.buttons[i] || !this.buttons[i].width) return
|
|
203
|
+
|
|
204
|
+
animation.transition(buttonRef, {
|
|
205
|
+
styles: {
|
|
206
|
+
transform: 'translateX(0px)'
|
|
207
|
+
},
|
|
208
|
+
duration: this.getDuratin,
|
|
209
|
+
timingFunction: 'ease-in-out'
|
|
210
|
+
}, () => {})
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
// 打开菜单
|
|
214
|
+
openSwipeAction() {
|
|
215
|
+
if (this.status === 'open') return
|
|
216
|
+
this.moving = true
|
|
217
|
+
const buttonsWidth = -this.buttonsWidth
|
|
218
|
+
let previewButtonsMoveX = 0
|
|
219
|
+
animation.transition(this.$refs['u-swipe-action-item__content'].ref, {
|
|
220
|
+
styles: {
|
|
221
|
+
transform: `translateX(${buttonsWidth}px)`
|
|
222
|
+
},
|
|
223
|
+
duration: this.getDuratin,
|
|
224
|
+
timingFunction: 'ease-in-out'
|
|
225
|
+
}, () => {
|
|
226
|
+
this.status = 'open'
|
|
227
|
+
this.moving = false
|
|
228
|
+
this.openHandler()
|
|
229
|
+
})
|
|
230
|
+
// 按钮的组的长度
|
|
231
|
+
const len = this.buttons.length
|
|
232
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
233
|
+
const buttonRef = this.$refs[`u-swipe-action-item__right__button-${i}`][0].ref
|
|
234
|
+
// 如果不满足边界条件,返回
|
|
235
|
+
if (this.buttons.length === 0 || !this.buttons[i] || !this.buttons[i].width) return
|
|
236
|
+
// 通过比例,得出元素自身该移动的距离
|
|
237
|
+
const translateX = this.buttons[i].width / this.buttonsWidth * buttonsWidth
|
|
238
|
+
// 最终移动的距离,是通过自身比例算出的距离,再加上在它之前所有按钮移动的距离之和
|
|
239
|
+
const realTranslateX = translateX + previewButtonsMoveX
|
|
240
|
+
animation.transition(buttonRef, {
|
|
241
|
+
styles: {
|
|
242
|
+
transform: `translateX(${realTranslateX}px)`
|
|
243
|
+
},
|
|
244
|
+
duration: this.getDuratin,
|
|
245
|
+
timingFunction: 'ease-in-out'
|
|
246
|
+
}, () => {})
|
|
247
|
+
previewButtonsMoveX += translateX
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
// 查询按钮节点信息
|
|
251
|
+
queryRect() {
|
|
252
|
+
// 历遍所有按钮数组,通过getRectByDom返回一个promise
|
|
253
|
+
const promiseAll = this.rightOptions.map((item, index) => this.getRectByDom(this.$refs[`u-swipe-action-item__right__button-${index}`][0]))
|
|
254
|
+
// 通过promise.all方法,让所有按钮的查询结果返回一个数组的形式
|
|
255
|
+
Promise.all(promiseAll).then((sizes) => {
|
|
256
|
+
this.buttons = sizes
|
|
257
|
+
// 计算所有按钮总宽度
|
|
258
|
+
this.buttonsWidth = sizes.reduce((sum, cur) => sum + cur.width, 0)
|
|
259
|
+
})
|
|
260
|
+
},
|
|
261
|
+
// 通过nvue的dom模块,查询节点信息
|
|
262
|
+
getRectByDom(ref) {
|
|
263
|
+
return new Promise((resolve) => {
|
|
264
|
+
dom.getComponentRect(ref, (res) => {
|
|
265
|
+
resolve(res.size)
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// nvue操作dom的库,用于获取dom的尺寸信息
|
|
2
|
+
const dom = uni.requireNativePlugin('dom');
|
|
3
|
+
const bindingX = uni.requireNativePlugin('bindingx');
|
|
4
|
+
const animation = uni.requireNativePlugin('animation');
|
|
5
|
+
|
|
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
|
+
this.initialize()
|
|
39
|
+
},
|
|
40
|
+
methods: {
|
|
41
|
+
initialize() {
|
|
42
|
+
this.queryRect()
|
|
43
|
+
},
|
|
44
|
+
// 关闭单元格,用于打开一个,自动关闭其他单元格的场景
|
|
45
|
+
closeHandler() {
|
|
46
|
+
if(this.status === 'open') {
|
|
47
|
+
// 如果在打开状态下,进行点击的话,直接关闭单元格
|
|
48
|
+
return this.moveCellByAnimation('close') && this.unbindBindingX()
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
// 点击单元格
|
|
52
|
+
clickHandler() {
|
|
53
|
+
// 如果在移动中被点击,进行忽略
|
|
54
|
+
if(this.moving) return
|
|
55
|
+
// 尝试关闭其他打开的单元格
|
|
56
|
+
this.parent && this.parent.closeOther(this)
|
|
57
|
+
if(this.status === 'open') {
|
|
58
|
+
// 如果在打开状态下,进行点击的话,直接关闭单元格
|
|
59
|
+
return this.moveCellByAnimation('close') && this.unbindBindingX()
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// 滑动单元格
|
|
63
|
+
onTouchstart(e) {
|
|
64
|
+
// 如果当前正在移动中,或者disabled状态,则返回
|
|
65
|
+
if(this.moving || this.disabled) {
|
|
66
|
+
return this.unbindBindingX()
|
|
67
|
+
}
|
|
68
|
+
if(this.status === 'open') {
|
|
69
|
+
// 如果在打开状态下,进行点击的话,直接关闭单元格
|
|
70
|
+
return this.moveCellByAnimation('close') && this.unbindBindingX()
|
|
71
|
+
}
|
|
72
|
+
// 特殊情况下,e可能不为一个对象
|
|
73
|
+
e?.stopPropagation && e.stopPropagation()
|
|
74
|
+
e?.preventDefault && e.preventDefault()
|
|
75
|
+
this.moving = true
|
|
76
|
+
// 获取元素ref
|
|
77
|
+
const content = this.getContentRef()
|
|
78
|
+
let expression = `min(max(${-this.buttonsWidth}, x), 0)`
|
|
79
|
+
// 尝试关闭其他打开的单元格
|
|
80
|
+
this.parent && this.parent.closeOther(this)
|
|
81
|
+
|
|
82
|
+
// 阿里为了KPI而开源的BindingX
|
|
83
|
+
this.panEvent = bindingX.bind({
|
|
84
|
+
anchor: content,
|
|
85
|
+
eventType: 'pan',
|
|
86
|
+
props: [{
|
|
87
|
+
element: content,
|
|
88
|
+
// 绑定width属性,设置其宽度值
|
|
89
|
+
property: 'transform.translateX',
|
|
90
|
+
expression
|
|
91
|
+
}]
|
|
92
|
+
}, (res) => {
|
|
93
|
+
this.moving = false
|
|
94
|
+
if (res.state === 'end' || res.state === 'exit') {
|
|
95
|
+
const deltaX = res.deltaX
|
|
96
|
+
if(deltaX <= -this.buttonsWidth || deltaX >= 0) {
|
|
97
|
+
// 如果触摸滑动的过程中,大于单元格的总宽度,或者大于0,意味着已经动过滑动达到了打开或者关闭的状态
|
|
98
|
+
// 这里直接进行状态的标记
|
|
99
|
+
this.$nextTick(() => {
|
|
100
|
+
this.status = deltaX <= -this.buttonsWidth ? 'open' : 'close'
|
|
101
|
+
})
|
|
102
|
+
} else if(Math.abs(deltaX) > uni.$u.getPx(this.threshold)) {
|
|
103
|
+
// 在移动大于阈值、并且小于总按钮宽度时,进行自动打开或者关闭
|
|
104
|
+
// 移动距离大于0时,意味着需要关闭状态
|
|
105
|
+
if(Math.abs(deltaX) < this.buttonsWidth) {
|
|
106
|
+
this.moveCellByAnimation(deltaX > 0 ? 'close' : 'open')
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
// 在小于阈值时,进行关闭操作(如果在打开状态下,将不会执行bindingX)
|
|
110
|
+
this.moveCellByAnimation('close')
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
},
|
|
115
|
+
// 释放bindingX
|
|
116
|
+
unbindBindingX() {
|
|
117
|
+
// 释放上一次的资源
|
|
118
|
+
if (this?.panEvent?.token != 0) {
|
|
119
|
+
bindingX.unbind({
|
|
120
|
+
token: this.panEvent?.token,
|
|
121
|
+
// pan为手势事件
|
|
122
|
+
eventType: 'pan'
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
// 查询按钮节点信息
|
|
127
|
+
queryRect() {
|
|
128
|
+
// 历遍所有按钮数组,通过getRectByDom返回一个promise
|
|
129
|
+
const promiseAll = this.options.map((item, index) => {
|
|
130
|
+
return this.getRectByDom(this.$refs[`u-swipe-action-item__right__button-${index}`][0])
|
|
131
|
+
})
|
|
132
|
+
// 通过promise.all方法,让所有按钮的查询结果返回一个数组的形式
|
|
133
|
+
Promise.all(promiseAll).then(sizes => {
|
|
134
|
+
this.buttons = sizes
|
|
135
|
+
// 计算所有按钮总宽度
|
|
136
|
+
this.buttonsWidth = sizes.reduce((sum, cur) => sum + cur.width, 0)
|
|
137
|
+
})
|
|
138
|
+
},
|
|
139
|
+
// 通过nvue的dom模块,查询节点信息
|
|
140
|
+
getRectByDom(ref) {
|
|
141
|
+
return new Promise(resolve => {
|
|
142
|
+
dom.getComponentRect(ref, res => {
|
|
143
|
+
resolve(res.size)
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
},
|
|
147
|
+
// 移动单元格到左边或者右边尽头
|
|
148
|
+
moveCellByAnimation(status = 'open') {
|
|
149
|
+
if(this.moving) return
|
|
150
|
+
// 标识当前状态
|
|
151
|
+
this.moveing = true
|
|
152
|
+
const content = this.getContentRef()
|
|
153
|
+
const x = status === 'open' ? -this.buttonsWidth : 0
|
|
154
|
+
animation.transition(content, {
|
|
155
|
+
styles: {
|
|
156
|
+
transform: `translateX(${x}px)`,
|
|
157
|
+
},
|
|
158
|
+
duration: uni.$u.getDuration(this.duration, false),
|
|
159
|
+
timingFunction: 'ease-in-out'
|
|
160
|
+
}, () => {
|
|
161
|
+
this.moving = false
|
|
162
|
+
this.status = status
|
|
163
|
+
this.unbindBindingX()
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
// 获取元素ref
|
|
167
|
+
getContentRef() {
|
|
168
|
+
return this.$refs['u-swipe-action-item__content'].ref
|
|
169
|
+
},
|
|
170
|
+
beforeDestroy() {
|
|
171
|
+
this.unbindBindingX()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|