my-uniapp-tools 1.0.4 → 1.0.6
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/package.json +1 -1
- package/src/index.js +2 -0
- package/src/system/index.ts +7 -7
- package/src/utils/index.ts +89 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
package/src/system/index.ts
CHANGED
|
@@ -149,12 +149,12 @@ export const getStatusBarHeight = () => {
|
|
|
149
149
|
export const getMenuButtonBoundingClientRect = () => {
|
|
150
150
|
try {
|
|
151
151
|
const platform = getPlatform();
|
|
152
|
-
|
|
152
|
+
|
|
153
153
|
// 只有在小程序平台才执行getMenuButtonBoundingClientRect
|
|
154
154
|
if (platform === 'weixin' || platform === 'alipay') {
|
|
155
155
|
return uni.getMenuButtonBoundingClientRect();
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
// 非小程序平台返回null
|
|
159
159
|
return null;
|
|
160
160
|
} catch (error) {
|
|
@@ -173,7 +173,7 @@ export const getNavHeight = () => {
|
|
|
173
173
|
// 获取状态栏高度
|
|
174
174
|
const statusBarHeight = getStatusBarHeight();
|
|
175
175
|
const platform = getPlatform();
|
|
176
|
-
|
|
176
|
+
|
|
177
177
|
// 小程序平台:状态栏高度 + 菜单按钮高度
|
|
178
178
|
if (platform === 'weixin' || platform === 'alipay') {
|
|
179
179
|
const menuButtonInfo = getMenuButtonBoundingClientRect();
|
|
@@ -183,17 +183,17 @@ export const getNavHeight = () => {
|
|
|
183
183
|
return navHeight;
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
// App和H5平台:使用默认导航栏高度
|
|
188
|
-
const defaultNavHeight =
|
|
188
|
+
const defaultNavHeight = 0; // 默认导航栏高度
|
|
189
189
|
const totalHeight = statusBarHeight + defaultNavHeight;
|
|
190
190
|
console.log(`🚀 ~ ${platform}平台导航栏高度:`, totalHeight);
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
return totalHeight;
|
|
193
193
|
} catch (error) {
|
|
194
194
|
console.error('获取导航栏高度失败:', error);
|
|
195
195
|
// 返回默认高度(状态栏高度 + 44px 默认导航栏高度)
|
|
196
|
-
return getStatusBarHeight() +
|
|
196
|
+
return getStatusBarHeight() + 0;
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具函数库
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 深拷贝对象
|
|
7
|
+
* @param target 目标对象,将被拷贝的内容覆盖
|
|
8
|
+
* @param source 源对象,被拷贝的对象
|
|
9
|
+
* @returns 返回深拷贝后的目标对象
|
|
10
|
+
* @description 支持对象、数组、基本数据类型的深度拷贝,处理循环引用问题
|
|
11
|
+
*/
|
|
12
|
+
export function useDeepCopyByObj<T>(target: T, source: any): T {
|
|
13
|
+
// 处理循环引用的WeakMap
|
|
14
|
+
const visited = new WeakMap();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 内部递归拷贝函数
|
|
18
|
+
* @param targetObj 目标对象
|
|
19
|
+
* @param sourceObj 源对象
|
|
20
|
+
* @returns 拷贝后的对象
|
|
21
|
+
*/
|
|
22
|
+
function copyRecursive(targetObj: any, sourceObj: any): any {
|
|
23
|
+
// 处理null和undefined
|
|
24
|
+
if (sourceObj === null || sourceObj === undefined) {
|
|
25
|
+
return sourceObj;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 处理基本数据类型
|
|
29
|
+
if (typeof sourceObj !== 'object') {
|
|
30
|
+
return sourceObj;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 处理循环引用
|
|
34
|
+
if (visited.has(sourceObj)) {
|
|
35
|
+
return visited.get(sourceObj);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 处理Date对象
|
|
39
|
+
if (sourceObj instanceof Date) {
|
|
40
|
+
return new Date(sourceObj.getTime());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 处理RegExp对象
|
|
44
|
+
if (sourceObj instanceof RegExp) {
|
|
45
|
+
return new RegExp(sourceObj.source, sourceObj.flags);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 处理数组
|
|
49
|
+
if (Array.isArray(sourceObj)) {
|
|
50
|
+
const result: any[] = [];
|
|
51
|
+
visited.set(sourceObj, result);
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < sourceObj.length; i++) {
|
|
54
|
+
result[i] = copyRecursive(undefined, sourceObj[i]);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 处理普通对象
|
|
60
|
+
const result: any = {};
|
|
61
|
+
visited.set(sourceObj, result);
|
|
62
|
+
|
|
63
|
+
// 拷贝所有可枚举属性
|
|
64
|
+
for (const key in sourceObj) {
|
|
65
|
+
if (sourceObj.hasOwnProperty(key)) {
|
|
66
|
+
result[key] = copyRecursive(undefined, sourceObj[key]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 如果target是对象类型,则将source的属性拷贝到target中
|
|
74
|
+
if (typeof target === 'object' && target !== null && !Array.isArray(target)) {
|
|
75
|
+
const copiedSource = copyRecursive(undefined, source);
|
|
76
|
+
|
|
77
|
+
// 将拷贝后的source属性合并到target中
|
|
78
|
+
for (const key in copiedSource) {
|
|
79
|
+
if (copiedSource.hasOwnProperty(key)) {
|
|
80
|
+
(target as any)[key] = copiedSource[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return target;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 如果target不是对象,则直接返回source的深拷贝
|
|
88
|
+
return copyRecursive(undefined, source) as T;
|
|
89
|
+
}
|