uview-pro 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/changelog.md +6 -0
- package/components/u-action-sheet/u-action-sheet.vue +205 -0
- package/components/u-alert-tips/u-alert-tips.vue +241 -0
- package/components/u-avatar/u-avatar.vue +220 -0
- package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
- package/components/u-avatar-cropper/weCropper.d.ts +54 -0
- package/components/u-avatar-cropper/weCropper.js +1267 -0
- package/components/u-avatar-cropper/weCropper.ts +1254 -0
- package/components/u-back-top/u-back-top.vue +156 -0
- package/components/u-badge/u-badge.vue +189 -0
- package/components/u-button/u-button.vue +562 -0
- package/components/u-calendar/u-calendar.vue +725 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
- package/components/u-card/u-card.vue +240 -0
- package/components/u-cell-group/u-cell-group.vue +56 -0
- package/components/u-cell-item/u-cell-item.vue +245 -0
- package/components/u-checkbox/u-checkbox.vue +310 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
- package/components/u-circle-progress/u-circle-progress.vue +210 -0
- package/components/u-col/u-col.vue +135 -0
- package/components/u-collapse/u-collapse.vue +82 -0
- package/components/u-collapse-item/u-collapse-item.vue +190 -0
- package/components/u-column-notice/u-column-notice.vue +264 -0
- package/components/u-count-down/u-count-down.vue +333 -0
- package/components/u-count-to/u-count-to.vue +297 -0
- package/components/u-divider/u-divider.vue +141 -0
- package/components/u-dropdown/u-dropdown.vue +311 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
- package/components/u-empty/u-empty.vue +111 -0
- package/components/u-field/u-field.vue +469 -0
- package/components/u-form/u-form.vue +162 -0
- package/components/u-form-item/u-form-item.vue +476 -0
- package/components/u-full-screen/u-full-screen.vue +80 -0
- package/components/u-gap/u-gap.vue +48 -0
- package/components/u-grid/u-grid.vue +101 -0
- package/components/u-grid-item/u-grid-item.vue +136 -0
- package/components/u-icon/u-icon.vue +389 -0
- package/components/u-image/types.ts +48 -0
- package/components/u-image/u-image.vue +218 -0
- package/components/u-index-anchor/u-index-anchor.vue +101 -0
- package/components/u-index-list/u-index-list.vue +376 -0
- package/components/u-input/u-input.vue +462 -0
- package/components/u-keyboard/u-keyboard.vue +188 -0
- package/components/u-lazy-load/u-lazy-load.vue +288 -0
- package/components/u-line/u-line.vue +71 -0
- package/components/u-line-progress/u-line-progress.vue +128 -0
- package/components/u-link/u-link.vue +87 -0
- package/components/u-loading/u-loading.vue +111 -0
- package/components/u-loadmore/u-loadmore.vue +205 -0
- package/components/u-mask/u-mask.vue +137 -0
- package/components/u-message-input/u-message-input.vue +315 -0
- package/components/u-modal/u-modal.vue +284 -0
- package/components/u-navbar/u-navbar.vue +314 -0
- package/components/u-no-network/image.ts +2 -0
- package/components/u-no-network/u-no-network.vue +311 -0
- package/components/u-notice-bar/u-notice-bar.vue +274 -0
- package/components/u-number-box/u-number-box.vue +344 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
- package/components/u-parse/libs/CssHandler.js +100 -0
- package/components/u-parse/libs/MpHtmlParser.js +580 -0
- package/components/u-parse/libs/config.js +80 -0
- package/components/u-parse/libs/handler.wxs +22 -0
- package/components/u-parse/libs/trees.vue +505 -0
- package/components/u-parse/u-parse.vue +645 -0
- package/components/u-picker/u-picker.vue +808 -0
- package/components/u-popup/u-popup.vue +404 -0
- package/components/u-radio/u-radio.vue +272 -0
- package/components/u-radio-group/u-radio-group.vue +116 -0
- package/components/u-rate/u-rate.vue +349 -0
- package/components/u-read-more/u-read-more.vue +199 -0
- package/components/u-row/u-row.vue +95 -0
- package/components/u-row-notice/u-row-notice.vue +273 -0
- package/components/u-search/u-search.vue +298 -0
- package/components/u-section/u-section.vue +175 -0
- package/components/u-select/u-select.vue +387 -0
- package/components/u-skeleton/u-skeleton.vue +230 -0
- package/components/u-slider/u-slider.vue +293 -0
- package/components/u-steps/u-steps.vue +200 -0
- package/components/u-sticky/u-sticky.vue +189 -0
- package/components/u-subsection/u-subsection.vue +388 -0
- package/components/u-swipe-action/u-swipe-action.vue +289 -0
- package/components/u-swiper/u-swiper.vue +305 -0
- package/components/u-switch/u-switch.vue +146 -0
- package/components/u-tabbar/u-tabbar.vue +347 -0
- package/components/u-table/u-table.vue +104 -0
- package/components/u-tabs/u-tabs.vue +322 -0
- package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
- package/components/u-tag/u-tag.vue +270 -0
- package/components/u-td/u-td.vue +76 -0
- package/components/u-th/u-th.vue +70 -0
- package/components/u-time-line/u-time-line.vue +39 -0
- package/components/u-time-line-item/u-time-line-item.vue +88 -0
- package/components/u-toast/types.ts +4 -0
- package/components/u-toast/u-toast.vue +238 -0
- package/components/u-top-tips/u-top-tips.vue +118 -0
- package/components/u-tr/u-tr.vue +24 -0
- package/components/u-upload/u-upload.vue +600 -0
- package/components/u-verification-code/u-verification-code.vue +194 -0
- package/components/u-waterfall/u-waterfall.vue +186 -0
- package/iconfont.css +910 -0
- package/index.scss +23 -0
- package/index.ts +166 -0
- package/libs/config/config.ts +26 -0
- package/libs/config/zIndex.ts +37 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +176 -0
- package/libs/css/style.components.scss +7 -0
- package/libs/css/style.h5.scss +8 -0
- package/libs/css/style.mp.scss +72 -0
- package/libs/css/style.nvue.scss +3 -0
- package/libs/css/style.vue.scss +175 -0
- package/libs/function/$parent.ts +22 -0
- package/libs/function/addUnit.ts +13 -0
- package/libs/function/color.ts +37 -0
- package/libs/function/colorGradient.ts +123 -0
- package/libs/function/debounce.ts +28 -0
- package/libs/function/deepClone.ts +39 -0
- package/libs/function/deepMerge.ts +34 -0
- package/libs/function/getParent.ts +59 -0
- package/libs/function/getRect.ts +26 -0
- package/libs/function/guid.ts +42 -0
- package/libs/function/md5.ts +397 -0
- package/libs/function/parent.ts +21 -0
- package/libs/function/queryParams.ts +60 -0
- package/libs/function/random.ts +16 -0
- package/libs/function/randomArray.ts +11 -0
- package/libs/function/route.ts +118 -0
- package/libs/function/sys.ts +15 -0
- package/libs/function/test.ts +229 -0
- package/libs/function/throttle.ts +31 -0
- package/libs/function/timeFormat.ts +54 -0
- package/libs/function/timeFrom.ts +48 -0
- package/libs/function/toast.ts +14 -0
- package/libs/function/trim.ts +21 -0
- package/libs/function/type2icon.ts +36 -0
- package/libs/hooks/useEmitter.ts +77 -0
- package/libs/hooks/useParent.ts +29 -0
- package/libs/request/index.ts +237 -0
- package/libs/store/index.ts +88 -0
- package/libs/util/area.ts +1 -0
- package/libs/util/async-validator.js +1356 -0
- package/libs/util/city.ts +1 -0
- package/libs/util/emitter.ts +112 -0
- package/libs/util/mitt.ts +118 -0
- package/libs/util/parent.ts +20 -0
- package/libs/util/province.ts +1 -0
- package/package.json +98 -0
- package/readme.md +165 -0
- package/theme.scss +38 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="">
|
|
3
|
+
<view class="u-steps" :style="directionStyle">
|
|
4
|
+
<view class="u-steps__item" :class="['u-steps__item--' + direction]" v-for="(item, index) in list" :key="index">
|
|
5
|
+
<view class="u-steps__item__num" v-if="mode == 'number'" :style="numberStyle(index)">
|
|
6
|
+
<text v-if="currentIndex < index" :style="textStyle(index)">
|
|
7
|
+
{{ index + 1 }}
|
|
8
|
+
</text>
|
|
9
|
+
<u-icon v-else size="22" color="#ffffff" :name="icon"></u-icon>
|
|
10
|
+
</view>
|
|
11
|
+
<view class="u-steps__item__dot" v-if="mode == 'dot'" :style="dotStyle(index)"></view>
|
|
12
|
+
<text class="u-line-1" :style="textStyle(index)" :class="['u-steps__item__text--' + direction]">
|
|
13
|
+
{{ item.name }}
|
|
14
|
+
</text>
|
|
15
|
+
<view class="u-steps__item__line" :class="['u-steps__item__line--' + mode]" v-if="index < list.length - 1">
|
|
16
|
+
<u-line :direction="direction" length="100%" :hair-line="false" :color="unActiveColor"></u-line>
|
|
17
|
+
</view>
|
|
18
|
+
</view>
|
|
19
|
+
</view>
|
|
20
|
+
</view>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
import { computed } from 'vue';
|
|
25
|
+
|
|
26
|
+
defineOptions({ name: 'u-steps' });
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* steps 步骤条
|
|
30
|
+
* @description 该组件一般用于完成一个任务要分几个步骤,标识目前处于第几步的场景。
|
|
31
|
+
* @tutorial https://www.uviewui.com/components/steps.html
|
|
32
|
+
* @property {String} mode 设置模式(默认dot)
|
|
33
|
+
* @property {Array<{name: string}>} list 数轴条数据,数组。具体见上方示例
|
|
34
|
+
* @property {String} type type主题(默认primary)
|
|
35
|
+
* @property {String} direction row-横向,column-竖向(默认row)
|
|
36
|
+
* @property {Number|String} current 设置当前处于第几步
|
|
37
|
+
* @property {String} activeColor 已完成步骤的激活颜色,如设置,type值会失效
|
|
38
|
+
* @property {String} unActiveColor 未激活的颜色,用于表示未完成步骤的颜色(默认#606266)
|
|
39
|
+
* @property {String} icon 自定义图标
|
|
40
|
+
* @example <u-steps :list="numList" active-color="#fa3534"></u-steps>
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
const props = defineProps({
|
|
44
|
+
/** 步骤条的类型,dot|number */
|
|
45
|
+
mode: {
|
|
46
|
+
type: String,
|
|
47
|
+
default: 'dot'
|
|
48
|
+
},
|
|
49
|
+
/** 步骤条的数据 */
|
|
50
|
+
list: {
|
|
51
|
+
type: Array as () => { name: string }[],
|
|
52
|
+
default: (): { name: string }[] => []
|
|
53
|
+
},
|
|
54
|
+
/** 主题类型, primary|success|info|warning|error */
|
|
55
|
+
type: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: 'primary'
|
|
58
|
+
},
|
|
59
|
+
/** 当前哪一步是激活的 */
|
|
60
|
+
current: {
|
|
61
|
+
type: [Number, String],
|
|
62
|
+
default: 0
|
|
63
|
+
},
|
|
64
|
+
/** 激活步骤的颜色 */
|
|
65
|
+
activeColor: {
|
|
66
|
+
type: String,
|
|
67
|
+
default: '#2979ff'
|
|
68
|
+
},
|
|
69
|
+
/** 未激活的颜色 */
|
|
70
|
+
unActiveColor: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: '#909399'
|
|
73
|
+
},
|
|
74
|
+
/** 自定义图标 */
|
|
75
|
+
icon: {
|
|
76
|
+
type: String,
|
|
77
|
+
default: 'checkmark'
|
|
78
|
+
},
|
|
79
|
+
/** step的排列方向,row-横向,column-竖向 */
|
|
80
|
+
direction: {
|
|
81
|
+
type: String,
|
|
82
|
+
default: 'row'
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// 计算属性,计算当前步骤的索引值
|
|
87
|
+
// 如果 current 是字符串,则转换为数字,否则直接使用数字
|
|
88
|
+
const currentIndex = computed(() => (typeof props.current === 'string' ? Number(props.current) : props.current));
|
|
89
|
+
|
|
90
|
+
// 计算方向样式
|
|
91
|
+
const directionStyle = computed(() => ({ flexDirection: props.direction as 'row' | 'column' }));
|
|
92
|
+
|
|
93
|
+
// 计算当前步骤的样式
|
|
94
|
+
const numberStyle = (index: number) => ({
|
|
95
|
+
backgroundColor: currentIndex.value < index ? 'transparent' : props.activeColor,
|
|
96
|
+
borderColor: currentIndex.value < index ? props.unActiveColor : props.activeColor
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 计算当前步骤的样式
|
|
100
|
+
const dotStyle = (index: number) => ({
|
|
101
|
+
backgroundColor: index <= currentIndex.value ? props.activeColor : props.unActiveColor
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// 计算当前步骤的文字样式
|
|
105
|
+
const textStyle = (index: number) => ({
|
|
106
|
+
color: index <= currentIndex.value ? props.activeColor : props.unActiveColor
|
|
107
|
+
});
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<style lang="scss" scoped>
|
|
111
|
+
@import '../../libs/css/style.components.scss';
|
|
112
|
+
|
|
113
|
+
$u-steps-item-number-width: 44rpx;
|
|
114
|
+
$u-steps-item-dot-width: 20rpx;
|
|
115
|
+
|
|
116
|
+
.u-steps {
|
|
117
|
+
@include vue-flex;
|
|
118
|
+
|
|
119
|
+
.u-steps__item {
|
|
120
|
+
flex: 1;
|
|
121
|
+
text-align: center;
|
|
122
|
+
position: relative;
|
|
123
|
+
min-width: 100rpx;
|
|
124
|
+
font-size: 26rpx;
|
|
125
|
+
color: #8799a3;
|
|
126
|
+
@include vue-flex;
|
|
127
|
+
justify-content: center;
|
|
128
|
+
flex-direction: column;
|
|
129
|
+
align-items: center;
|
|
130
|
+
|
|
131
|
+
&--row {
|
|
132
|
+
@include vue-flex;
|
|
133
|
+
flex-direction: column;
|
|
134
|
+
|
|
135
|
+
.u-steps__item__line {
|
|
136
|
+
position: absolute;
|
|
137
|
+
z-index: 0;
|
|
138
|
+
left: 75%;
|
|
139
|
+
width: 50%;
|
|
140
|
+
|
|
141
|
+
&--dot {
|
|
142
|
+
top: calc(#{$u-steps-item-dot-width} / 2);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&--number {
|
|
146
|
+
top: calc(#{$u-steps-item-number-width} / 2);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&--column {
|
|
152
|
+
@include vue-flex;
|
|
153
|
+
flex-direction: row;
|
|
154
|
+
justify-content: flex-start;
|
|
155
|
+
min-height: 120rpx;
|
|
156
|
+
|
|
157
|
+
.u-steps__item__line {
|
|
158
|
+
position: absolute;
|
|
159
|
+
z-index: 0;
|
|
160
|
+
height: 50%;
|
|
161
|
+
top: 75%;
|
|
162
|
+
|
|
163
|
+
&--dot {
|
|
164
|
+
left: calc(#{$u-steps-item-dot-width} / 2);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
&--number {
|
|
168
|
+
left: calc(#{$u-steps-item-number-width} / 2);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
&__num {
|
|
174
|
+
@include vue-flex;
|
|
175
|
+
align-items: center;
|
|
176
|
+
justify-content: center;
|
|
177
|
+
width: $u-steps-item-number-width;
|
|
178
|
+
height: $u-steps-item-number-width;
|
|
179
|
+
border: 1px solid #8799a3;
|
|
180
|
+
border-radius: 50%;
|
|
181
|
+
overflow: hidden;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
&__dot {
|
|
185
|
+
width: $u-steps-item-dot-width;
|
|
186
|
+
height: $u-steps-item-dot-width;
|
|
187
|
+
@include vue-flex;
|
|
188
|
+
border-radius: 50%;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
&__text--row {
|
|
192
|
+
margin-top: 14rpx;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
&__text--column {
|
|
196
|
+
margin-left: 14rpx;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
</style>
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="">
|
|
3
|
+
<view
|
|
4
|
+
class="u-sticky-wrap"
|
|
5
|
+
:class="[elClass]"
|
|
6
|
+
:style="{
|
|
7
|
+
height: fixed ? height + 'px' : 'auto',
|
|
8
|
+
backgroundColor: bgColor
|
|
9
|
+
}"
|
|
10
|
+
>
|
|
11
|
+
<view
|
|
12
|
+
class="u-sticky"
|
|
13
|
+
:style="{
|
|
14
|
+
position: fixed ? 'fixed' : 'static',
|
|
15
|
+
top: stickyTop + 'px',
|
|
16
|
+
left: left + 'px',
|
|
17
|
+
width: width == 'auto' ? 'auto' : width + 'px',
|
|
18
|
+
zIndex: uZIndex
|
|
19
|
+
}"
|
|
20
|
+
>
|
|
21
|
+
<slot></slot>
|
|
22
|
+
</view>
|
|
23
|
+
</view>
|
|
24
|
+
</view>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script setup lang="ts">
|
|
28
|
+
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount, getCurrentInstance } from 'vue';
|
|
29
|
+
import { $u } from '../..';
|
|
30
|
+
|
|
31
|
+
defineOptions({ name: 'u-sticky' });
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* sticky 吸顶
|
|
35
|
+
* @description 该组件与CSS中position: sticky属性实现的效果一致,当组件达到预设的到顶部距离时, 就会固定在指定位置,组件位置大于预设的顶部距离时,会重新按照正常的布局排列。
|
|
36
|
+
* @tutorial https://www.uviewui.com/components/sticky.html
|
|
37
|
+
* @property {String|Number} offsetTop 吸顶时与顶部的距离,单位rpx(默认0)
|
|
38
|
+
* @property {String|Number} index 自定义标识,用于区分是哪一个组件
|
|
39
|
+
* @property {Boolean} enable 是否开启吸顶功能(默认true)
|
|
40
|
+
* @property {String} bgColor 组件背景颜色(默认#ffffff)
|
|
41
|
+
* @property {String|Number} zIndex 吸顶时的z-index值(默认970)
|
|
42
|
+
* @property {String|Number} h5NavHeight 导航栏高度,自定义导航栏时(无导航栏时需设置为0),需要传入此值,单位px(默认44)
|
|
43
|
+
* @event fixed 组件吸顶时触发
|
|
44
|
+
* @event unfixed 组件取消吸顶时触发
|
|
45
|
+
* @example <u-sticky offset-top="200"><view>塞下秋来风景异,衡阳雁去无留意</view></u-sticky>
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
const emit = defineEmits(['fixed', 'unfixed']);
|
|
49
|
+
|
|
50
|
+
const props = defineProps({
|
|
51
|
+
/** 吸顶容器到顶部某个距离的时候,进行吸顶,在H5平台,NavigationBar为44px */
|
|
52
|
+
offsetTop: {
|
|
53
|
+
type: [Number, String],
|
|
54
|
+
default: 0
|
|
55
|
+
},
|
|
56
|
+
/** 列表中的索引值 */
|
|
57
|
+
index: {
|
|
58
|
+
type: [Number, String],
|
|
59
|
+
default: ''
|
|
60
|
+
},
|
|
61
|
+
/** 是否开启吸顶功能 */
|
|
62
|
+
enable: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: true
|
|
65
|
+
},
|
|
66
|
+
/** h5顶部导航栏的高度 */
|
|
67
|
+
h5NavHeight: {
|
|
68
|
+
type: [Number, String],
|
|
69
|
+
default: 44
|
|
70
|
+
},
|
|
71
|
+
/** 吸顶区域的背景颜色 */
|
|
72
|
+
bgColor: {
|
|
73
|
+
type: String,
|
|
74
|
+
default: '#ffffff'
|
|
75
|
+
},
|
|
76
|
+
/** z-index值 */
|
|
77
|
+
zIndex: {
|
|
78
|
+
type: [Number, String],
|
|
79
|
+
default: ''
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const instance = getCurrentInstance();
|
|
83
|
+
const fixed = ref(false);
|
|
84
|
+
const height = ref<'auto' | number>('auto');
|
|
85
|
+
const stickyTop = ref(0);
|
|
86
|
+
const elClass = ref('');
|
|
87
|
+
const left = ref(0);
|
|
88
|
+
const width = ref<'auto' | number>('auto');
|
|
89
|
+
let contentObserver: any = null;
|
|
90
|
+
|
|
91
|
+
elClass.value = $u.guid();
|
|
92
|
+
|
|
93
|
+
const uZIndex = computed(() => (props.zIndex ? props.zIndex : $u?.zIndex?.sticky ?? 970));
|
|
94
|
+
|
|
95
|
+
watch(
|
|
96
|
+
() => props.offsetTop,
|
|
97
|
+
() => {
|
|
98
|
+
initObserver();
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
watch(
|
|
103
|
+
() => props.enable,
|
|
104
|
+
val => {
|
|
105
|
+
if (val == false) {
|
|
106
|
+
fixed.value = false;
|
|
107
|
+
disconnectObserver('contentObserver');
|
|
108
|
+
} else {
|
|
109
|
+
initObserver();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
onMounted(() => {
|
|
115
|
+
initObserver();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
onBeforeUnmount(() => {
|
|
119
|
+
disconnectObserver('contentObserver');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 初始化 IntersectionObserver 监听
|
|
124
|
+
*/
|
|
125
|
+
function initObserver() {
|
|
126
|
+
if (!props.enable) return;
|
|
127
|
+
// #ifdef H5
|
|
128
|
+
stickyTop.value = Number(props.offsetTop) !== 0 ? uni.upx2px(Number(props.offsetTop)) + Number(props.h5NavHeight) : Number(props.h5NavHeight);
|
|
129
|
+
// #endif
|
|
130
|
+
// #ifndef H5
|
|
131
|
+
stickyTop.value = Number(props.offsetTop) !== 0 ? uni.upx2px(Number(props.offsetTop)) : 0;
|
|
132
|
+
// #endif
|
|
133
|
+
console.log('stickyTop.value', stickyTop.value);
|
|
134
|
+
disconnectObserver('contentObserver');
|
|
135
|
+
$u.getRect('.' + elClass.value, instance).then((res: any) => {
|
|
136
|
+
height.value = res.height;
|
|
137
|
+
left.value = res.left;
|
|
138
|
+
width.value = res.width;
|
|
139
|
+
nextTick(() => {
|
|
140
|
+
observeContent();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 创建 IntersectionObserver 监听内容区域
|
|
147
|
+
*/
|
|
148
|
+
function observeContent() {
|
|
149
|
+
disconnectObserver('contentObserver');
|
|
150
|
+
|
|
151
|
+
contentObserver = uni.createIntersectionObserver(instance?.proxy, {
|
|
152
|
+
thresholds: [0.95, 0.98, 1]
|
|
153
|
+
});
|
|
154
|
+
contentObserver.relativeToViewport({
|
|
155
|
+
top: -stickyTop.value
|
|
156
|
+
});
|
|
157
|
+
contentObserver.observe('.' + elClass.value, (res: any) => {
|
|
158
|
+
if (!props.enable) return;
|
|
159
|
+
setFixed(res.boundingClientRect.top);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 设置 fixed 状态
|
|
165
|
+
*/
|
|
166
|
+
function setFixed(top: number) {
|
|
167
|
+
const isFixed = top < stickyTop.value;
|
|
168
|
+
if (isFixed) emit('fixed', props.index);
|
|
169
|
+
else if (fixed.value) emit('unfixed', props.index);
|
|
170
|
+
fixed.value = isFixed;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 断开 observer
|
|
175
|
+
*/
|
|
176
|
+
function disconnectObserver(observerName: string) {
|
|
177
|
+
if (observerName === 'contentObserver' && contentObserver) {
|
|
178
|
+
contentObserver.disconnect();
|
|
179
|
+
contentObserver = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<style scoped lang="scss">
|
|
185
|
+
@import '../../libs/css/style.components.scss';
|
|
186
|
+
.u-sticky {
|
|
187
|
+
z-index: 9999999999;
|
|
188
|
+
}
|
|
189
|
+
</style>
|