hy-app 0.7.2 → 0.7.3
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/README.md +17 -1
- package/components/hy-list/hy-list.vue +16 -2
- package/components/hy-modal/props.ts +1 -1
- package/components/hy-modal/typing.d.ts +52 -16
- package/components/hy-number-step/hy-number-step.vue +0 -2
- package/libs/common/versionControl.ts +5 -4
- package/package.json +1 -1
- package/libs/composables/useTouch.md +0 -237
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
## 在线使用文档地址
|
|
2
2
|
- [华玥组件库文档(需要翻墙)](https://hy-component-docs.vercel.app/)
|
|
3
|
-
- [华玥组件库文档(国内旧地址,2025-11-12之后域名过期)](https://www.gxh151.top)
|
|
4
3
|
- [华玥组件库文档(国内新地址)](https://www.hy-design-uni.top)
|
|
5
4
|
|
|
6
5
|
## 📱 移动端预览
|
|
@@ -43,8 +42,19 @@ export function createApp () {
|
|
|
43
42
|
</template>
|
|
44
43
|
```
|
|
45
44
|
|
|
45
|
+
## 让 Volar/VS Code 识别组件
|
|
46
|
+
```json
|
|
47
|
+
// tsconfig.json
|
|
48
|
+
{
|
|
49
|
+
"compilerOptions": {
|
|
50
|
+
"types": ["hy-app/global"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
46
55
|
## 在page.json文件里面配置按需引入组件
|
|
47
56
|
```json
|
|
57
|
+
// page.json文件
|
|
48
58
|
{
|
|
49
59
|
"easycom": {
|
|
50
60
|
"custom": {
|
|
@@ -53,3 +63,9 @@ export function createApp () {
|
|
|
53
63
|
}
|
|
54
64
|
}
|
|
55
65
|
```
|
|
66
|
+
|
|
67
|
+
## 全局导入组件库样式(修改 uni.scss)
|
|
68
|
+
```scss ./uni.scss
|
|
69
|
+
// uni.scss文件
|
|
70
|
+
@use "hy-app/index.scss" as *;
|
|
71
|
+
```
|
|
@@ -125,6 +125,20 @@ const heightCache = reactive<Record<number, number>>({})
|
|
|
125
125
|
// 预估高度(用于首屏渲染)
|
|
126
126
|
const estimatedHeight = computed(() => getPx(props.itemHeight) + getPx(props.marginBottom))
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* 节流函数(返回新函数版本)
|
|
130
|
+
*/
|
|
131
|
+
const throttleFn = <T extends (...args: any[]) => void>(fn: T, wait: number = 16): T => {
|
|
132
|
+
let lastTime = 0
|
|
133
|
+
return ((...args: any[]) => {
|
|
134
|
+
const now = Date.now()
|
|
135
|
+
if (now - lastTime >= wait) {
|
|
136
|
+
lastTime = now
|
|
137
|
+
fn(...args)
|
|
138
|
+
}
|
|
139
|
+
}) as T
|
|
140
|
+
}
|
|
141
|
+
|
|
128
142
|
onMounted(() => {
|
|
129
143
|
nextTick(async () => {
|
|
130
144
|
const res = await getRect('.hy-virtual-container', false, instance)
|
|
@@ -264,9 +278,9 @@ watch(
|
|
|
264
278
|
/**
|
|
265
279
|
* 监听滚动条距离顶部距离,实时更新(带节流)
|
|
266
280
|
*/
|
|
267
|
-
const onScroll =
|
|
281
|
+
const onScroll = throttleFn((e: any) => {
|
|
268
282
|
scrollTop.value = e.detail.scrollTop || 0
|
|
269
|
-
},
|
|
283
|
+
}, 16)
|
|
270
284
|
|
|
271
285
|
/**
|
|
272
286
|
* 滚动底部函数
|
|
@@ -1,16 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
export interface HyModalProps {
|
|
2
|
+
/** 是否显示模态框 */
|
|
3
|
+
modelValue: boolean
|
|
4
|
+
/** 标题内容 */
|
|
5
|
+
title?: string
|
|
6
|
+
/** 模态框内容 */
|
|
7
|
+
content?: string
|
|
8
|
+
/** 确认按钮的文字 */
|
|
9
|
+
confirmText?: string
|
|
10
|
+
/** 取消按钮的文字 */
|
|
11
|
+
cancelText?: string
|
|
12
|
+
/** 是否显示确认按钮 */
|
|
13
|
+
showConfirmButton?: boolean
|
|
14
|
+
/** 是否显示取消按钮 */
|
|
15
|
+
showCancelButton?: boolean
|
|
16
|
+
/** 确认按钮的颜色 */
|
|
17
|
+
confirmColor?: string
|
|
18
|
+
/** 取消按钮的颜色 */
|
|
19
|
+
cancelColor?: string
|
|
20
|
+
/** 对调确认和取消的位置 */
|
|
21
|
+
buttonReverse?: boolean
|
|
22
|
+
/** 是否开启缩放模式 */
|
|
23
|
+
zoom?: boolean
|
|
24
|
+
/** 弹窗的圆角 */
|
|
25
|
+
round?: string | number
|
|
26
|
+
/** 点击确认按钮自动关闭 */
|
|
27
|
+
autoClose?: boolean
|
|
28
|
+
/** 加载按钮 */
|
|
29
|
+
loading?: boolean
|
|
30
|
+
/** 是否允许点击遮罩关闭Modal */
|
|
31
|
+
closeOnClickOverlay?: boolean
|
|
32
|
+
/** 往上偏移的值 */
|
|
33
|
+
negativeTop?: number
|
|
34
|
+
/** modal宽度 */
|
|
35
|
+
width?: string | number
|
|
36
|
+
/** 确认按钮的样式 */
|
|
37
|
+
confirmButtonShape?: 'circle' | 'square'
|
|
38
|
+
/** 文案对齐方式 */
|
|
39
|
+
contentTextAlign?: 'left' | 'center' | 'right'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IModalEmits {
|
|
43
|
+
/** 点击确认按钮时触发 */
|
|
44
|
+
(e: 'confirm'): void
|
|
45
|
+
/** 点击取消按钮时触发 */
|
|
46
|
+
(e: 'cancel'): void
|
|
47
|
+
/** 点击遮罩关闭时触发 */
|
|
48
|
+
(e: 'close'): void
|
|
49
|
+
/** 更新值触发 */
|
|
50
|
+
(e: 'update:modelValue', show: boolean): void
|
|
51
|
+
(e: 'update:loading', show: boolean): void
|
|
52
|
+
}
|
|
@@ -175,7 +175,6 @@ const format = (value: number | string): number => {
|
|
|
175
175
|
// 对比最大最小值,取在min和max之间的值
|
|
176
176
|
value = Math.max(Math.min(props.max, value), props.min)
|
|
177
177
|
// 如果设定了最大的小数位数,使用toFixed去进行格式化
|
|
178
|
-
console.log(value, 111)
|
|
179
178
|
if (props.decimalLength !== null) {
|
|
180
179
|
value = parseFloat(value.toFixed(props.decimalLength))
|
|
181
180
|
}
|
|
@@ -197,7 +196,6 @@ watch(
|
|
|
197
196
|
if (newValue !== currentValue.value) {
|
|
198
197
|
currentValue.value = format(props.modelValue)
|
|
199
198
|
}
|
|
200
|
-
console.log(currentValue.value)
|
|
201
199
|
},
|
|
202
200
|
{ immediate: true }
|
|
203
201
|
)
|
|
@@ -107,11 +107,12 @@ export const appInit = {
|
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* 比较版本号
|
|
110
|
-
*
|
|
111
|
-
* 0:相等
|
|
112
|
-
* -1:本地版本大
|
|
113
|
-
* @param serverVersion 最新版本
|
|
110
|
+
* @param serverVersion 服务端版本
|
|
114
111
|
* @param localVersion 本地版本
|
|
112
|
+
* @returns
|
|
113
|
+
* 1: 服务端版本更高
|
|
114
|
+
* 0: 版本相同
|
|
115
|
+
* -1: 本地版本更高
|
|
115
116
|
*/
|
|
116
117
|
compareVersion(serverVersion: string, localVersion: string) {
|
|
117
118
|
if (!serverVersion || !localVersion) return 0
|
package/package.json
CHANGED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
# useTouch 触摸事件组合式 API
|
|
2
|
-
|
|
3
|
-
## 功能介绍
|
|
4
|
-
|
|
5
|
-
`useTouch` 是一个基于 Vue 3 Composition API 的触摸事件处理钩子,用于跟踪和分析用户的触摸操作,包括触摸方向、位移距离等信息。
|
|
6
|
-
|
|
7
|
-
- 支持跟踪触摸的水平和垂直方向
|
|
8
|
-
- 提供实时的位移数据
|
|
9
|
-
- 支持响应式状态管理
|
|
10
|
-
- 轻量简洁,易于集成
|
|
11
|
-
|
|
12
|
-
## 引入方式
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import { useTouch } from '@/package/libs/composables/useTouch'
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## API 文档
|
|
19
|
-
|
|
20
|
-
### useTouch()
|
|
21
|
-
|
|
22
|
-
创建并返回触摸事件处理实例,包含触摸事件处理函数和触摸状态。
|
|
23
|
-
|
|
24
|
-
**返回值**:包含以下属性的对象:
|
|
25
|
-
|
|
26
|
-
| 返回值 | 类型 | 说明 |
|
|
27
|
-
|--------|------|------|
|
|
28
|
-
| touchStart | (event: any) => void | 触摸开始事件处理函数 |
|
|
29
|
-
| touchMove | (event: any) => void | 触摸移动事件处理函数 |
|
|
30
|
-
| direction | Ref<string> | 触摸方向,值为 "horizontal"(水平)、"vertical"(垂直)或 ""(未确定) |
|
|
31
|
-
| deltaX | Ref<number> | 水平方向位移,正数表示向右,负数表示向左 |
|
|
32
|
-
| deltaY | Ref<number> | 垂直方向位移,正数表示向下,负数表示向上 |
|
|
33
|
-
| offsetX | Ref<number> | 水平方向位移的绝对值 |
|
|
34
|
-
| offsetY | Ref<number> | 垂直方向位移的绝对值 |
|
|
35
|
-
| startX | Ref<number> | 触摸开始时的 X 坐标 |
|
|
36
|
-
| startY | Ref<number> | 触摸开始时的 Y 坐标 |
|
|
37
|
-
|
|
38
|
-
## 使用示例
|
|
39
|
-
|
|
40
|
-
### 基础用法
|
|
41
|
-
|
|
42
|
-
```vue
|
|
43
|
-
<template>
|
|
44
|
-
<div
|
|
45
|
-
class="touch-area"
|
|
46
|
-
@touchstart="touchStart"
|
|
47
|
-
@touchmove="touchMove"
|
|
48
|
-
>
|
|
49
|
-
<div class="info">
|
|
50
|
-
<p>触摸方向: {{ direction }}</p>
|
|
51
|
-
<p>水平位移: {{ deltaX }}px</p>
|
|
52
|
-
<p>垂直位移: {{ deltaY }}px</p>
|
|
53
|
-
<p>水平偏移: {{ offsetX }}px</p>
|
|
54
|
-
<p>垂直偏移: {{ offsetY }}px</p>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
</template>
|
|
58
|
-
|
|
59
|
-
<script setup lang="ts">
|
|
60
|
-
import { useTouch } from '@/package/libs/composables/useTouch'
|
|
61
|
-
|
|
62
|
-
const {
|
|
63
|
-
touchStart,
|
|
64
|
-
touchMove,
|
|
65
|
-
direction,
|
|
66
|
-
deltaX,
|
|
67
|
-
deltaY,
|
|
68
|
-
offsetX,
|
|
69
|
-
offsetY
|
|
70
|
-
} = useTouch()
|
|
71
|
-
</script>
|
|
72
|
-
|
|
73
|
-
<style scoped>
|
|
74
|
-
.touch-area {
|
|
75
|
-
width: 100%;
|
|
76
|
-
height: 300px;
|
|
77
|
-
background-color: #f5f5f5;
|
|
78
|
-
display: flex;
|
|
79
|
-
align-items: center;
|
|
80
|
-
justify-content: center;
|
|
81
|
-
border-radius: 8px;
|
|
82
|
-
touch-action: none;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.info {
|
|
86
|
-
text-align: center;
|
|
87
|
-
font-size: 14px;
|
|
88
|
-
color: #333;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.info p {
|
|
92
|
-
margin: 8px 0;
|
|
93
|
-
}
|
|
94
|
-
</style>
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### 高级用法 - 实现滑动手势
|
|
98
|
-
|
|
99
|
-
```vue
|
|
100
|
-
<template>
|
|
101
|
-
<div
|
|
102
|
-
class="swipe-container"
|
|
103
|
-
@touchstart="touchStart"
|
|
104
|
-
@touchmove="touchMove"
|
|
105
|
-
@touchend="touchEnd"
|
|
106
|
-
>
|
|
107
|
-
<div
|
|
108
|
-
class="swipe-content"
|
|
109
|
-
:style="{
|
|
110
|
-
transform: `translateX(${swipeOffset}px)`
|
|
111
|
-
}"
|
|
112
|
-
>
|
|
113
|
-
滑动内容区域
|
|
114
|
-
</div>
|
|
115
|
-
</div>
|
|
116
|
-
</template>
|
|
117
|
-
|
|
118
|
-
<script setup lang="ts">
|
|
119
|
-
import { ref, computed } from 'vue'
|
|
120
|
-
import { useTouch } from '@/package/libs/composables/useTouch'
|
|
121
|
-
|
|
122
|
-
const {
|
|
123
|
-
touchStart,
|
|
124
|
-
touchMove,
|
|
125
|
-
direction,
|
|
126
|
-
deltaX
|
|
127
|
-
} = useTouch()
|
|
128
|
-
|
|
129
|
-
const swipeOffset = ref(0)
|
|
130
|
-
const maxSwipeOffset = 100
|
|
131
|
-
|
|
132
|
-
const touchEnd = () => {
|
|
133
|
-
if (direction.value === 'horizontal') {
|
|
134
|
-
if (deltaX.value > 50) {
|
|
135
|
-
// 向右滑动超过阈值
|
|
136
|
-
swipeOffset.value = maxSwipeOffset
|
|
137
|
-
} else if (deltaX.value < -50) {
|
|
138
|
-
// 向左滑动超过阈值
|
|
139
|
-
swipeOffset.value = -maxSwipeOffset
|
|
140
|
-
} else {
|
|
141
|
-
// 复位
|
|
142
|
-
swipeOffset.value = 0
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
</script>
|
|
147
|
-
|
|
148
|
-
<style scoped>
|
|
149
|
-
.swipe-container {
|
|
150
|
-
width: 100%;
|
|
151
|
-
height: 100px;
|
|
152
|
-
overflow: hidden;
|
|
153
|
-
position: relative;
|
|
154
|
-
background-color: #f5f5f5;
|
|
155
|
-
border-radius: 8px;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
.swipe-content {
|
|
159
|
-
width: 100%;
|
|
160
|
-
height: 100%;
|
|
161
|
-
background-color: #409eff;
|
|
162
|
-
color: white;
|
|
163
|
-
display: flex;
|
|
164
|
-
align-items: center;
|
|
165
|
-
justify-content: center;
|
|
166
|
-
transition: transform 0.3s ease;
|
|
167
|
-
}
|
|
168
|
-
</style>
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## 技术实现
|
|
172
|
-
|
|
173
|
-
### 核心原理
|
|
174
|
-
|
|
175
|
-
1. **响应式状态管理**:使用 Vue 3 的 `ref` 创建响应式变量,跟踪触摸状态
|
|
176
|
-
2. **触摸事件处理**:通过 `touchStart` 和 `touchMove` 函数处理触摸事件
|
|
177
|
-
3. **方向判断**:根据水平和垂直位移的绝对值大小判断触摸方向
|
|
178
|
-
4. **位移计算**:实时计算触摸点的位移距离和偏移量
|
|
179
|
-
|
|
180
|
-
### 关键函数
|
|
181
|
-
|
|
182
|
-
#### touchStart(event: any)
|
|
183
|
-
|
|
184
|
-
触摸开始时的事件处理函数,初始化所有状态变量。
|
|
185
|
-
|
|
186
|
-
- **参数**:`event` - 触摸事件对象
|
|
187
|
-
- **功能**:
|
|
188
|
-
- 获取第一个触摸点
|
|
189
|
-
- 重置方向和位移状态
|
|
190
|
-
- 记录触摸开始的坐标位置
|
|
191
|
-
|
|
192
|
-
#### touchMove(event: any)
|
|
193
|
-
|
|
194
|
-
触摸移动时的事件处理函数,计算位移和方向。
|
|
195
|
-
|
|
196
|
-
- **参数**:`event` - 触摸事件对象
|
|
197
|
-
- **功能**:
|
|
198
|
-
- 获取当前触摸点
|
|
199
|
-
- 计算水平和垂直方向的位移
|
|
200
|
-
- 计算位移的绝对值
|
|
201
|
-
- 根据位移绝对值判断触摸方向
|
|
202
|
-
|
|
203
|
-
## 返回值详解
|
|
204
|
-
|
|
205
|
-
| 返回值 | 类型 | 说明 |
|
|
206
|
-
|--------|------|------|
|
|
207
|
-
| touchStart | Function | 触摸开始事件处理函数,需绑定到元素的 @touchstart 事件 |
|
|
208
|
-
| touchMove | Function | 触摸移动事件处理函数,需绑定到元素的 @touchmove 事件 |
|
|
209
|
-
| direction | Ref<string> | 触摸方向,值为 "horizontal"(水平)、"vertical"(垂直)或 ""(未确定) |
|
|
210
|
-
| deltaX | Ref<number> | 水平方向位移,正数表示向右,负数表示向左 |
|
|
211
|
-
| deltaY | Ref<number> | 垂直方向位移,正数表示向下,负数表示向上 |
|
|
212
|
-
| offsetX | Ref<number> | 水平方向位移的绝对值 |
|
|
213
|
-
| offsetY | Ref<number> | 垂直方向位移的绝对值 |
|
|
214
|
-
| startX | Ref<number> | 触摸开始时的 X 坐标 |
|
|
215
|
-
| startY | Ref<number> | 触摸开始时的 Y 坐标 |
|
|
216
|
-
|
|
217
|
-
## 注意事项
|
|
218
|
-
|
|
219
|
-
1. **事件绑定**:需要在目标元素上同时绑定 `@touchstart` 和 `@touchmove` 事件
|
|
220
|
-
2. **触摸设备**:此钩子仅在支持触摸事件的设备上有效
|
|
221
|
-
3. **性能优化**:对于频繁的触摸移动事件,可以考虑使用 `passive` 事件监听器或节流处理
|
|
222
|
-
4. **浏览器兼容性**:不同浏览器对触摸事件的实现可能存在差异,建议在主要目标设备上进行测试
|
|
223
|
-
5. **事件对象类型**:当前实现中 `event` 参数类型为 `any`,在 TypeScript 项目中可以根据需要定义更具体的类型
|
|
224
|
-
|
|
225
|
-
## 应用场景
|
|
226
|
-
|
|
227
|
-
1. **滑动手势识别**:如左右滑动切换内容、上下滑动刷新等
|
|
228
|
-
2. **拖拽功能**:实现元素的拖拽移动
|
|
229
|
-
3. **手势密码**:辅助实现手势密码功能
|
|
230
|
-
4. **游戏控制**:用于游戏中的触摸控制
|
|
231
|
-
5. **交互式组件**:如滑块、滑动菜单等组件的实现
|
|
232
|
-
|
|
233
|
-
## 总结
|
|
234
|
-
|
|
235
|
-
`useTouch` 是一个轻量级的触摸事件处理钩子,提供了简单而强大的触摸状态跟踪功能。通过使用它,开发者可以轻松实现各种基于触摸的交互效果,提升应用的用户体验。
|
|
236
|
-
|
|
237
|
-
该钩子返回的响应式状态和事件处理函数可以与 Vue 3 的组合式 API 无缝集成,适用于各种需要触摸交互的场景。
|