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,244 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-skeleton">
|
|
3
|
+
<view
|
|
4
|
+
class="u-skeleton__wrapper"
|
|
5
|
+
ref="u-skeleton__wrapper"
|
|
6
|
+
v-if="loading"
|
|
7
|
+
style="display: flex; flex-direction: row;"
|
|
8
|
+
>
|
|
9
|
+
<view
|
|
10
|
+
class="u-skeleton__wrapper__avatar"
|
|
11
|
+
v-if="avatar"
|
|
12
|
+
:class="[`u-skeleton__wrapper__avatar--${avatarShape}`, animate && 'animate']"
|
|
13
|
+
:style="{
|
|
14
|
+
height: $u.addUnit(avatarSize),
|
|
15
|
+
width: $u.addUnit(avatarSize)
|
|
16
|
+
}"
|
|
17
|
+
></view>
|
|
18
|
+
<view
|
|
19
|
+
class="u-skeleton__wrapper__content"
|
|
20
|
+
ref="u-skeleton__wrapper__content"
|
|
21
|
+
style="flex: 1;"
|
|
22
|
+
>
|
|
23
|
+
<view
|
|
24
|
+
class="u-skeleton__wrapper__content__title"
|
|
25
|
+
v-if="title"
|
|
26
|
+
:style="{
|
|
27
|
+
width: uTitleWidth,
|
|
28
|
+
height: $u.addUnit(titleHeight),
|
|
29
|
+
}"
|
|
30
|
+
:class="[animate && 'animate']"
|
|
31
|
+
></view>
|
|
32
|
+
<view
|
|
33
|
+
class="u-skeleton__wrapper__content__rows"
|
|
34
|
+
:class="[animate && 'animate']"
|
|
35
|
+
v-for="(item, index) in rowsArray"
|
|
36
|
+
:key="index"
|
|
37
|
+
:style="{
|
|
38
|
+
width: item.width,
|
|
39
|
+
height: item.height,
|
|
40
|
+
marginTop: item.marginTop
|
|
41
|
+
}"
|
|
42
|
+
>
|
|
43
|
+
|
|
44
|
+
</view>
|
|
45
|
+
</view>
|
|
46
|
+
</view>
|
|
47
|
+
<slot v-else />
|
|
48
|
+
</view>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<script>
|
|
52
|
+
import props from './props.js';
|
|
53
|
+
// #ifdef APP-NVUE
|
|
54
|
+
// 由于weex为阿里的KPI业绩考核的产物,所以不支持百分比单位,这里需要通过dom查询组件的宽度
|
|
55
|
+
const dom = uni.requireNativePlugin('dom')
|
|
56
|
+
const animation = uni.requireNativePlugin('animation')
|
|
57
|
+
// #endif
|
|
58
|
+
/**
|
|
59
|
+
* Skeleton 骨架屏
|
|
60
|
+
* @description 骨架屏一般用于页面在请求远程数据尚未完成时,页面用灰色块预显示本来的页面结构,给用户更好的体验。
|
|
61
|
+
* @tutorial https://www.uviewui.com/components/skeleton.html
|
|
62
|
+
* @property {Boolean} loading 是否显示骨架占位图,设置为false将会展示子组件内容 (默认 true )
|
|
63
|
+
* @property {Boolean} animate 是否开启动画效果 (默认 true )
|
|
64
|
+
* @property {String | Number} rows 段落占位图行数 (默认 0 )
|
|
65
|
+
* @property {String | Number | Array} rowsWidth 段落占位图的宽度,可以为百分比,数值,带单位字符串等,可通过数组传入指定每个段落行的宽度 (默认 '100%' )
|
|
66
|
+
* @property {String | Number | Array} rowsHeight 段落的高度 (默认 18 )
|
|
67
|
+
* @property {Boolean} title 是否展示标题占位图 (默认 true )
|
|
68
|
+
* @property {String | Number} titleWidth 标题的宽度 (默认 '50%' )
|
|
69
|
+
* @property {String | Number} titleHeight 标题的高度 (默认 18 )
|
|
70
|
+
* @property {Boolean} avatar 是否展示头像占位图 (默认 false )
|
|
71
|
+
* @property {String | Number} avatarSize 头像占位图大小 (默认 32 )
|
|
72
|
+
* @property {String} avatarShape 头像占位图的形状,circle-圆形,square-方形 (默认 'circle' )
|
|
73
|
+
* @example <u-search placeholder="日照香炉生紫烟" v-model="keyword"></u-search>
|
|
74
|
+
*/
|
|
75
|
+
export default {
|
|
76
|
+
name: 'u-skeleton',
|
|
77
|
+
mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
|
|
78
|
+
data() {
|
|
79
|
+
return {
|
|
80
|
+
width: 0,
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
watch: {
|
|
84
|
+
loading() {
|
|
85
|
+
this.getComponentWidth()
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
computed: {
|
|
89
|
+
rowsArray() {
|
|
90
|
+
if (/%$/.test(this.rowsHeight)) {
|
|
91
|
+
uni.$u.error('rowsHeight参数不支持百分比单位')
|
|
92
|
+
}
|
|
93
|
+
const rows = []
|
|
94
|
+
for (let i = 0; i < this.rows; i++) {
|
|
95
|
+
let item = {},
|
|
96
|
+
// 需要预防超出数组边界的情况
|
|
97
|
+
rowWidth = uni.$u.test.array(this.rowsWidth) ? (this.rowsWidth[i] || (i === this.row - 1 ? '70%' : '100%')) : i ===
|
|
98
|
+
this.rows - 1 ? '70%' : this.rowsWidth,
|
|
99
|
+
rowHeight = uni.$u.test.array(this.rowsHeight) ? (this.rowsHeight[i] || '18px') : this.rowsHeight
|
|
100
|
+
// 如果有title占位图,第一个段落占位图的外边距需要大一些,如果没有title占位图,第一个段落占位图则无需外边距
|
|
101
|
+
// 之所以需要这么做,是因为weex的无能,以提升性能为借口不支持css的一些伪类
|
|
102
|
+
item.marginTop = !this.title && i === 0 ? 0 : this.title && i === 0 ? '20px' : '12px'
|
|
103
|
+
// 如果设置的为百分比的宽度,转换为px值,因为nvue不支持百分比单位
|
|
104
|
+
if (/%$/.test(rowWidth)) {
|
|
105
|
+
// 通过parseInt提取出百分比单位中的数值部分,除以100得到百分比的小数值
|
|
106
|
+
item.width = uni.$u.addUnit(this.width * parseInt(rowWidth) / 100)
|
|
107
|
+
} else {
|
|
108
|
+
item.width = uni.$u.addUnit(rowWidth)
|
|
109
|
+
}
|
|
110
|
+
item.height = uni.$u.addUnit(rowHeight)
|
|
111
|
+
rows.push(item)
|
|
112
|
+
}
|
|
113
|
+
// console.log(rows);
|
|
114
|
+
return rows
|
|
115
|
+
},
|
|
116
|
+
uTitleWidth() {
|
|
117
|
+
let tWidth = 0
|
|
118
|
+
if (/%$/.test(this.titleWidth)) {
|
|
119
|
+
// 通过parseInt提取出百分比单位中的数值部分,除以100得到百分比的小数值
|
|
120
|
+
tWidth = uni.$u.addUnit(this.width * parseInt(this.titleWidth) / 100)
|
|
121
|
+
} else {
|
|
122
|
+
tWidth = uni.$u.addUnit(this.titleWidth)
|
|
123
|
+
}
|
|
124
|
+
return uni.$u.addUnit(tWidth)
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
},
|
|
128
|
+
mounted() {
|
|
129
|
+
this.init()
|
|
130
|
+
},
|
|
131
|
+
methods: {
|
|
132
|
+
init() {
|
|
133
|
+
this.getComponentWidth()
|
|
134
|
+
// #ifdef APP-NVUE
|
|
135
|
+
this.loading && this.animate && this.setNvueAnimation()
|
|
136
|
+
// #endif
|
|
137
|
+
},
|
|
138
|
+
async setNvueAnimation() {
|
|
139
|
+
// #ifdef APP-NVUE
|
|
140
|
+
// 为了让opacity:1的状态保持一定时间,这里做一个延时
|
|
141
|
+
await uni.$u.sleep(500)
|
|
142
|
+
const skeleton = this.$refs['u-skeleton__wrapper'];
|
|
143
|
+
skeleton && this.loading && this.animate && animation.transition(skeleton, {
|
|
144
|
+
styles: {
|
|
145
|
+
opacity: 0.5
|
|
146
|
+
},
|
|
147
|
+
duration: 600,
|
|
148
|
+
}, () => {
|
|
149
|
+
// 这里无需判断是否loading和开启动画状态,因为最终的状态必须达到opacity: 1,否则可能
|
|
150
|
+
// 会停留在opacity: 0.5的状态中
|
|
151
|
+
animation.transition(skeleton, {
|
|
152
|
+
styles: {
|
|
153
|
+
opacity: 1
|
|
154
|
+
},
|
|
155
|
+
duration: 600,
|
|
156
|
+
}, () => {
|
|
157
|
+
// 只有在loading中时,才执行动画
|
|
158
|
+
this.loading && this.animate && this.setNvueAnimation()
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
// #endif
|
|
162
|
+
},
|
|
163
|
+
// 获取组件的宽度
|
|
164
|
+
async getComponentWidth() {
|
|
165
|
+
// 延时一定时间,以获取dom尺寸
|
|
166
|
+
await uni.$u.sleep(20)
|
|
167
|
+
// #ifndef APP-NVUE
|
|
168
|
+
this.$uGetRect('.u-skeleton__wrapper__content').then(size => {
|
|
169
|
+
this.width = size.width
|
|
170
|
+
})
|
|
171
|
+
// #endif
|
|
172
|
+
|
|
173
|
+
// #ifdef APP-NVUE
|
|
174
|
+
const ref = this.$refs['u-skeleton__wrapper__content']
|
|
175
|
+
ref && dom.getComponentRect(ref, (res) => {
|
|
176
|
+
this.width = res.size.width
|
|
177
|
+
})
|
|
178
|
+
// #endif
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<style lang="scss" scoped>
|
|
185
|
+
@import "../../libs/css/components.scss";
|
|
186
|
+
|
|
187
|
+
@mixin background {
|
|
188
|
+
/* #ifdef APP-NVUE */
|
|
189
|
+
background-color: #F1F2F4;
|
|
190
|
+
/* #endif */
|
|
191
|
+
/* #ifndef APP-NVUE */
|
|
192
|
+
background: linear-gradient(90deg, #F1F2F4 25%, #e6e6e6 37%, #F1F2F4 50%);
|
|
193
|
+
background-size: 400% 100%;
|
|
194
|
+
/* #endif */
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.u-skeleton {
|
|
198
|
+
flex: 1;
|
|
199
|
+
|
|
200
|
+
&__wrapper {
|
|
201
|
+
@include flex(row);
|
|
202
|
+
|
|
203
|
+
&__avatar {
|
|
204
|
+
@include background;
|
|
205
|
+
margin-right: 15px;
|
|
206
|
+
|
|
207
|
+
&--circle {
|
|
208
|
+
border-radius: 100px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
&--square {
|
|
212
|
+
border-radius: 4px;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
&__content {
|
|
217
|
+
flex: 1;
|
|
218
|
+
|
|
219
|
+
&__rows,
|
|
220
|
+
&__title {
|
|
221
|
+
@include background;
|
|
222
|
+
border-radius: 3px;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* #ifndef APP-NVUE */
|
|
229
|
+
.animate {
|
|
230
|
+
animation: skeleton 1.8s ease infinite
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@keyframes skeleton {
|
|
234
|
+
0% {
|
|
235
|
+
background-position: 100% 50%
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
100% {
|
|
239
|
+
background-position: 0 50%
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* #endif */
|
|
244
|
+
</style>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 使用普通的js方案实现slider
|
|
3
|
+
*/
|
|
4
|
+
export default {
|
|
5
|
+
watch: {
|
|
6
|
+
value(n) {
|
|
7
|
+
// 只有在非滑动状态时,才可以通过value更新滑块值,这里监听,是为了让用户触发
|
|
8
|
+
if (this.status === 'end') {
|
|
9
|
+
this.updateSliderPlacement(n, true)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
mounted() {
|
|
14
|
+
this.init()
|
|
15
|
+
},
|
|
16
|
+
methods: {
|
|
17
|
+
init() {
|
|
18
|
+
this.getSliderRect()
|
|
19
|
+
},
|
|
20
|
+
// 获取slider尺寸
|
|
21
|
+
getSliderRect() {
|
|
22
|
+
// 获取滑块条的尺寸信息
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
this.$uGetRect('.u-slider').then((rect) => {
|
|
25
|
+
this.sliderRect = rect
|
|
26
|
+
this.updateSliderPlacement(this.value, true)
|
|
27
|
+
})
|
|
28
|
+
}, 10)
|
|
29
|
+
},
|
|
30
|
+
// 是否可以操作
|
|
31
|
+
canNotDo() {
|
|
32
|
+
return this.disabled
|
|
33
|
+
},
|
|
34
|
+
// 获取当前手势点的X轴位移值
|
|
35
|
+
getTouchX(e) {
|
|
36
|
+
return e.touches[0].clientX
|
|
37
|
+
},
|
|
38
|
+
formatStep(value) {
|
|
39
|
+
// 移动点占总长度的百分比
|
|
40
|
+
return Math.round(Math.max(this.min, Math.min(value, this.max)) / this.step) * this.step
|
|
41
|
+
},
|
|
42
|
+
// 发出事件
|
|
43
|
+
emitEvent(event, value) {
|
|
44
|
+
this.$emit(event, value || this.value)
|
|
45
|
+
},
|
|
46
|
+
// 标记当前手势的状态
|
|
47
|
+
setTouchStatus(status) {
|
|
48
|
+
this.status = status
|
|
49
|
+
},
|
|
50
|
+
onTouchStart(e) {
|
|
51
|
+
if (this.canNotDo()) {
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
// 标示当前的状态为开始触摸滑动
|
|
55
|
+
this.emitEvent('start')
|
|
56
|
+
this.setTouchStatus('start')
|
|
57
|
+
},
|
|
58
|
+
onTouchMove(e) {
|
|
59
|
+
if (this.canNotDo()) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
// 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值
|
|
63
|
+
const x = this.getTouchX(e)
|
|
64
|
+
const { left, width } = this.sliderRect
|
|
65
|
+
const distanceX = x - left
|
|
66
|
+
// 获得移动距离对整个滑块的百分比值,此为带有多位小数的值,不能用此更新视图
|
|
67
|
+
// 否则造成通信阻塞,需要每改变一个step值时修改一次视图
|
|
68
|
+
const percent = (distanceX / width) * 100
|
|
69
|
+
this.setTouchStatus('moving')
|
|
70
|
+
this.updateSliderPlacement(percent, true, 'moving')
|
|
71
|
+
},
|
|
72
|
+
onTouchEnd() {
|
|
73
|
+
if (this.canNotDo()) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
this.emitEvent('end')
|
|
77
|
+
this.setTouchStatus('end')
|
|
78
|
+
},
|
|
79
|
+
// 设置滑点的位置
|
|
80
|
+
updateSliderPlacement(value, drag, event) {
|
|
81
|
+
// 去掉小数部分,同时也是对step步进的处理
|
|
82
|
+
const { width } = this.sliderRect
|
|
83
|
+
const percent = this.formatStep(value)
|
|
84
|
+
// 设置移动的值
|
|
85
|
+
const barStyle = {
|
|
86
|
+
width: `${percent / 100 * width}px`
|
|
87
|
+
}
|
|
88
|
+
// 移动期间无需过渡动画
|
|
89
|
+
if (drag === true) {
|
|
90
|
+
barStyle.transition = 'none'
|
|
91
|
+
} else {
|
|
92
|
+
// 非移动期间,删掉对过渡为空的声明,让css中的声明起效
|
|
93
|
+
delete barStyle.transition
|
|
94
|
+
}
|
|
95
|
+
// 修改value值
|
|
96
|
+
this.$emit('input', percent)
|
|
97
|
+
// 事件的名称
|
|
98
|
+
if (event) {
|
|
99
|
+
this.emitEvent(event, percent)
|
|
100
|
+
}
|
|
101
|
+
this.barStyle = barStyle
|
|
102
|
+
},
|
|
103
|
+
onClick(e) {
|
|
104
|
+
if (this.canNotDo()) {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
// 直接点击滑块的情况,计算方式与onTouchMove方法相同
|
|
108
|
+
const { left, width } = this.sliderRect
|
|
109
|
+
const value = ((e.detail.x - left) / width) * 100
|
|
110
|
+
this.updateSliderPlacement(value, false, 'click')
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
data() {
|
|
3
|
+
return {
|
|
4
|
+
sliderRect: {},
|
|
5
|
+
info: {
|
|
6
|
+
width: null,
|
|
7
|
+
left: null,
|
|
8
|
+
step: this.step,
|
|
9
|
+
disabled: this.disabled,
|
|
10
|
+
min: this.min,
|
|
11
|
+
max: this.max,
|
|
12
|
+
value: this.value
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
mounted() {
|
|
17
|
+
this.init()
|
|
18
|
+
},
|
|
19
|
+
methods: {
|
|
20
|
+
init() {
|
|
21
|
+
this.getSliderRect()
|
|
22
|
+
},
|
|
23
|
+
// 获取slider尺寸
|
|
24
|
+
getSliderRect() {
|
|
25
|
+
// 获取滑块条的尺寸信息
|
|
26
|
+
uni.$u.sleep().then(() => {
|
|
27
|
+
this.$uGetRect('.u-slider').then((rect) => {
|
|
28
|
+
this.info.width = rect.width
|
|
29
|
+
this.info.left = rect.left
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
// 此方法由wxs调用,用于修改v-model绑定的值
|
|
34
|
+
updateValue(value) {
|
|
35
|
+
this.$emit('input', value)
|
|
36
|
+
},
|
|
37
|
+
// 此方法由wxs调用,发出事件
|
|
38
|
+
emitEvent(e) {
|
|
39
|
+
this.$emit(e.event, e.value ? e.value : this.value)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 使用wxs方案实现slider
|
|
3
|
+
* 兼容微信,QQ,H5,Vue版的安卓和iOS
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 开始滑动操作
|
|
7
|
+
* @param {Object} e
|
|
8
|
+
* @param {Object} ownerInstance
|
|
9
|
+
*/
|
|
10
|
+
function onTouchMove(e, ownerInstance) {
|
|
11
|
+
// wxs事件对象下有一个instance属性,表示当前触发此事件的组件的实例,通过该实例,可以获取相关的dataset,设置样式等信息
|
|
12
|
+
// https://developers.weixin.qq.com/miniprogram/dev/framework/view/interactive-animation.html
|
|
13
|
+
var instance = e.instance;
|
|
14
|
+
// getState()为一个对象,挂载在instance上,类似组件的data一样,可以存放一些变量,供以后的触发事件中使用
|
|
15
|
+
var state = instance.getState()
|
|
16
|
+
|
|
17
|
+
// 滑块组件的整体尺寸信息
|
|
18
|
+
var mp = state.mp
|
|
19
|
+
if(mp.disabled) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var distanceX = getTouchX(e) - mp.left
|
|
24
|
+
// 获得移动距离对整个滑块的百分比值,此为带有多位小数的值,step大于1时,不能用此更新视图
|
|
25
|
+
var percent = (distanceX / mp.width) * 100
|
|
26
|
+
|
|
27
|
+
updateSliderPlacement(instance, ownerInstance, percent, 'moving')
|
|
28
|
+
|
|
29
|
+
// 阻止页面滚动,可以保证在滑动过程中,不让页面可以上下滚动,造成不好的体验
|
|
30
|
+
e.stopPropagation && e.stopPropagation()
|
|
31
|
+
e.preventDefault && e.preventDefault()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function onClick(e, ownerInstance) {
|
|
35
|
+
var instance = e.instance
|
|
36
|
+
var state = instance.getState()
|
|
37
|
+
var mp = state.mp
|
|
38
|
+
if(mp.disabled) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 直接点击滑块的情况,计算方式与onTouchMove方法相同
|
|
43
|
+
var value = ((e.detail.x - mp.left) / mp.width) * 100
|
|
44
|
+
updateSliderPlacement(instance, ownerInstance, value, 'click')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function sizeReady(newValue, oldValue, ownerInstance, instance) {
|
|
48
|
+
// 页面初始化时候,也会触发此方法,传递的值为空,这里不执行往后的逻辑
|
|
49
|
+
if(!newValue || newValue.disabled) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
var state = instance.getState()
|
|
53
|
+
state.mp = newValue
|
|
54
|
+
updateSliderPlacement(instance, ownerInstance, newValue.value)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 设置滑点的位置
|
|
58
|
+
function updateSliderPlacement(instance, ownerInstance, value, event) {
|
|
59
|
+
var state = instance.getState()
|
|
60
|
+
var mp = state.mp
|
|
61
|
+
if(mp.disabled) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var percent = 0
|
|
66
|
+
if (mp.step > 1) {
|
|
67
|
+
// 如果step步进大于1,需要跳步,所以需要使用Math.round进行取整
|
|
68
|
+
percent = Math.round(Math.max(mp.min, Math.min(value, mp.max)) / mp.step) * mp.step
|
|
69
|
+
} else {
|
|
70
|
+
// 当step=1时,无需跳步,充分利用wxs性能,滑块实时跟随手势,达到丝滑的效果
|
|
71
|
+
percent = Math.max(mp.min, Math.min(value, mp.max))
|
|
72
|
+
}
|
|
73
|
+
// 返回组件的实例
|
|
74
|
+
var gapInstance = ownerInstance.selectComponent('.u-slider__gap')
|
|
75
|
+
// 在移动期间,不允许transition动画,否则会造成卡顿
|
|
76
|
+
gapInstance[event === 'click' ? 'addClass' : 'removeClass']('u-slider__gap--ani')
|
|
77
|
+
// 调用逻辑层的方法,修改v-model绑定的值
|
|
78
|
+
ownerInstance.callMethod('updateValue', Math.round(percent))
|
|
79
|
+
if(event) {
|
|
80
|
+
ownerInstance.callMethod('emitEvent', {
|
|
81
|
+
event: event,
|
|
82
|
+
value: Math.round(percent)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 设置移动的值
|
|
87
|
+
gapInstance.requestAnimationFrame(function() {
|
|
88
|
+
gapInstance.setStyle({
|
|
89
|
+
width: percent / 100 * mp.width + 'px',
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 开始滑动
|
|
95
|
+
function onTouchStart(e, ownerInstance) {
|
|
96
|
+
ownerInstance.callMethod('emitEvent', {
|
|
97
|
+
event: 'start',
|
|
98
|
+
value: null
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 停止滑动
|
|
103
|
+
function onTouchEnd(e, ownerInstance) {
|
|
104
|
+
ownerInstance.callMethod('emitEvent', {
|
|
105
|
+
event: 'end',
|
|
106
|
+
value: null
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 获取当前手势点的X轴位移值
|
|
111
|
+
function getTouchX(e) {
|
|
112
|
+
return e.touches[0].clientX
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
onTouchStart: onTouchStart,
|
|
117
|
+
onTouchMove: onTouchMove,
|
|
118
|
+
onTouchEnd: onTouchEnd,
|
|
119
|
+
sizeReady: sizeReady,
|
|
120
|
+
onClick: onClick
|
|
121
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 使用bindingx方案实现slider
|
|
3
|
+
* 只能使用于nvue下
|
|
4
|
+
*/
|
|
5
|
+
// 引入bindingx,此库类似于微信小程序wxs,目的是让js运行在视图层,减少视图层和逻辑层的通信折损
|
|
6
|
+
const BindingX = uni.requireNativePlugin('bindingx')
|
|
7
|
+
// nvue操作dom的库,用于获取dom的尺寸信息
|
|
8
|
+
const dom = uni.requireNativePlugin('dom')
|
|
9
|
+
// nvue中用于操作元素动画的库,类似于uni.animation,只不过uni.animation不能用于nvue
|
|
10
|
+
const animation = uni.requireNativePlugin('animation')
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
data() {
|
|
14
|
+
return {
|
|
15
|
+
// bindingx的回调值,用于取消绑定
|
|
16
|
+
panEvent: null,
|
|
17
|
+
// 标记是否移动状态
|
|
18
|
+
moving: false,
|
|
19
|
+
// 位移的偏移量
|
|
20
|
+
x: 0,
|
|
21
|
+
// 是否正在触摸过程中,用于标记动画类是否添加或移除
|
|
22
|
+
touching: false,
|
|
23
|
+
changeFromInside: false
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
watch: {
|
|
27
|
+
// 监听vlaue的变化,此变化可能是由于内部修改v-model的值,或者外部
|
|
28
|
+
// 从服务端获取一个值后,赋值给slider的v-model而导致的
|
|
29
|
+
value(n) {
|
|
30
|
+
if (!this.changeFromInside) {
|
|
31
|
+
this.initX()
|
|
32
|
+
} else {
|
|
33
|
+
this.changeFromInside = false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
mounted() {
|
|
38
|
+
this.init()
|
|
39
|
+
},
|
|
40
|
+
methods: {
|
|
41
|
+
init() {
|
|
42
|
+
this.getSliderRect()
|
|
43
|
+
},
|
|
44
|
+
// 获取节点信息
|
|
45
|
+
// 获取slider尺寸
|
|
46
|
+
getSliderRect() {
|
|
47
|
+
// 获取滑块条的尺寸信息
|
|
48
|
+
// 通过nvue的dom模块,查询节点信息
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
dom.getComponentRect(this.$refs['slider'], res => {
|
|
51
|
+
this.sliderRect = res.size
|
|
52
|
+
this.initX()
|
|
53
|
+
})
|
|
54
|
+
}, 10)
|
|
55
|
+
},
|
|
56
|
+
// 初始化按钮位置
|
|
57
|
+
initButtonStyle({
|
|
58
|
+
barStyle,
|
|
59
|
+
buttonWrapperStyle
|
|
60
|
+
}) {
|
|
61
|
+
this.barStyle = barStyle
|
|
62
|
+
this.buttonWrapperStyle = buttonWrapperStyle
|
|
63
|
+
},
|
|
64
|
+
emitEvent(event, value) {
|
|
65
|
+
this.$emit(event, value ? value : this.value)
|
|
66
|
+
},
|
|
67
|
+
formatStep(value) {
|
|
68
|
+
// 移动点占总长度的百分比
|
|
69
|
+
return Math.round(Math.max(this.min, Math.min(value, this.max)) / this.step) * this.step
|
|
70
|
+
},
|
|
71
|
+
// 滑动开始
|
|
72
|
+
onTouchStart(e) {
|
|
73
|
+
// 阻止页面滚动,可以保证在滑动过程中,不让页面可以上下滚动,造成不好的体验
|
|
74
|
+
e.stopPropagation && e.stopPropagation()
|
|
75
|
+
e.preventDefault && e.preventDefault()
|
|
76
|
+
if (this.moving || this.disabled) {
|
|
77
|
+
// 释放上一次的资源
|
|
78
|
+
if (this.panEvent?.token != 0) {
|
|
79
|
+
BindingX.unbind({
|
|
80
|
+
token: this.panEvent.token,
|
|
81
|
+
// pan为手势事件
|
|
82
|
+
eventType: 'pan'
|
|
83
|
+
})
|
|
84
|
+
this.gesToken = 0
|
|
85
|
+
}
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.moving = true
|
|
90
|
+
this.touching = true
|
|
91
|
+
|
|
92
|
+
// 获取元素ref
|
|
93
|
+
const button = this.$refs['nvue-button'].ref
|
|
94
|
+
const gap = this.$refs['nvue-gap'].ref
|
|
95
|
+
|
|
96
|
+
const {
|
|
97
|
+
min,
|
|
98
|
+
max,
|
|
99
|
+
step
|
|
100
|
+
} = this
|
|
101
|
+
const {
|
|
102
|
+
left,
|
|
103
|
+
width
|
|
104
|
+
} = this.sliderRect
|
|
105
|
+
|
|
106
|
+
// 初始值为本次偏移量x,加上次停止滑动时的结束值
|
|
107
|
+
let exporession = `(${this.x} + x)`
|
|
108
|
+
// 将偏移的x值,转为总位移的百分比值,为了和min和max进行判断
|
|
109
|
+
exporession = `(${exporession} / ${width}) * 100`
|
|
110
|
+
if (step > 1) {
|
|
111
|
+
// 如果step步进大于1,需要跳步,所以需要使用Math.round进行取整
|
|
112
|
+
exporession = `round(max(${min}, min(${exporession}, ${max})) / ${step}) * ${step}`
|
|
113
|
+
} else {
|
|
114
|
+
// 当step=1时,无需跳步,充分利用bindingx性能,滑块实时跟随手势,达到丝滑的效果
|
|
115
|
+
exporession = `max(${min}, min(${exporession}, ${max}))`
|
|
116
|
+
}
|
|
117
|
+
// 将百分比最后转化为对应的px值
|
|
118
|
+
exporession = `${exporession} / 100 * ${width}`
|
|
119
|
+
// 最大值不允许超过轨迹的宽度
|
|
120
|
+
const {
|
|
121
|
+
sliderWidth
|
|
122
|
+
} = this.sliderRect
|
|
123
|
+
exporession = `min(${sliderWidth}, ${exporession})`
|
|
124
|
+
// 滑块点总是需要一个左偏移的值,为自身宽度的一半
|
|
125
|
+
const buttonExpression = `${exporession} - ${this.blockHeight / 2}`
|
|
126
|
+
// 阿里为了KPI而开源的BindingX
|
|
127
|
+
this.panEvent = BindingX.bind({
|
|
128
|
+
anchor: button,
|
|
129
|
+
eventType: 'pan',
|
|
130
|
+
props: [{
|
|
131
|
+
element: gap,
|
|
132
|
+
// 绑定width属性,设置其宽度值
|
|
133
|
+
property: 'width',
|
|
134
|
+
expression
|
|
135
|
+
}, {
|
|
136
|
+
element: button,
|
|
137
|
+
// 绑定width属性,设置其宽度值
|
|
138
|
+
property: 'transform.translateX',
|
|
139
|
+
expression: buttonExpression
|
|
140
|
+
}]
|
|
141
|
+
}, (e) => {
|
|
142
|
+
if (e.state === 'end' || e.state === 'exit') {
|
|
143
|
+
//
|
|
144
|
+
this.x = uni.$u.range(0, left + width, e.deltaX + this.x)
|
|
145
|
+
// 根据偏移值,得出移动的百分比,进而修改双向绑定的v-model的值
|
|
146
|
+
const value = (this.x / width) * 100
|
|
147
|
+
const percent = this.formatStep(value)
|
|
148
|
+
// 修改value值
|
|
149
|
+
this.$emit('input', percent)
|
|
150
|
+
// 标记下一次触发value的watch时,这个值的变化,是由内部改变的
|
|
151
|
+
this.changeFromInside = true
|
|
152
|
+
this.moving = false
|
|
153
|
+
this.touching = false
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
},
|
|
157
|
+
// 从value的变化,倒推得出x的值该为多少
|
|
158
|
+
initX() {
|
|
159
|
+
const {
|
|
160
|
+
left,
|
|
161
|
+
width
|
|
162
|
+
} = this.sliderRect
|
|
163
|
+
// 得出x的初始偏移值,之所以需要这么做,是因为在bindingX中,触摸滑动时,只能的值本次移动的偏移值
|
|
164
|
+
// 而无法的值准确的前后移动的两个点的坐标值,weex纯粹为阿里巴巴的KPI(部门业绩考核)产物,也就这样了
|
|
165
|
+
this.x = this.value / 100 * width
|
|
166
|
+
// 设置移动的值
|
|
167
|
+
const barStyle = {
|
|
168
|
+
width: this.x + 'px'
|
|
169
|
+
}
|
|
170
|
+
// 按钮的初始值
|
|
171
|
+
const buttonWrapperStyle = {
|
|
172
|
+
transform: `translateX(${this.x - this.blockHeight / 2}px)`
|
|
173
|
+
}
|
|
174
|
+
this.initButtonStyle({
|
|
175
|
+
barStyle,
|
|
176
|
+
buttonWrapperStyle
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|