hy-app 0.5.6 → 0.5.7

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.
@@ -0,0 +1,73 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+ @use "../../libs/css/theme" as *;
3
+
4
+
5
+ @include b(card) {
6
+ position: relative;
7
+ overflow: hidden;
8
+ font-size: 28rpx;
9
+ background-color: $hy-background--container;
10
+ box-sizing: border-box;
11
+
12
+ @include e(full) {
13
+ margin-left: $hy-border-margin-padding-base !important;
14
+ margin-right: $hy-border-margin-padding-base !important;
15
+ }
16
+
17
+ @include m(border) {
18
+ @include pseudo(after) {
19
+ border-radius: 16rpx;
20
+ }
21
+ }
22
+
23
+ /* 头部 */
24
+ @include e(head) {
25
+ padding: 20rpx 20rpx 10rpx;
26
+ @include m(flex) {
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: space-between;
30
+ }
31
+
32
+ @include m(left) {
33
+ display: flex;
34
+ align-items: center;
35
+ flex: 1;
36
+
37
+ @include edeep(thumb) {
38
+ margin-right: $hy-border-margin-padding-base;
39
+ flex-shrink: 0
40
+ }
41
+
42
+ @include e(title) {
43
+ max-width: 400rpx;
44
+ font-size: $hy-font-size-base;
45
+ @include lineEllipsis;
46
+ }
47
+
48
+ @include e(sub) {
49
+ color: $hy-text-color--grey;
50
+ font-size: $hy-font-size-sm;
51
+ }
52
+ }
53
+
54
+ @include m(right) {
55
+ color: $hy-text-color--grey;
56
+ margin-left: $hy-border-margin-padding-sm;
57
+
58
+ @include e(text) {
59
+ white-space: nowrap;
60
+ }
61
+ }
62
+ }
63
+
64
+ /* 身体 */
65
+ @include e(body) {
66
+ padding: 10rpx 20rpx 10rpx;
67
+ }
68
+
69
+ /* 尾部 */
70
+ @include e(foot) {
71
+ padding: 10rpx 20rpx 20rpx;
72
+ }
73
+ }
@@ -0,0 +1,12 @@
1
+ import type { CSSProperties } from 'vue'
2
+
3
+ export default interface HyStatusBarProps {
4
+ /**
5
+ * @description 背景色 (默认 'transparent' )
6
+ * */
7
+ bgColor?: string
8
+ /**
9
+ * @description 自定义样式
10
+ * */
11
+ customStyle?: CSSProperties
12
+ }
@@ -0,0 +1,226 @@
1
+ <template>
2
+ <view>
3
+ <!-- 哨兵必须在 sticky 前面 -->
4
+ <view :id="sentinelId" class="hy-sticky__sentinel"></view>
5
+
6
+ <!-- 占位元素:当吸顶后占据原高度,避免页面抖动 -->
7
+ <view v-if="isFixed" :style="{ height: placeholderHeight + 'px' }" />
8
+
9
+ <view
10
+ ref="stickyRef"
11
+ :class="['hy-sticky', isFixed ? 'hy-sticky__fixed' : '']"
12
+ :style="mergedStyle"
13
+ >
14
+ <slot />
15
+ </view>
16
+ </view>
17
+ </template>
18
+
19
+ <script setup lang="ts">
20
+ import { ref, computed, onMounted, onUnmounted, nextTick, getCurrentInstance, watch } from 'vue'
21
+ import type { CSSProperties } from 'vue'
22
+ import { onPageScroll } from '@dcloudio/uni-app'
23
+ import { addUnit, getRect } from '../../libs'
24
+ import type { IStickyEmits } from './typing'
25
+ import stickyProps from './props'
26
+
27
+ const props = defineProps(stickyProps)
28
+ const emit = defineEmits<IStickyEmits>()
29
+
30
+ const instance = getCurrentInstance()
31
+ const sentinelId = `hy-sticky-sentinel-${Math.random().toString(36).slice(2, 9)}`
32
+ const stickyRef = ref<HTMLElement | null>(null)
33
+ const isFixed = ref(false)
34
+ const placeholderHeight = ref(0)
35
+ let observer: UniApp.IntersectionObserver | null = null
36
+ let rafTimer = 0
37
+
38
+ // 组件样式(吸顶时使用 fixed/fallback)
39
+ // 注意:position: sticky 在部分平台失效时,我们使用绝对 fixed 样式做回退
40
+ const mergedStyle = computed<CSSProperties>(() => {
41
+ if (!props.enable) return {}
42
+ if (isFixed.value) {
43
+ // fixed 样式回退,尽量跟 sticky 表现一致
44
+ return {
45
+ position: 'fixed',
46
+ top: addUnit(props.offsetTop),
47
+ left: '0px',
48
+ right: '0px',
49
+ zIndex: props.zIndex
50
+ // 保持宽度,如果需要你可以传入宽度样式到 custom style slot
51
+ }
52
+ } else {
53
+ return {
54
+ position: 'sticky',
55
+ top: addUnit(props.offsetTop),
56
+ zIndex: props.zIndex
57
+ }
58
+ }
59
+ })
60
+
61
+ // Helper: 查询哨兵和 sticky 高度/位置
62
+ const querySentinel = (): Promise<{
63
+ sentinelTop: number
64
+ sentinelBottom: number
65
+ stickyHeight: number
66
+ }> => {
67
+ return new Promise((resolve) => {
68
+ const query = uni.createSelectorQuery().in(instance!)
69
+ query
70
+ .select(`#${sentinelId}`)
71
+ .boundingClientRect()
72
+ .selectViewport()
73
+ .exec((res: any[]) => {
74
+ // res 结构:[ sentinelRect, viewportRect ]
75
+ const sentinelRect = res[0] || {}
76
+ const viewportRect = res[1] || {}
77
+ const stickyRectQuery = uni.createSelectorQuery().in(instance!)
78
+ stickyRectQuery
79
+ .select('.hy-sticky')
80
+ .boundingClientRect()
81
+ .exec((r2: any[]) => {
82
+ const stickyRect = (r2 && r2[0]) || {}
83
+ resolve({
84
+ sentinelTop: sentinelRect.top ?? 0,
85
+ sentinelBottom: sentinelRect.bottom ?? 0,
86
+ stickyHeight: stickyRect.height ?? 0
87
+ })
88
+ })
89
+ })
90
+ })
91
+ }
92
+
93
+ // IntersectionObserver 初始化(优先)
94
+ const initObserver = async () => {
95
+ if (!props.enable) return
96
+ // 先断开之前的
97
+ observer?.disconnect()
98
+ observer = null
99
+
100
+ try {
101
+ // 若用户传入 scrollSelector,则使用 relativeTo(container)
102
+ const ins = instance!
103
+ const io = uni.createIntersectionObserver(ins, {
104
+ thresholds: [0, 1]
105
+ })
106
+
107
+ if (props.scrollSelector) {
108
+ // 使用相对容器(scroll-view)
109
+ io.relativeTo(`.${props.scrollSelector}`, { top: props.offsetTop })
110
+ } else {
111
+ // 使用视口
112
+ io.relativeToViewport({ top: -props.offsetTop })
113
+ }
114
+
115
+ io.observe(`#${sentinelId}`, (res) => {
116
+ const fixed = res.boundingClientRect.top <= props.offsetTop
117
+ if (fixed !== isFixed.value) {
118
+ // 当切换为 fixed,记录占位高度
119
+ if (fixed) {
120
+ // 获取 sticky 高度作为占位
121
+ getRect('.hy-sticky', false, instance).then((rect) => {
122
+ placeholderHeight.value = rect?.height ? rect.height : 0
123
+ })
124
+ } else {
125
+ placeholderHeight.value = 0
126
+ }
127
+ isFixed.value = fixed
128
+ emit('change', fixed)
129
+ }
130
+ })
131
+
132
+ observer = io
133
+ } catch (e) {
134
+ // createIntersectionObserver 在极少数平台可能抛错,交给回退逻辑
135
+ observer = null
136
+ }
137
+ }
138
+
139
+ const pageScrollHandler = () => {
140
+ if (rafTimer) return
141
+ rafTimer = requestAnimationFrame(async () => {
142
+ rafTimer = 0
143
+
144
+ const { sentinelBottom, stickyHeight } = await querySentinel()
145
+ const offset = props.offsetTop
146
+
147
+ // 用 bottom 判断,保证吸顶时位置保持 offset
148
+ const fixed = sentinelBottom <= offset
149
+
150
+ if (fixed !== isFixed.value) {
151
+ isFixed.value = fixed
152
+
153
+ if (fixed) {
154
+ placeholderHeight.value = stickyHeight
155
+ } else {
156
+ placeholderHeight.value = 0
157
+ }
158
+
159
+ emit('change', fixed)
160
+ }
161
+ })
162
+ }
163
+
164
+ const onPageScrollListener = (e: any) => {
165
+ // 仅当 enable 时才处理
166
+ if (!props.enable) return
167
+ // 如果我们已经有 observer 且工作正常,则可以不必依赖回退(但保留检查以防万一)
168
+ // 这里仍然执行 pageScrollHandler 以防 observer 未触发
169
+ pageScrollHandler()
170
+ }
171
+
172
+ // 供外部触发重置(比如内容加载高度变化)
173
+ const refresh = async () => {
174
+ await nextTick()
175
+ // 重新测高度
176
+ getRect('.hy-sticky', false, instance).then((rect) => {
177
+ placeholderHeight.value = rect?.height ? rect.height : 0
178
+ })
179
+ // 重新 init observer
180
+ await initObserver()
181
+ // 手动触发一次检测
182
+ pageScrollHandler()
183
+ }
184
+
185
+ onMounted(() => {
186
+ nextTick(async () => {
187
+ await initObserver()
188
+
189
+ // 始终绑定 page scroll 回退(能兼容大多数场景)
190
+ // 注意:如果页面使用 scroll-view(而非页面滚动),你应传入 scrollSelector 以使用 relativeTo(container)
191
+ onPageScroll && onPageScroll(onPageScrollListener)
192
+ })
193
+ })
194
+
195
+ onUnmounted(() => {
196
+ observer?.disconnect()
197
+ observer = null
198
+ // 解除 pageScroll 监听:uni-app 没有 onPageScroll.off,onPageScroll 是全局注册的,通常不需要解绑
199
+ // 但是我们清理 raf
200
+ if (rafTimer) cancelAnimationFrame(rafTimer)
201
+ })
202
+
203
+ // 如果 enable 改变,重置
204
+ watch(
205
+ () => props.enable,
206
+ (v) => {
207
+ if (v) {
208
+ refresh()
209
+ } else {
210
+ observer?.disconnect()
211
+ observer = null
212
+ isFixed.value = false
213
+ placeholderHeight.value = 0
214
+ }
215
+ }
216
+ )
217
+
218
+ defineExpose({
219
+ refresh
220
+ })
221
+ </script>
222
+
223
+ <style lang="scss" scoped>
224
+ @import './index.scss';
225
+ @import './index.scss';
226
+ </style>
@@ -0,0 +1,29 @@
1
+ @use "../../libs/css/theme" as *;
2
+ @use "../../libs/css/mixin.scss" as *;
3
+
4
+ @include b(sticky) {
5
+ width: 100%;
6
+ /* 默认 sticky(非 fixed)样式 */
7
+ position: -webkit-sticky;
8
+ position: sticky;
9
+ top: 0;
10
+ left: 0;
11
+ right: 0;
12
+ background: #fff;
13
+ box-sizing: border-box;
14
+
15
+ @include e(fixed) {
16
+ /* 在这里加过渡 */
17
+ transition:
18
+ box-shadow 0.18s ease,
19
+ transform 0.18s ease;
20
+ }
21
+
22
+ /* 哨兵样式:不可见但参与布局 */
23
+ @include e(sentinel) {
24
+ height: 1px;
25
+ opacity: 0;
26
+ pointer-events: none;
27
+ }
28
+
29
+ }
@@ -0,0 +1,24 @@
1
+ const stickyProps = {
2
+ /** 吸顶时距离顶部的偏移量(单位:px) */
3
+ zIndex: {
4
+ type: [String, Number],
5
+ default: 99
6
+ },
7
+ /** 吸顶时的层级 */
8
+ offsetTop: {
9
+ type: [String, Number],
10
+ default: 0
11
+ },
12
+ /** 是否启用吸顶功能 */
13
+ enable: {
14
+ type: Boolean,
15
+ default: true
16
+ },
17
+ /** 在scroll-view内使用时,指定scroll-view的类名(不含点) */
18
+ scrollSelector: {
19
+ type: String,
20
+ default: ''
21
+ }
22
+ }
23
+
24
+ export default stickyProps
@@ -0,0 +1,4 @@
1
+ export interface IStickyEmits {
2
+ /** 固定时候执行 */
3
+ (e: 'change', isFixed: boolean): void
4
+ }
@@ -1,57 +1,57 @@
1
- @use "../../libs/css/theme" as *;
2
- @use "../../libs/css/mixin.scss" as *;
3
-
4
- @include b(tabbar-group) {
5
- display: flex;
6
- align-items: center;
7
- flex-wrap: nowrap;
8
- position: relative;
9
- background: $hy-background--container;
10
- height: 100rpx;
11
-
12
- @include e(placeholder) {
13
- box-sizing: content-box;
14
- padding-bottom: constant(safe-area-inset-bottom);
15
- padding-bottom: env(safe-area-inset-bottom);
16
- height: 100rpx;
17
- }
18
-
19
- @include m(circle) {
20
- margin-left: $hy-border-margin-padding-lg;
21
- margin-right: $hy-border-margin-padding-lg;
22
- border-radius: $hy-border-radius-semicircle;
23
- box-shadow: $hy-box-shadow;
24
-
25
- @include is(fixed) {
26
- @include is(safe) {
27
- bottom: constant(safe-area-inset-bottom);
28
- bottom: env(safe-area-inset-bottom);
29
- }
30
- }
31
-
32
- }
33
-
34
- @include m(square) {
35
-
36
- @include is(fixed) {
37
- @include is(safe) {
38
- box-sizing: content-box;
39
- padding-bottom: constant(safe-area-inset-bottom);
40
- padding-bottom: env(safe-area-inset-bottom);
41
- }
42
- }
43
-
44
-
45
- @include is(border) {
46
- border-top: $hy-border-line;
47
- }
48
- }
49
-
50
- @include is(fixed) {
51
- position: fixed;
52
- left: 0;
53
- bottom: 0;
54
- right: 0;
55
- z-index: 500;
56
- }
1
+ @use "../../libs/css/theme" as *;
2
+ @use "../../libs/css/mixin.scss" as *;
3
+
4
+ @include b(tabbar-group) {
5
+ display: flex;
6
+ align-items: center;
7
+ flex-wrap: nowrap;
8
+ position: relative;
9
+ background: $hy-background--container;
10
+ height: 100rpx;
11
+
12
+ @include e(placeholder) {
13
+ box-sizing: content-box;
14
+ padding-bottom: constant(safe-area-inset-bottom);
15
+ padding-bottom: env(safe-area-inset-bottom);
16
+ height: 100rpx;
17
+ }
18
+
19
+ @include m(circle) {
20
+ margin-left: $hy-border-margin-padding-lg;
21
+ margin-right: $hy-border-margin-padding-lg;
22
+ border-radius: $hy-border-radius-semicircle;
23
+ box-shadow: $hy-box-shadow;
24
+
25
+ @include is(fixed) {
26
+ @include is(safe) {
27
+ bottom: constant(safe-area-inset-bottom);
28
+ bottom: env(safe-area-inset-bottom);
29
+ }
30
+ }
31
+
32
+ }
33
+
34
+ @include m(square) {
35
+
36
+ @include is(fixed) {
37
+ @include is(safe) {
38
+ box-sizing: content-box;
39
+ padding-bottom: constant(safe-area-inset-bottom);
40
+ padding-bottom: env(safe-area-inset-bottom);
41
+ }
42
+ }
43
+
44
+
45
+ @include is(border) {
46
+ border-top: $hy-border-line;
47
+ }
48
+ }
49
+
50
+ @include is(fixed) {
51
+ position: fixed;
52
+ left: 0;
53
+ bottom: 0;
54
+ right: 0;
55
+ z-index: 500;
56
+ }
57
57
  }
@@ -1,43 +1,43 @@
1
- @use "../../libs/css/theme" as *;
2
- @use "../../libs/css/mixin.scss" as *;
3
-
4
-
5
- @include b(tabbar-item) {
6
- flex: 1;
7
- text-align: center;
8
- text-decoration: none;
9
- height: 100%;
10
- display: flex;
11
- justify-content: center;
12
- align-items: center;
13
-
14
- @include e(body) {
15
- display: flex;
16
- align-items: center;
17
- flex-direction: column;
18
- line-height: 1;
19
- padding: 0;
20
- position: relative;
21
-
22
- :deep(){
23
- @include is(active) {
24
- color: $hy-primary;
25
- }
26
-
27
- @include is(inactive) {
28
- color: $hy-text-color--grey;
29
- }
30
- }
31
- }
32
-
33
-
34
- @include e(body-title) {
35
- font-size: $hy-font-size-sm;
36
- line-height: initial;
37
- }
38
-
39
- @include edeep(body-icon) {
40
- font-size: 40rpx;
41
- }
42
-
1
+ @use "../../libs/css/theme" as *;
2
+ @use "../../libs/css/mixin.scss" as *;
3
+
4
+
5
+ @include b(tabbar-item) {
6
+ flex: 1;
7
+ text-align: center;
8
+ text-decoration: none;
9
+ height: 100%;
10
+ display: flex;
11
+ justify-content: center;
12
+ align-items: center;
13
+
14
+ @include e(body) {
15
+ display: flex;
16
+ align-items: center;
17
+ flex-direction: column;
18
+ line-height: 1;
19
+ padding: 0;
20
+ position: relative;
21
+
22
+ :deep(){
23
+ @include is(active) {
24
+ color: $hy-primary;
25
+ }
26
+
27
+ @include is(inactive) {
28
+ color: $hy-text-color--grey;
29
+ }
30
+ }
31
+ }
32
+
33
+
34
+ @include e(body-title) {
35
+ font-size: $hy-font-size-sm;
36
+ line-height: initial;
37
+ }
38
+
39
+ @include edeep(body-icon) {
40
+ font-size: 40rpx;
41
+ }
42
+
43
43
  }
@@ -1,24 +1,24 @@
1
- const tabBarItemProps = {
2
- /** 图标 */
3
- icon: {
4
- type: String,
5
- default: ''
6
- },
7
- /** 标题 */
8
- title: {
9
- type: String,
10
- default: ''
11
- },
12
- /** 唯一标识 */
13
- name: {
14
- type: [String, Number],
15
- default: ''
16
- },
17
- /** 徽标显示值,当为徽标为点时候,必须要value设置true或者有值 */
18
- value: {
19
- type: [String, Number, Boolean],
20
- default: ''
21
- }
22
- }
23
-
24
- export default tabBarItemProps
1
+ const tabBarItemProps = {
2
+ /** 图标 */
3
+ icon: {
4
+ type: String,
5
+ default: ''
6
+ },
7
+ /** 标题 */
8
+ title: {
9
+ type: String,
10
+ default: ''
11
+ },
12
+ /** 唯一标识 */
13
+ name: {
14
+ type: [String, Number],
15
+ default: ''
16
+ },
17
+ /** 徽标显示值,当为徽标为点时候,必须要value设置true或者有值 */
18
+ value: {
19
+ type: [String, Number, Boolean],
20
+ default: ''
21
+ }
22
+ }
23
+
24
+ export default tabBarItemProps
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hy-app",
3
- "version": "0.5.6",
4
- "description": "fix: 单元格拆分",
3
+ "version": "0.5.7",
4
+ "description": "feat: 新增sticky组件",
5
5
  "main": "./index.ts",
6
6
  "private": false,
7
7
  "scripts": {},