@tplc/wot 0.0.1
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/components/common/AbortablePromise.ts +36 -0
- package/components/common/abstracts/_config.scss +7 -0
- package/components/common/abstracts/_function.scss +76 -0
- package/components/common/abstracts/_mixin.scss +339 -0
- package/components/common/abstracts/variable.scss +1346 -0
- package/components/common/base64.ts +30 -0
- package/components/common/canvasHelper.ts +49 -0
- package/components/common/clickoutside.ts +34 -0
- package/components/common/dayjs.ts +157 -0
- package/components/common/event.ts +8 -0
- package/components/common/props.ts +51 -0
- package/components/common/util.ts +751 -0
- package/components/composables/useCell.ts +13 -0
- package/components/composables/useChildren.ts +122 -0
- package/components/composables/useCountDown.ts +138 -0
- package/components/composables/useLockScroll.ts +39 -0
- package/components/composables/useParent.ts +41 -0
- package/components/composables/usePopover.ts +193 -0
- package/components/composables/useQueue.ts +52 -0
- package/components/composables/useRaf.ts +37 -0
- package/components/composables/useTouch.ts +44 -0
- package/components/composables/useTranslate.ts +22 -0
- package/components/wd-action-sheet/index.scss +204 -0
- package/components/wd-action-sheet/types.ts +128 -0
- package/components/wd-action-sheet/wd-action-sheet.vue +174 -0
- package/components/wd-backtop/index.scss +25 -0
- package/components/wd-backtop/types.ts +37 -0
- package/components/wd-backtop/wd-backtop.vue +48 -0
- package/components/wd-badge/index.scss +59 -0
- package/components/wd-badge/types.ts +53 -0
- package/components/wd-badge/wd-badge.vue +69 -0
- package/components/wd-button/index.scss +340 -0
- package/components/wd-button/types.ts +112 -0
- package/components/wd-button/wd-button.vue +176 -0
- package/components/wd-calendar/index.scss +244 -0
- package/components/wd-calendar/types.ts +235 -0
- package/components/wd-calendar/wd-calendar.vue +456 -0
- package/components/wd-calendar-view/index.scss +9 -0
- package/components/wd-calendar-view/month/index.scss +151 -0
- package/components/wd-calendar-view/month/month.vue +391 -0
- package/components/wd-calendar-view/month/types.ts +19 -0
- package/components/wd-calendar-view/monthPanel/index.scss +89 -0
- package/components/wd-calendar-view/monthPanel/month-panel.vue +388 -0
- package/components/wd-calendar-view/monthPanel/types.ts +48 -0
- package/components/wd-calendar-view/types.ts +134 -0
- package/components/wd-calendar-view/utils.ts +451 -0
- package/components/wd-calendar-view/wd-calendar-view.vue +111 -0
- package/components/wd-calendar-view/year/index.scss +148 -0
- package/components/wd-calendar-view/year/types.ts +19 -0
- package/components/wd-calendar-view/year/year.vue +220 -0
- package/components/wd-calendar-view/yearPanel/index.scss +24 -0
- package/components/wd-calendar-view/yearPanel/types.ts +38 -0
- package/components/wd-calendar-view/yearPanel/year-panel.vue +140 -0
- package/components/wd-card/index.scss +70 -0
- package/components/wd-card/types.ts +30 -0
- package/components/wd-card/wd-card.vue +40 -0
- package/components/wd-cell/index.scss +189 -0
- package/components/wd-cell/types.ts +96 -0
- package/components/wd-cell/wd-cell.vue +135 -0
- package/components/wd-cell-group/index.scss +55 -0
- package/components/wd-cell-group/types.ts +41 -0
- package/components/wd-cell-group/wd-cell-group.vue +45 -0
- package/components/wd-checkbox/index.scss +285 -0
- package/components/wd-checkbox/types.ts +68 -0
- package/components/wd-checkbox/wd-checkbox.vue +185 -0
- package/components/wd-checkbox-group/index.scss +20 -0
- package/components/wd-checkbox-group/types.ts +59 -0
- package/components/wd-checkbox-group/wd-checkbox-group.vue +103 -0
- package/components/wd-circle/index.scss +18 -0
- package/components/wd-circle/types.ts +54 -0
- package/components/wd-circle/wd-circle.vue +318 -0
- package/components/wd-col/index.scss +19 -0
- package/components/wd-col/types.ts +15 -0
- package/components/wd-col/wd-col.vue +91 -0
- package/components/wd-col-picker/index.scss +241 -0
- package/components/wd-col-picker/types.ts +170 -0
- package/components/wd-col-picker/wd-col-picker.vue +550 -0
- package/components/wd-collapse/index.scss +55 -0
- package/components/wd-collapse/types.ts +63 -0
- package/components/wd-collapse/wd-collapse.vue +160 -0
- package/components/wd-collapse-item/index.scss +79 -0
- package/components/wd-collapse-item/types.ts +36 -0
- package/components/wd-collapse-item/wd-collapse-item.vue +182 -0
- package/components/wd-config-provider/types.ts +1023 -0
- package/components/wd-config-provider/wd-config-provider.vue +82 -0
- package/components/wd-count-down/index.scss +14 -0
- package/components/wd-count-down/types.ts +41 -0
- package/components/wd-count-down/utils.ts +52 -0
- package/components/wd-count-down/wd-count-down.vue +60 -0
- package/components/wd-count-to/index.scss +6 -0
- package/components/wd-count-to/types.ts +110 -0
- package/components/wd-count-to/wd-count-to.vue +134 -0
- package/components/wd-curtain/index.scss +80 -0
- package/components/wd-curtain/types.ts +45 -0
- package/components/wd-curtain/wd-curtain.vue +174 -0
- package/components/wd-datetime-picker/index.scss +243 -0
- package/components/wd-datetime-picker/types.ts +225 -0
- package/components/wd-datetime-picker/wd-datetime-picker.vue +827 -0
- package/components/wd-datetime-picker-view/index.scss +0 -0
- package/components/wd-datetime-picker-view/types.ts +137 -0
- package/components/wd-datetime-picker-view/wd-datetime-picker-view.vue +514 -0
- package/components/wd-divider/index.scss +32 -0
- package/components/wd-divider/types.ts +12 -0
- package/components/wd-divider/wd-divider.vue +29 -0
- package/components/wd-drop-menu/index.scss +89 -0
- package/components/wd-drop-menu/types.ts +38 -0
- package/components/wd-drop-menu/wd-drop-menu.vue +128 -0
- package/components/wd-drop-menu-item/index.scss +66 -0
- package/components/wd-drop-menu-item/types.ts +78 -0
- package/components/wd-drop-menu-item/wd-drop-menu-item.vue +230 -0
- package/components/wd-fab/index.scss +115 -0
- package/components/wd-fab/types.ts +61 -0
- package/components/wd-fab/wd-fab.vue +257 -0
- package/components/wd-form/index.scss +10 -0
- package/components/wd-form/types.ts +93 -0
- package/components/wd-form/wd-form.vue +185 -0
- package/components/wd-form-item/index.scss +17 -0
- package/components/wd-form-item/types.ts +22 -0
- package/components/wd-form-item/wd-form-item.vue +65 -0
- package/components/wd-gap/index.scss +9 -0
- package/components/wd-gap/types.ts +23 -0
- package/components/wd-gap/wd-gap.vue +39 -0
- package/components/wd-grid/index.scss +9 -0
- package/components/wd-grid/types.ts +54 -0
- package/components/wd-grid/wd-grid.vue +107 -0
- package/components/wd-grid-item/index.scss +137 -0
- package/components/wd-grid-item/types.ts +74 -0
- package/components/wd-grid-item/wd-grid-item.vue +181 -0
- package/components/wd-icon/index.scss +1222 -0
- package/components/wd-icon/types.ts +21 -0
- package/components/wd-icon/wd-icon.vue +53 -0
- package/components/wd-icon/wd-icons.ttf +0 -0
- package/components/wd-img/index.scss +19 -0
- package/components/wd-img/types.ts +53 -0
- package/components/wd-img/wd-img.vue +76 -0
- package/components/wd-img-cropper/index.scss +227 -0
- package/components/wd-img-cropper/types.ts +87 -0
- package/components/wd-img-cropper/wd-img-cropper.vue +659 -0
- package/components/wd-index-anchor/index.scss +34 -0
- package/components/wd-index-anchor/type.ts +9 -0
- package/components/wd-index-anchor/wd-index-anchor.vue +57 -0
- package/components/wd-index-bar/index.scss +39 -0
- package/components/wd-index-bar/type.ts +28 -0
- package/components/wd-index-bar/wd-index-bar.vue +158 -0
- package/components/wd-input/index.scss +326 -0
- package/components/wd-input/types.ts +182 -0
- package/components/wd-input/wd-input.vue +327 -0
- package/components/wd-input-number/index.scss +132 -0
- package/components/wd-input-number/types.ts +78 -0
- package/components/wd-input-number/wd-input-number.vue +221 -0
- package/components/wd-loading/index.scss +34 -0
- package/components/wd-loading/types.ts +31 -0
- package/components/wd-loading/wd-loading.vue +90 -0
- package/components/wd-loadmore/index.scss +39 -0
- package/components/wd-loadmore/types.ts +24 -0
- package/components/wd-loadmore/wd-loadmore.vue +53 -0
- package/components/wd-message-box/index.scss +121 -0
- package/components/wd-message-box/index.ts +95 -0
- package/components/wd-message-box/types.ts +116 -0
- package/components/wd-message-box/wd-message-box.vue +326 -0
- package/components/wd-navbar/index.scss +103 -0
- package/components/wd-navbar/types.ts +52 -0
- package/components/wd-navbar/wd-navbar.vue +142 -0
- package/components/wd-navbar-capsule/index.scss +65 -0
- package/components/wd-navbar-capsule/types.ts +0 -0
- package/components/wd-navbar-capsule/wd-navbar-capsule.vue +31 -0
- package/components/wd-notice-bar/index.scss +86 -0
- package/components/wd-notice-bar/types.ts +56 -0
- package/components/wd-notice-bar/wd-notice-bar.vue +223 -0
- package/components/wd-notify/index.scss +34 -0
- package/components/wd-notify/index.ts +59 -0
- package/components/wd-notify/types.ts +62 -0
- package/components/wd-notify/wd-notify.vue +83 -0
- package/components/wd-number-keyboard/index.scss +78 -0
- package/components/wd-number-keyboard/key/index.scss +79 -0
- package/components/wd-number-keyboard/key/index.vue +76 -0
- package/components/wd-number-keyboard/key/types.ts +11 -0
- package/components/wd-number-keyboard/types.ts +79 -0
- package/components/wd-number-keyboard/wd-number-keyboard.vue +173 -0
- package/components/wd-overlay/index.scss +17 -0
- package/components/wd-overlay/types.ts +25 -0
- package/components/wd-overlay/wd-overlay.vue +46 -0
- package/components/wd-pagination/index.scss +57 -0
- package/components/wd-pagination/types.ts +41 -0
- package/components/wd-pagination/wd-pagination.vue +121 -0
- package/components/wd-password-input/index.scss +123 -0
- package/components/wd-password-input/types.ts +48 -0
- package/components/wd-password-input/wd-password-input.vue +58 -0
- package/components/wd-picker/index.scss +216 -0
- package/components/wd-picker/types.ts +186 -0
- package/components/wd-picker/wd-picker.vue +409 -0
- package/components/wd-picker-view/index.scss +91 -0
- package/components/wd-picker-view/types.ts +162 -0
- package/components/wd-picker-view/wd-picker-view.vue +361 -0
- package/components/wd-popover/index.scss +123 -0
- package/components/wd-popover/types.ts +69 -0
- package/components/wd-popover/wd-popover.vue +216 -0
- package/components/wd-popup/index.scss +112 -0
- package/components/wd-popup/types.ts +68 -0
- package/components/wd-popup/wd-popup.vue +227 -0
- package/components/wd-progress/index.scss +62 -0
- package/components/wd-progress/types.ts +40 -0
- package/components/wd-progress/wd-progress.vue +201 -0
- package/components/wd-radio/index.scss +300 -0
- package/components/wd-radio/types.ts +42 -0
- package/components/wd-radio/wd-radio.vue +136 -0
- package/components/wd-radio-group/index.scss +23 -0
- package/components/wd-radio-group/types.ts +36 -0
- package/components/wd-radio-group/wd-radio-group.vue +54 -0
- package/components/wd-rate/index.scss +24 -0
- package/components/wd-rate/types.ts +91 -0
- package/components/wd-rate/wd-rate.vue +131 -0
- package/components/wd-resize/index.scss +26 -0
- package/components/wd-resize/types.ts +6 -0
- package/components/wd-resize/wd-resize.vue +155 -0
- package/components/wd-row/index.scss +10 -0
- package/components/wd-row/types.ts +16 -0
- package/components/wd-row/wd-row.vue +63 -0
- package/components/wd-search/index.scss +148 -0
- package/components/wd-search/types.ts +83 -0
- package/components/wd-search/wd-search.vue +237 -0
- package/components/wd-segmented/index.scss +97 -0
- package/components/wd-segmented/types.ts +68 -0
- package/components/wd-segmented/wd-segmented.vue +143 -0
- package/components/wd-select-picker/index.scss +177 -0
- package/components/wd-select-picker/types.ts +116 -0
- package/components/wd-select-picker/wd-select-picker.vue +486 -0
- package/components/wd-sidebar/index.scss +25 -0
- package/components/wd-sidebar/types.ts +28 -0
- package/components/wd-sidebar/wd-sidebar.vue +41 -0
- package/components/wd-sidebar-item/index.scss +93 -0
- package/components/wd-sidebar-item/types.ts +31 -0
- package/components/wd-sidebar-item/wd-sidebar-item.vue +114 -0
- package/components/wd-skeleton/index.scss +101 -0
- package/components/wd-skeleton/index.ts +1 -0
- package/components/wd-skeleton/types.ts +69 -0
- package/components/wd-skeleton/wd-skeleton.vue +135 -0
- package/components/wd-slider/index.scss +91 -0
- package/components/wd-slider/types.ts +104 -0
- package/components/wd-slider/wd-slider.vue +377 -0
- package/components/wd-sort-button/index.scss +86 -0
- package/components/wd-sort-button/types.ts +43 -0
- package/components/wd-sort-button/wd-sort-button.vue +76 -0
- package/components/wd-status-tip/index.scss +37 -0
- package/components/wd-status-tip/types.ts +59 -0
- package/components/wd-status-tip/wd-status-tip.vue +94 -0
- package/components/wd-step/index.scss +236 -0
- package/components/wd-step/types.ts +33 -0
- package/components/wd-step/wd-step.vue +151 -0
- package/components/wd-steps/index.scss +10 -0
- package/components/wd-steps/types.ts +59 -0
- package/components/wd-steps/wd-steps.vue +37 -0
- package/components/wd-sticky/index.scss +9 -0
- package/components/wd-sticky/types.ts +13 -0
- package/components/wd-sticky/wd-sticky.vue +190 -0
- package/components/wd-sticky-box/index.scss +6 -0
- package/components/wd-sticky-box/types.ts +20 -0
- package/components/wd-sticky-box/wd-sticky-box.vue +154 -0
- package/components/wd-swipe-action/index.scss +22 -0
- package/components/wd-swipe-action/types.ts +43 -0
- package/components/wd-swipe-action/wd-swipe-action.vue +307 -0
- package/components/wd-swiper/index.scss +23 -0
- package/components/wd-swiper/types.ts +189 -0
- package/components/wd-swiper/wd-swiper.vue +202 -0
- package/components/wd-swiper-nav/index.scss +153 -0
- package/components/wd-swiper-nav/types.ts +42 -0
- package/components/wd-swiper-nav/wd-swiper-nav.vue +37 -0
- package/components/wd-switch/index.scss +58 -0
- package/components/wd-switch/types.ts +56 -0
- package/components/wd-switch/wd-switch.vue +83 -0
- package/components/wd-tab/index.scss +8 -0
- package/components/wd-tab/types.ts +20 -0
- package/components/wd-tab/wd-tab.vue +100 -0
- package/components/wd-tabbar/index.scss +57 -0
- package/components/wd-tabbar/types.ts +88 -0
- package/components/wd-tabbar/wd-tabbar.vue +104 -0
- package/components/wd-tabbar-item/index.scss +52 -0
- package/components/wd-tabbar-item/types.ts +51 -0
- package/components/wd-tabbar-item/wd-tabbar-item.vue +101 -0
- package/components/wd-table/index.scss +132 -0
- package/components/wd-table/types.ts +69 -0
- package/components/wd-table/wd-table.vue +255 -0
- package/components/wd-table-col/index.scss +44 -0
- package/components/wd-table-col/types.ts +54 -0
- package/components/wd-table-col/wd-table-col.vue +149 -0
- package/components/wd-tabs/index.scss +280 -0
- package/components/wd-tabs/types.ts +71 -0
- package/components/wd-tabs/wd-tabs.vue +528 -0
- package/components/wd-tag/index.scss +115 -0
- package/components/wd-tag/types.ts +81 -0
- package/components/wd-tag/wd-tag.vue +154 -0
- package/components/wd-text/index.scss +34 -0
- package/components/wd-text/types.ts +98 -0
- package/components/wd-text/wd-text.vue +138 -0
- package/components/wd-textarea/index.scss +343 -0
- package/components/wd-textarea/types.ts +298 -0
- package/components/wd-textarea/wd-textarea.vue +303 -0
- package/components/wd-toast/index.scss +66 -0
- package/components/wd-toast/index.ts +109 -0
- package/components/wd-toast/types.ts +76 -0
- package/components/wd-toast/wd-toast.vue +212 -0
- package/components/wd-tooltip/index.scss +61 -0
- package/components/wd-tooltip/types.ts +102 -0
- package/components/wd-tooltip/wd-tooltip.vue +167 -0
- package/components/wd-transition/index.scss +91 -0
- package/components/wd-transition/types.ts +89 -0
- package/components/wd-transition/wd-transition.vue +221 -0
- package/components/wd-upload/index.scss +173 -0
- package/components/wd-upload/types.ts +378 -0
- package/components/wd-upload/utils.ts +152 -0
- package/components/wd-upload/wd-upload.vue +737 -0
- package/components/wd-video-preview/index.scss +34 -0
- package/components/wd-video-preview/types.ts +32 -0
- package/components/wd-video-preview/wd-video-preview.vue +76 -0
- package/components/wd-watermark/index.scss +18 -0
- package/components/wd-watermark/types.ts +82 -0
- package/components/wd-watermark/wd-watermark.vue +592 -0
- package/components/wot-design-uni/wot-design-uni.vue +14 -0
- package/global.d.ts +108 -0
- package/index.ts +30 -0
- package/locale/index.ts +41 -0
- package/locale/lang/en-US.ts +128 -0
- package/locale/lang/th-TH.ts +127 -0
- package/locale/lang/vi-VN.ts +89 -0
- package/locale/lang/zh-CN.ts +127 -0
- package/locale/lang/zh-HK.ts +84 -0
- package/locale/lang/zh-TW.ts +84 -0
- package/package.json +20 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :style="`${rootStyle};display: inline-block;`">
|
|
3
|
+
<view :class="`wd-sticky ${customClass}`" :style="stickyStyle" :id="styckyId">
|
|
4
|
+
<view class="wd-sticky__container" :style="containerStyle">
|
|
5
|
+
<wd-resize @resize="handleResize" custom-style="display: inline-block;">
|
|
6
|
+
<slot />
|
|
7
|
+
</wd-resize>
|
|
8
|
+
</view>
|
|
9
|
+
</view>
|
|
10
|
+
</view>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
export default {
|
|
15
|
+
name: 'wd-sticky',
|
|
16
|
+
options: {
|
|
17
|
+
addGlobalClass: true,
|
|
18
|
+
virtualHost: true,
|
|
19
|
+
styleIsolation: 'shared',
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script lang="ts" setup>
|
|
25
|
+
import { computed, getCurrentInstance, reactive, ref, type CSSProperties } from 'vue'
|
|
26
|
+
import { addUnit, getRect, objToStyle, requestAnimationFrame, uuid } from '../common/util'
|
|
27
|
+
import { stickyProps } from './types'
|
|
28
|
+
import { useParent } from '../composables/useParent'
|
|
29
|
+
import { STICKY_BOX_KEY } from '../wd-sticky-box/types'
|
|
30
|
+
|
|
31
|
+
const props = defineProps(stickyProps)
|
|
32
|
+
const styckyId = ref<string>(`wd-sticky${uuid()}`)
|
|
33
|
+
const observerList = ref<UniApp.IntersectionObserver[]>([])
|
|
34
|
+
|
|
35
|
+
const stickyState = reactive({
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
boxLeaved: false,
|
|
38
|
+
top: 0,
|
|
39
|
+
height: 0,
|
|
40
|
+
width: 0,
|
|
41
|
+
state: '',
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const { parent: stickyBox } = useParent(STICKY_BOX_KEY)
|
|
45
|
+
|
|
46
|
+
const { proxy } = getCurrentInstance() as any
|
|
47
|
+
|
|
48
|
+
const rootStyle = computed(() => {
|
|
49
|
+
const style: CSSProperties = {
|
|
50
|
+
'z-index': props.zIndex,
|
|
51
|
+
height: addUnit(stickyState.height),
|
|
52
|
+
width: addUnit(stickyState.width),
|
|
53
|
+
}
|
|
54
|
+
if (!stickyState.boxLeaved) {
|
|
55
|
+
style.position = 'relative'
|
|
56
|
+
}
|
|
57
|
+
return `${objToStyle(style)};${props.customStyle}`
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const stickyStyle = computed(() => {
|
|
61
|
+
const style: CSSProperties = {
|
|
62
|
+
'z-index': props.zIndex,
|
|
63
|
+
height: addUnit(stickyState.height),
|
|
64
|
+
width: addUnit(stickyState.width),
|
|
65
|
+
}
|
|
66
|
+
if (!stickyState.boxLeaved) {
|
|
67
|
+
style.position = 'relative'
|
|
68
|
+
}
|
|
69
|
+
return `${objToStyle(style)};`
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const containerStyle = computed(() => {
|
|
73
|
+
const style: CSSProperties = {
|
|
74
|
+
position: stickyState.position as 'static' | 'relative' | 'absolute' | 'sticky' | 'fixed',
|
|
75
|
+
top: addUnit(stickyState.top),
|
|
76
|
+
}
|
|
77
|
+
return objToStyle(style)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const innerOffsetTop = computed(() => {
|
|
81
|
+
let top: number = 0
|
|
82
|
+
// #ifdef H5
|
|
83
|
+
// H5端,导航栏为普通元素,需要将组件移动到导航栏的下边沿
|
|
84
|
+
// H5的导航栏高度为44px
|
|
85
|
+
top = 44
|
|
86
|
+
// #endif
|
|
87
|
+
|
|
88
|
+
return top + props.offsetTop
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 清除对当前组件的监听
|
|
93
|
+
*/
|
|
94
|
+
function clearObserver() {
|
|
95
|
+
while (observerList.value.length !== 0) {
|
|
96
|
+
observerList.value.pop()!.disconnect()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 添加对当前组件的监听
|
|
101
|
+
*/
|
|
102
|
+
function createObserver() {
|
|
103
|
+
const observer = uni.createIntersectionObserver(proxy, { thresholds: [0, 0.5] })
|
|
104
|
+
observerList.value.push(observer)
|
|
105
|
+
return observer
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 当前内容高度发生变化时重置监听
|
|
109
|
+
*/
|
|
110
|
+
function handleResize(detail: any) {
|
|
111
|
+
stickyState.width = detail.width
|
|
112
|
+
stickyState.height = detail.height
|
|
113
|
+
requestAnimationFrame(() => {
|
|
114
|
+
observerContentScroll()
|
|
115
|
+
if (!stickyBox || !stickyBox.observerForChild) return
|
|
116
|
+
stickyBox.observerForChild(proxy)
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 监听吸顶元素滚动事件
|
|
121
|
+
*/
|
|
122
|
+
function observerContentScroll() {
|
|
123
|
+
if (stickyState.height === 0 && stickyState.width === 0) return
|
|
124
|
+
const offset = innerOffsetTop.value + stickyState.height
|
|
125
|
+
clearObserver()
|
|
126
|
+
createObserver()
|
|
127
|
+
.relativeToViewport({
|
|
128
|
+
top: -offset,
|
|
129
|
+
})
|
|
130
|
+
.observe(`#${styckyId.value}`, (result) => {
|
|
131
|
+
handleRelativeTo(result)
|
|
132
|
+
})
|
|
133
|
+
getRect(`#${styckyId.value}`, false, proxy).then((res) => {
|
|
134
|
+
// #ifdef H5
|
|
135
|
+
// H5端,查询节点信息未计算导航栏高度
|
|
136
|
+
res.bottom = Number(res.bottom) + 44
|
|
137
|
+
// #endif
|
|
138
|
+
if (Number(res.bottom) <= offset) handleRelativeTo({ boundingClientRect: res })
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @description 根据位置进行吸顶
|
|
143
|
+
*/
|
|
144
|
+
function handleRelativeTo({ boundingClientRect }: any) {
|
|
145
|
+
// sticky 高度大于或等于 wd-sticky-box,使用 wd-sticky-box 无任何意义
|
|
146
|
+
if (stickyBox && stickyState.height >= stickyBox.boxStyle.height) {
|
|
147
|
+
stickyState.position = 'absolute'
|
|
148
|
+
stickyState.top = 0
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let isStycky = boundingClientRect.top <= innerOffsetTop.value
|
|
153
|
+
// #ifdef H5 || APP-PLUS
|
|
154
|
+
isStycky = boundingClientRect.top < innerOffsetTop.value
|
|
155
|
+
// #endif
|
|
156
|
+
|
|
157
|
+
if (isStycky) {
|
|
158
|
+
stickyState.state = 'sticky'
|
|
159
|
+
stickyState.boxLeaved = false
|
|
160
|
+
stickyState.position = 'fixed'
|
|
161
|
+
stickyState.top = innerOffsetTop.value
|
|
162
|
+
} else {
|
|
163
|
+
stickyState.state = 'normal'
|
|
164
|
+
stickyState.boxLeaved = false
|
|
165
|
+
stickyState.position = 'absolute'
|
|
166
|
+
stickyState.top = 0
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 设置位置
|
|
172
|
+
* @param setboxLeaved
|
|
173
|
+
* @param setPosition
|
|
174
|
+
* @param setTop
|
|
175
|
+
*/
|
|
176
|
+
function setPosition(boxLeaved: boolean, position: string, top: number) {
|
|
177
|
+
stickyState.boxLeaved = boxLeaved
|
|
178
|
+
stickyState.position = position
|
|
179
|
+
stickyState.top = top
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
defineExpose({
|
|
183
|
+
setPosition,
|
|
184
|
+
stickyState,
|
|
185
|
+
offsetTop: props.offsetTop,
|
|
186
|
+
})
|
|
187
|
+
</script>
|
|
188
|
+
<style lang="scss" scoped>
|
|
189
|
+
@import './index';
|
|
190
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2024-04-08 22:34:01
|
|
4
|
+
* @LastEditTime: 2024-06-01 16:04:56
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description:
|
|
7
|
+
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/wd-sticky-box/types.ts
|
|
8
|
+
* 记得注释
|
|
9
|
+
*/
|
|
10
|
+
import type { ComponentInternalInstance, InjectionKey } from 'vue'
|
|
11
|
+
|
|
12
|
+
export type stickyBoxProvide = {
|
|
13
|
+
boxStyle: {
|
|
14
|
+
height: number // 高度
|
|
15
|
+
width: number // 宽度
|
|
16
|
+
}
|
|
17
|
+
observerForChild: (child: ComponentInternalInstance) => void // 监听子组件
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const STICKY_BOX_KEY: InjectionKey<stickyBoxProvide> = Symbol('wd-sticky-box')
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view style="position: relative">
|
|
3
|
+
<view :class="`wd-sticky-box ${props.customClass}`" :style="customStyle" :id="styckyBoxId">
|
|
4
|
+
<wd-resize @resize="handleResize">
|
|
5
|
+
<slot />
|
|
6
|
+
</wd-resize>
|
|
7
|
+
</view>
|
|
8
|
+
</view>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
export default {
|
|
13
|
+
name: 'wd-sticky-box',
|
|
14
|
+
options: {
|
|
15
|
+
addGlobalClass: true,
|
|
16
|
+
// virtualHost: true,
|
|
17
|
+
styleIsolation: 'shared',
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts" setup>
|
|
23
|
+
import { getCurrentInstance, onBeforeMount, reactive, ref } from 'vue'
|
|
24
|
+
import { getRect, uuid } from '../common/util'
|
|
25
|
+
import { baseProps } from '../common/props'
|
|
26
|
+
import { STICKY_BOX_KEY } from './types'
|
|
27
|
+
import { useChildren } from '../composables/useChildren'
|
|
28
|
+
|
|
29
|
+
const props = defineProps(baseProps)
|
|
30
|
+
|
|
31
|
+
const styckyBoxId = ref<string>(`wd-sticky-box${uuid()}`)
|
|
32
|
+
|
|
33
|
+
const observerMap = ref<Map<any, any>>(new Map())
|
|
34
|
+
|
|
35
|
+
const boxStyle = reactive({
|
|
36
|
+
height: 0,
|
|
37
|
+
width: 0,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const { proxy } = getCurrentInstance() as any
|
|
41
|
+
|
|
42
|
+
const { children: stickyList, linkChildren } = useChildren(STICKY_BOX_KEY)
|
|
43
|
+
linkChildren({
|
|
44
|
+
boxStyle,
|
|
45
|
+
observerForChild,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
onBeforeMount(() => {
|
|
49
|
+
observerMap.value = new Map()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 容器大小变化后重新监听sticky组件与box组件的交叉状态
|
|
54
|
+
* @param detail
|
|
55
|
+
*/
|
|
56
|
+
function handleResize(detail: any) {
|
|
57
|
+
// 相对的容器大小改变后,同步设置 wd-sticky-box 的大小
|
|
58
|
+
boxStyle.width = detail.width
|
|
59
|
+
boxStyle.height = detail.height
|
|
60
|
+
// wd-sticky-box 大小变化时,重新监听所有吸顶元素
|
|
61
|
+
const temp = observerMap.value
|
|
62
|
+
observerMap.value = new Map()
|
|
63
|
+
for (const [uid] of temp) {
|
|
64
|
+
const child = stickyList.find((sticky) => {
|
|
65
|
+
return sticky.$.uid === uid
|
|
66
|
+
})
|
|
67
|
+
observerForChild(child)
|
|
68
|
+
}
|
|
69
|
+
temp.forEach((observer) => {
|
|
70
|
+
observer.disconnect()
|
|
71
|
+
})
|
|
72
|
+
temp.clear()
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 删除对指定sticky的监听
|
|
76
|
+
* @param child 指定的子组件
|
|
77
|
+
*/
|
|
78
|
+
function deleteObserver(child: any) {
|
|
79
|
+
const observer = observerMap.value.get(child.$.uid)
|
|
80
|
+
if (!observer) return
|
|
81
|
+
observer.disconnect()
|
|
82
|
+
observerMap.value.delete(child.$.uid)
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 针对指定sticky添加监听
|
|
86
|
+
* @param child 指定的子组件
|
|
87
|
+
*/
|
|
88
|
+
function createObserver(child: any) {
|
|
89
|
+
const observer = uni.createIntersectionObserver(proxy, { thresholds: [0, 0.5] })
|
|
90
|
+
observerMap.value.set(child.$.uid, observer)
|
|
91
|
+
return observer
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 监听子组件
|
|
95
|
+
* @param child 子组件
|
|
96
|
+
*/
|
|
97
|
+
function observerForChild(child: any) {
|
|
98
|
+
deleteObserver(child)
|
|
99
|
+
const observer = createObserver(child)
|
|
100
|
+
const exposed = child.$.exposed
|
|
101
|
+
let offset = exposed.stickyState.height + exposed.offsetTop
|
|
102
|
+
// #ifdef H5
|
|
103
|
+
// H5端,导航栏为普通元素,需要将组件移动到导航栏的下边沿
|
|
104
|
+
// H5的导航栏高度为44px
|
|
105
|
+
offset = offset + 44
|
|
106
|
+
// #endif
|
|
107
|
+
|
|
108
|
+
if (boxStyle.height <= exposed.stickyState.height) {
|
|
109
|
+
exposed.setPosition(false, 'absolute', 0)
|
|
110
|
+
}
|
|
111
|
+
observer.relativeToViewport({ top: -offset }).observe(`#${styckyBoxId.value}`, (result) => {
|
|
112
|
+
handleRelativeTo(exposed, result)
|
|
113
|
+
})
|
|
114
|
+
// 当子组件默认处于边界外且永远不会进入边界内时,需要手动调用一次
|
|
115
|
+
getRect(`#${styckyBoxId.value}`, false, proxy)
|
|
116
|
+
.then((res) => {
|
|
117
|
+
// #ifdef H5
|
|
118
|
+
// H5端,查询节点信息未计算导航栏高度
|
|
119
|
+
res.bottom = Number(res.bottom) + 44
|
|
120
|
+
// #endif
|
|
121
|
+
if (Number(res.bottom) <= offset) handleRelativeTo(exposed, { boundingClientRect: res })
|
|
122
|
+
})
|
|
123
|
+
.catch((res) => {
|
|
124
|
+
console.log(res)
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 监听容器组件
|
|
129
|
+
* @param {Object} exposed wd-sticky实例暴露出的事件
|
|
130
|
+
* @param {Object} boundingClientRect 边界信息
|
|
131
|
+
*/
|
|
132
|
+
function handleRelativeTo(exposed: any, { boundingClientRect }: any) {
|
|
133
|
+
let childOffsetTop = exposed.offsetTop
|
|
134
|
+
// #ifdef H5
|
|
135
|
+
// H5端,导航栏为普通元素,需要将组件移动到导航栏的下边沿
|
|
136
|
+
// H5的导航栏高度为44px
|
|
137
|
+
childOffsetTop = childOffsetTop + 44
|
|
138
|
+
// #endif
|
|
139
|
+
const offset = exposed.stickyState.height + childOffsetTop
|
|
140
|
+
let isAbsolute = boundingClientRect.bottom <= offset
|
|
141
|
+
// #ifdef H5 || APP-PLUS
|
|
142
|
+
isAbsolute = boundingClientRect.bottom < offset
|
|
143
|
+
// #endif
|
|
144
|
+
if (isAbsolute) {
|
|
145
|
+
exposed.setPosition(true, 'absolute', boundingClientRect.height - exposed.stickyState.height)
|
|
146
|
+
} else if (boundingClientRect.top <= offset && !isAbsolute) {
|
|
147
|
+
if (exposed.stickyState.state === 'normal') return
|
|
148
|
+
exposed.setPosition(false, 'fixed', childOffsetTop)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
</script>
|
|
152
|
+
<style lang="scss" scoped>
|
|
153
|
+
@import './index';
|
|
154
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@import '../common/abstracts/variable';
|
|
2
|
+
@import '../common/abstracts/mixin';
|
|
3
|
+
|
|
4
|
+
@include b(swipe-action) {
|
|
5
|
+
position: relative;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
@include e(left) {
|
|
8
|
+
left: 0;
|
|
9
|
+
transform: translate3d(-100%, 0, 0);
|
|
10
|
+
}
|
|
11
|
+
@include e(right) {
|
|
12
|
+
right: 0;
|
|
13
|
+
transform: translate3d(100%, 0, 0);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.wd-swipe-action__left,
|
|
18
|
+
.wd-swipe-action__right {
|
|
19
|
+
position: absolute;
|
|
20
|
+
top: 0;
|
|
21
|
+
height: 100%;
|
|
22
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ExtractPropTypes, PropType } from 'vue'
|
|
2
|
+
import { baseProps, makeBooleanProp, makeStringProp } from '../common/props'
|
|
3
|
+
|
|
4
|
+
export type SwipeActionStatus = 'left' | 'close' | 'right'
|
|
5
|
+
|
|
6
|
+
// 点击关闭按钮、滑动关闭按钮、通过控制value关闭按钮
|
|
7
|
+
export type SwipeActionReason = 'click' | 'swipe' | 'value'
|
|
8
|
+
|
|
9
|
+
export type SwipeActionPosition = SwipeActionStatus | 'inside'
|
|
10
|
+
|
|
11
|
+
export type SwipeActionBeforeClose = (
|
|
12
|
+
reason: SwipeActionReason,
|
|
13
|
+
position: SwipeActionPosition,
|
|
14
|
+
) => void
|
|
15
|
+
|
|
16
|
+
export const swipeActionProps = {
|
|
17
|
+
...baseProps,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 滑动按钮的状态,使用v-model进行双向绑定。
|
|
21
|
+
* 可选值为:'left'(左滑)、'close'(关闭状态)、'right'(右滑)。
|
|
22
|
+
* 类型:string
|
|
23
|
+
* 默认值:'close'
|
|
24
|
+
*/
|
|
25
|
+
modelValue: makeStringProp<SwipeActionStatus>('close'),
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 是否禁用滑动操作。
|
|
29
|
+
* 类型:boolean
|
|
30
|
+
* 默认值:false
|
|
31
|
+
*/
|
|
32
|
+
disabled: makeBooleanProp(false),
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 在关闭滑动按钮前调用的钩子函数。
|
|
36
|
+
* 可以在此函数中执行一些关闭前的操作,如确认提示等。
|
|
37
|
+
* 类型:function
|
|
38
|
+
* 默认值:无
|
|
39
|
+
*/
|
|
40
|
+
beforeClose: Function as PropType<SwipeActionBeforeClose>,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type SwipeActionProps = ExtractPropTypes<typeof swipeActionProps>
|