hy-app 0.2.5 → 0.2.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/common/index.ts +2 -1
- package/common/shakeService.ts +62 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +184 -0
- package/components/hy-action-sheet/index.scss +123 -0
- package/components/hy-action-sheet/props.ts +18 -0
- package/components/hy-action-sheet/typing.d.ts +96 -0
- package/components/hy-button/hy-button.vue +1 -1
- package/components/hy-button/typing.d.ts +35 -31
- package/components/hy-cell/typing.d.ts +27 -24
- package/components/hy-empty/hy-empty.vue +30 -37
- package/components/hy-empty/icon.ts +78 -0
- package/components/hy-empty/index.scss +2 -1
- package/components/hy-empty/props.ts +10 -9
- package/components/hy-empty/typing.d.ts +39 -14
- package/components/hy-float-button/hy-float-button.vue +98 -10
- package/components/hy-float-button/props.ts +16 -14
- package/components/hy-float-button/typing.d.ts +34 -23
- package/components/hy-icon/hy-icon.vue +40 -42
- package/components/hy-icon/props.ts +17 -16
- package/components/hy-icon/typing.d.ts +24 -20
- package/components/hy-modal/hy-modal.vue +42 -54
- package/components/hy-modal/index.scss +56 -32
- package/components/hy-modal/props.ts +15 -14
- package/components/hy-modal/typing.d.ts +23 -17
- package/components/hy-popup/index.scss +2 -2
- package/components/hy-popup/props.ts +7 -7
- package/components/hy-popup/typing.d.ts +17 -17
- package/components/hy-signature/props.ts +14 -14
- package/components/hy-tooltip/index.scss +2 -2
- package/libs/css/_config.scss +5 -0
- package/libs/css/_function.scss +89 -0
- package/libs/css/mixin.scss +58 -21
- package/libs/css/vars.css +3 -1
- package/package.json +2 -2
- package/theme.scss +2 -1
- package/utils/inspect.ts +48 -40
- package/utils/utils.ts +170 -187
package/utils/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import Base64 from
|
|
2
|
-
import type { CSSProperties } from
|
|
3
|
-
import { isNumber } from
|
|
4
|
-
let base64: any = new Base64()
|
|
1
|
+
import Base64 from './base64'
|
|
2
|
+
import type { CSSProperties } from 'vue'
|
|
3
|
+
import { isNumber } from './index'
|
|
4
|
+
let base64: any = new Base64()
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 加密函数
|
|
@@ -9,7 +9,7 @@ let base64: any = new Base64();
|
|
|
9
9
|
* @return { string } 加密字符串
|
|
10
10
|
* */
|
|
11
11
|
function encryptData(data: Record<string, any> | string): string {
|
|
12
|
-
return base64.encode(JSON.stringify(data))
|
|
12
|
+
return base64.encode(JSON.stringify(data))
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -18,7 +18,7 @@ function encryptData(data: Record<string, any> | string): string {
|
|
|
18
18
|
* @returns { any | any[] } 解码的数据
|
|
19
19
|
* */
|
|
20
20
|
function decryptData(encryptedVal: string): Record<string, any> {
|
|
21
|
-
return JSON.parse(base64.decode(encryptedVal.toString()))
|
|
21
|
+
return JSON.parse(base64.decode(encryptedVal.toString()))
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -43,20 +43,17 @@ function decryptData(encryptedVal: string): Record<string, any> {
|
|
|
43
43
|
* @param {String} unit 添加的单位名 比如px
|
|
44
44
|
* @returns {String}
|
|
45
45
|
*/
|
|
46
|
-
const addUnit = (
|
|
47
|
-
value: string | number = "auto",
|
|
48
|
-
unit: string = "",
|
|
49
|
-
): string => {
|
|
46
|
+
const addUnit = (value: string | number = 'auto', unit: string = ''): string => {
|
|
50
47
|
if (!unit) {
|
|
51
|
-
unit =
|
|
48
|
+
unit = 'px'
|
|
52
49
|
}
|
|
53
|
-
if (unit ==
|
|
54
|
-
value = Number(value) * 2
|
|
50
|
+
if (unit == 'rpx' && isNumber(String(value))) {
|
|
51
|
+
value = Number(value) * 2
|
|
55
52
|
}
|
|
56
|
-
value = String(value)
|
|
53
|
+
value = String(value)
|
|
57
54
|
// 用内置验证规则中的number判断是否为数值
|
|
58
|
-
return isNumber(value) ? `${value}${unit}` : value
|
|
59
|
-
}
|
|
55
|
+
return isNumber(value) ? `${value}${unit}` : value
|
|
56
|
+
}
|
|
60
57
|
|
|
61
58
|
/**
|
|
62
59
|
* @description 日期的月或日补零操作
|
|
@@ -64,42 +61,42 @@ const addUnit = (
|
|
|
64
61
|
* @returns {String}
|
|
65
62
|
*/
|
|
66
63
|
const padZero = (value: string | number): string => {
|
|
67
|
-
return `00${value}`.slice(-2)
|
|
68
|
-
}
|
|
64
|
+
return `00${value}`.slice(-2)
|
|
65
|
+
}
|
|
69
66
|
|
|
70
67
|
/**
|
|
71
68
|
* @description 清空对象里面的值
|
|
72
69
|
* @param val 任意类型的值
|
|
73
70
|
* */
|
|
74
71
|
const clearVal = (val: any) => {
|
|
75
|
-
const type = typeof val
|
|
76
|
-
const isArray = val instanceof Array
|
|
72
|
+
const type = typeof val
|
|
73
|
+
const isArray = val instanceof Array
|
|
77
74
|
switch (type) {
|
|
78
|
-
case
|
|
79
|
-
return
|
|
80
|
-
case
|
|
81
|
-
return 0
|
|
82
|
-
case
|
|
83
|
-
return false
|
|
84
|
-
case
|
|
85
|
-
return null
|
|
86
|
-
case
|
|
87
|
-
if (!val) return null
|
|
75
|
+
case 'string':
|
|
76
|
+
return ''
|
|
77
|
+
case 'number':
|
|
78
|
+
return 0
|
|
79
|
+
case 'boolean':
|
|
80
|
+
return false
|
|
81
|
+
case 'undefined':
|
|
82
|
+
return null
|
|
83
|
+
case 'object':
|
|
84
|
+
if (!val) return null
|
|
88
85
|
if (isArray) {
|
|
89
86
|
val.map((item) => {
|
|
90
|
-
clearVal(item)
|
|
91
|
-
})
|
|
92
|
-
return val
|
|
87
|
+
clearVal(item)
|
|
88
|
+
})
|
|
89
|
+
return val
|
|
93
90
|
} else {
|
|
94
91
|
Object.keys(val).map((k) => {
|
|
95
|
-
val[k] = clearVal(val[k])
|
|
96
|
-
})
|
|
97
|
-
return val
|
|
92
|
+
val[k] = clearVal(val[k])
|
|
93
|
+
})
|
|
94
|
+
return val
|
|
98
95
|
}
|
|
99
96
|
default:
|
|
100
|
-
return
|
|
97
|
+
return ''
|
|
101
98
|
}
|
|
102
|
-
}
|
|
99
|
+
}
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
102
|
* 时间戳格式化
|
|
@@ -107,36 +104,30 @@ const clearVal = (val: any) => {
|
|
|
107
104
|
* @param fmt 例:yyyy-MM-dd HH:mm:ss / yyyy-MM-dd
|
|
108
105
|
* @return date 例:2023-12-09
|
|
109
106
|
*/
|
|
110
|
-
const formatTime = (
|
|
111
|
-
|
|
112
|
-
fmt: string = "yyyy-MM-dd HH:mm:ss",
|
|
113
|
-
): string => {
|
|
114
|
-
let date: any;
|
|
107
|
+
const formatTime = (timestamp: number | string, fmt: string = 'yyyy-MM-dd HH:mm:ss'): string => {
|
|
108
|
+
let date: any
|
|
115
109
|
if (timestamp) {
|
|
116
|
-
date = new Date(timestamp) ? new Date(timestamp) : timestamp
|
|
117
|
-
let ret
|
|
110
|
+
date = new Date(timestamp) ? new Date(timestamp) : timestamp
|
|
111
|
+
let ret
|
|
118
112
|
const opt: any = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
'y+': date.getFullYear().toString(), //年
|
|
114
|
+
'M+': (date.getMonth() + 1).toString(), //月
|
|
115
|
+
'd+': date.getDate().toString(), //日
|
|
116
|
+
'H+': date.getHours().toString(), //时
|
|
117
|
+
'm+': date.getMinutes().toString(), //分
|
|
118
|
+
's+': date.getSeconds().toString(), //秒
|
|
125
119
|
//如果有其他格式字符需求可以继续添加,必须转化为字符串
|
|
126
|
-
}
|
|
120
|
+
}
|
|
127
121
|
for (let k in opt) {
|
|
128
|
-
ret = new RegExp(
|
|
122
|
+
ret = new RegExp('(' + k + ')').exec(fmt)
|
|
129
123
|
if (ret) {
|
|
130
|
-
fmt = fmt.replace(
|
|
131
|
-
ret[1],
|
|
132
|
-
ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0"),
|
|
133
|
-
);
|
|
124
|
+
fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'))
|
|
134
125
|
}
|
|
135
126
|
}
|
|
136
|
-
return fmt
|
|
127
|
+
return fmt
|
|
137
128
|
}
|
|
138
|
-
return date
|
|
139
|
-
}
|
|
129
|
+
return date
|
|
130
|
+
}
|
|
140
131
|
|
|
141
132
|
/**
|
|
142
133
|
* @description 时间戳或年月日格式转为多久之前
|
|
@@ -148,56 +139,51 @@ const formatTime = (
|
|
|
148
139
|
*/
|
|
149
140
|
const formatTimeToString = (
|
|
150
141
|
timestamp: string | number,
|
|
151
|
-
format: string | boolean =
|
|
142
|
+
format: string | boolean = 'yyyy-mm-dd',
|
|
152
143
|
): string => {
|
|
153
|
-
const now = new Date()
|
|
154
|
-
const oneYear = new Date(now.getFullYear(), 0, 1).getTime()
|
|
144
|
+
const now = new Date()
|
|
145
|
+
const oneYear = new Date(now.getFullYear(), 0, 1).getTime() // 当年一月一号时间戳
|
|
155
146
|
|
|
156
|
-
if (timestamp == null) timestamp = Number(now)
|
|
157
|
-
timestamp =
|
|
158
|
-
typeof timestamp === "string"
|
|
159
|
-
? parseInt(timestamp)
|
|
160
|
-
: new Date(timestamp).getTime();
|
|
147
|
+
if (timestamp == null) timestamp = Number(now)
|
|
148
|
+
timestamp = typeof timestamp === 'string' ? parseInt(timestamp) : new Date(timestamp).getTime()
|
|
161
149
|
// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
|
|
162
|
-
if (timestamp.toString().length == 10) timestamp *= 1000
|
|
163
|
-
let timer = now.getTime() - timestamp
|
|
164
|
-
timer = parseInt(String(timer / 1000))
|
|
150
|
+
if (timestamp.toString().length == 10) timestamp *= 1000
|
|
151
|
+
let timer = now.getTime() - timestamp
|
|
152
|
+
timer = parseInt(String(timer / 1000))
|
|
165
153
|
// 如果小于5分钟,则返回"刚刚",其他以此类推
|
|
166
|
-
let tips =
|
|
154
|
+
let tips = ''
|
|
167
155
|
switch (true) {
|
|
168
156
|
case timer < 300:
|
|
169
|
-
tips =
|
|
170
|
-
break
|
|
157
|
+
tips = '刚刚'
|
|
158
|
+
break
|
|
171
159
|
case timer >= 300 && timer < 3600:
|
|
172
|
-
tips = `${parseInt(String(timer / 60))}
|
|
173
|
-
break
|
|
160
|
+
tips = `${parseInt(String(timer / 60))}分钟前`
|
|
161
|
+
break
|
|
174
162
|
case timer >= 3600 && timer < 86400:
|
|
175
|
-
tips = `${parseInt(String(timer / 3600))}
|
|
176
|
-
break
|
|
163
|
+
tips = `${parseInt(String(timer / 3600))}小时前`
|
|
164
|
+
break
|
|
177
165
|
case timer >= 86400 && timer < 2592000:
|
|
178
|
-
tips = `${parseInt(String(timer / 86400))}
|
|
179
|
-
break
|
|
166
|
+
tips = `${parseInt(String(timer / 86400))}天前`
|
|
167
|
+
break
|
|
180
168
|
default:
|
|
181
169
|
// 如果format为false,则无论什么时间戳,都显示xx之前
|
|
182
170
|
if (format === false) {
|
|
183
171
|
if (timer >= 2592000 && timer < 365 * 86400) {
|
|
184
|
-
tips = `${parseInt(String(timer / (86400 * 30)))}
|
|
172
|
+
tips = `${parseInt(String(timer / (86400 * 30)))}个月前`
|
|
185
173
|
} else {
|
|
186
|
-
tips = `${parseInt(String(timer / (86400 * 365)))}
|
|
174
|
+
tips = `${parseInt(String(timer / (86400 * 365)))}年前`
|
|
187
175
|
}
|
|
188
176
|
} else {
|
|
189
177
|
if (timestamp > oneYear) {
|
|
190
|
-
formatTime(timestamp,
|
|
178
|
+
formatTime(timestamp, 'MM-dd')
|
|
191
179
|
} else {
|
|
192
180
|
tips =
|
|
193
|
-
format === true
|
|
194
|
-
? formatTime(timestamp, "yyyy-MM-dd")
|
|
195
|
-
: formatTime(timestamp, format);
|
|
181
|
+
format === true ? formatTime(timestamp, 'yyyy-MM-dd') : formatTime(timestamp, format)
|
|
196
182
|
}
|
|
197
183
|
}
|
|
198
184
|
}
|
|
199
|
-
return tips
|
|
200
|
-
}
|
|
185
|
+
return tips
|
|
186
|
+
}
|
|
201
187
|
|
|
202
188
|
/**
|
|
203
189
|
* @description 本地图片转base64方法(兼容APP、H5、小程序)
|
|
@@ -209,61 +195,68 @@ const imageToBase64 = (path: string) => {
|
|
|
209
195
|
// #ifdef APP-PLUS
|
|
210
196
|
plus.io.resolveLocalFileSystemURL(path, (entry) => {
|
|
211
197
|
entry.file((file) => {
|
|
212
|
-
let fileReader = new plus.io.FileReader()
|
|
213
|
-
fileReader.readAsDataURL(file)
|
|
198
|
+
let fileReader = new plus.io.FileReader()
|
|
199
|
+
fileReader.readAsDataURL(file)
|
|
214
200
|
fileReader.onloadend = (evt) => {
|
|
215
|
-
let base64 = evt.target.result.split(
|
|
216
|
-
resolve(base64)
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
})
|
|
201
|
+
let base64 = evt.target.result.split(',')[1]
|
|
202
|
+
resolve(base64)
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
})
|
|
220
206
|
// #endif
|
|
221
207
|
// #ifdef H5
|
|
222
208
|
uni.request({
|
|
223
209
|
url: path,
|
|
224
|
-
responseType:
|
|
210
|
+
responseType: 'arraybuffer',
|
|
225
211
|
success: (res) => {
|
|
226
|
-
resolve(uni.arrayBufferToBase64(res.data))
|
|
212
|
+
resolve(uni.arrayBufferToBase64(res.data))
|
|
227
213
|
},
|
|
228
|
-
})
|
|
214
|
+
})
|
|
229
215
|
// #endif
|
|
230
216
|
// #ifdef MP-WEIXIN
|
|
231
217
|
uni.getFileSystemManager().readFile({
|
|
232
218
|
filePath: path,
|
|
233
|
-
encoding:
|
|
219
|
+
encoding: 'base64',
|
|
234
220
|
success: (res) => {
|
|
235
|
-
resolve(res.data)
|
|
221
|
+
resolve(res.data)
|
|
236
222
|
},
|
|
237
|
-
})
|
|
223
|
+
})
|
|
238
224
|
// #endif
|
|
239
|
-
})
|
|
240
|
-
}
|
|
225
|
+
})
|
|
226
|
+
}
|
|
241
227
|
|
|
242
228
|
/**
|
|
243
229
|
* 函数防抖:一段实现执行多次,只执行最后一次
|
|
244
230
|
* @param {void} fn 回调函数
|
|
245
|
-
* @param {number}
|
|
231
|
+
* @param {number} wait 节流时间
|
|
246
232
|
* @returns {void}
|
|
247
233
|
* @constructor
|
|
248
234
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
235
|
+
let timeout: ReturnType<typeof setTimeout> | null = null
|
|
236
|
+
function debounce<T extends (...args: any[]) => void>(
|
|
237
|
+
fn: T,
|
|
238
|
+
wait: number = 500,
|
|
239
|
+
immediate: boolean = false,
|
|
240
|
+
) {
|
|
241
|
+
// 清除定时器
|
|
242
|
+
if (timeout !== null) clearTimeout(timeout)
|
|
243
|
+
// 立即执行,此类情况一般用不到
|
|
244
|
+
if (immediate) {
|
|
245
|
+
const callNow = !timeout
|
|
246
|
+
timeout = setTimeout(() => {
|
|
247
|
+
timeout = null
|
|
248
|
+
}, wait)
|
|
249
|
+
if (callNow) typeof fn === 'function' && fn()
|
|
250
|
+
} else {
|
|
251
|
+
// 设置定时器,当最后一次操作后,timeout不会再被清除,所以在延时wait毫秒后执行func回调方法
|
|
252
|
+
timeout = setTimeout(() => {
|
|
253
|
+
typeof fn === 'function' && fn()
|
|
254
|
+
}, wait)
|
|
255
|
+
}
|
|
263
256
|
}
|
|
264
257
|
|
|
265
|
-
let timer
|
|
266
|
-
let flag: boolean | undefined
|
|
258
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
259
|
+
let flag: boolean | undefined
|
|
267
260
|
/**
|
|
268
261
|
* 函数节流: 一段时间执行一次
|
|
269
262
|
* @param {void} fn 回调函数
|
|
@@ -272,29 +265,25 @@ let flag: boolean | undefined;
|
|
|
272
265
|
* @returns {void}
|
|
273
266
|
* @constructor
|
|
274
267
|
*/
|
|
275
|
-
const throttle = (
|
|
276
|
-
fn: Function,
|
|
277
|
-
wait: number = 500,
|
|
278
|
-
immediate: boolean = true,
|
|
279
|
-
): void => {
|
|
268
|
+
const throttle = (fn: Function, wait: number = 500, immediate: boolean = true): void => {
|
|
280
269
|
if (immediate) {
|
|
281
270
|
if (!flag) {
|
|
282
|
-
flag = true
|
|
271
|
+
flag = true
|
|
283
272
|
// 如果是立即执行,则在wait毫秒内开始时执行
|
|
284
|
-
typeof fn ===
|
|
273
|
+
typeof fn === 'function' && fn()
|
|
285
274
|
timer = setTimeout(() => {
|
|
286
|
-
flag = false
|
|
287
|
-
}, wait)
|
|
275
|
+
flag = false
|
|
276
|
+
}, wait)
|
|
288
277
|
}
|
|
289
278
|
} else if (!flag) {
|
|
290
|
-
flag = true
|
|
279
|
+
flag = true
|
|
291
280
|
// 如果是非立即执行,则在wait毫秒内的结束处执行
|
|
292
281
|
timer = setTimeout(() => {
|
|
293
|
-
flag = false
|
|
294
|
-
typeof fn ===
|
|
295
|
-
}, wait)
|
|
282
|
+
flag = false
|
|
283
|
+
typeof fn === 'function' && fn()
|
|
284
|
+
}, wait)
|
|
296
285
|
}
|
|
297
|
-
}
|
|
286
|
+
}
|
|
298
287
|
|
|
299
288
|
/**
|
|
300
289
|
* 递归拷贝对象
|
|
@@ -302,19 +291,19 @@ const throttle = (
|
|
|
302
291
|
* @returns 深拷贝的数组和对象
|
|
303
292
|
* */
|
|
304
293
|
const deepClone = (source: any) => {
|
|
305
|
-
if (!source && typeof source !==
|
|
306
|
-
throw new Error(
|
|
294
|
+
if (!source && typeof source !== 'object') {
|
|
295
|
+
throw new Error('该值不存在或者不是个对象')
|
|
307
296
|
}
|
|
308
|
-
const targetObj: any = source.constructor === Array ? [] : {}
|
|
297
|
+
const targetObj: any = source.constructor === Array ? [] : {}
|
|
309
298
|
Object.keys(source).forEach((keys) => {
|
|
310
|
-
if (source[keys] && typeof source[keys] ===
|
|
311
|
-
targetObj[keys] = deepClone(source[keys])
|
|
299
|
+
if (source[keys] && typeof source[keys] === 'object') {
|
|
300
|
+
targetObj[keys] = deepClone(source[keys])
|
|
312
301
|
} else {
|
|
313
|
-
targetObj[keys] = source[keys]
|
|
302
|
+
targetObj[keys] = source[keys]
|
|
314
303
|
}
|
|
315
|
-
})
|
|
316
|
-
return targetObj
|
|
317
|
-
}
|
|
304
|
+
})
|
|
305
|
+
return targetObj
|
|
306
|
+
}
|
|
318
307
|
|
|
319
308
|
/**
|
|
320
309
|
* 字节转化(b/KB/MB/GB)单位
|
|
@@ -322,16 +311,16 @@ const deepClone = (source: any) => {
|
|
|
322
311
|
* @returns {string} 返回单位大小
|
|
323
312
|
* */
|
|
324
313
|
const bytesToSize = (bytes: number) => {
|
|
325
|
-
const sizes = [
|
|
314
|
+
const sizes = ['b', 'KB', 'MB', 'GB', 'TB']
|
|
326
315
|
if (bytes === 0) {
|
|
327
|
-
return
|
|
316
|
+
return '0b'
|
|
328
317
|
}
|
|
329
|
-
const i = Math.floor(Math.log(bytes) / Math.log(1024))
|
|
318
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024))
|
|
330
319
|
if (i === 0) {
|
|
331
|
-
return `${bytes}${sizes[i]}
|
|
320
|
+
return `${bytes}${sizes[i]}`
|
|
332
321
|
}
|
|
333
|
-
return `${(bytes / 1024 ** i).toFixed(1)}${sizes[i]}
|
|
334
|
-
}
|
|
322
|
+
return `${(bytes / 1024 ** i).toFixed(1)}${sizes[i]}`
|
|
323
|
+
}
|
|
335
324
|
|
|
336
325
|
/**
|
|
337
326
|
* @description 将对象转换为 URL 查询参数字符串
|
|
@@ -343,10 +332,10 @@ const objectToUrlParams = (params: Record<string, any>): string => {
|
|
|
343
332
|
.filter(([key, value]) => value !== undefined && value !== null) // 过滤掉值为 undefined 或 null 的项
|
|
344
333
|
.map(([key, value]) => {
|
|
345
334
|
// 对值进行编码以确保 URL 安全
|
|
346
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}
|
|
335
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
|
|
347
336
|
})
|
|
348
|
-
.join(
|
|
349
|
-
}
|
|
337
|
+
.join('&') // 使用 & 拼接所有参数
|
|
338
|
+
}
|
|
350
339
|
|
|
351
340
|
/**
|
|
352
341
|
* 获取 [min,max]的随机数
|
|
@@ -356,18 +345,16 @@ const objectToUrlParams = (params: Record<string, any>): string => {
|
|
|
356
345
|
* @returns {Number} string 随机数
|
|
357
346
|
*/
|
|
358
347
|
const random = (min: number | string, max: number | string): number => {
|
|
359
|
-
min = Number(min)
|
|
360
|
-
max = Number(max)
|
|
361
|
-
return Math.floor(Math.random() * (max - min + 1) + min) ?? 0
|
|
362
|
-
}
|
|
348
|
+
min = Number(min)
|
|
349
|
+
max = Number(max)
|
|
350
|
+
return Math.floor(Math.random() * (max - min + 1) + min) ?? 0
|
|
351
|
+
}
|
|
363
352
|
|
|
364
353
|
const range = (min = 0, max = 0, value = 0) => {
|
|
365
|
-
return Math.max(min, Math.min(max, Number(value)))
|
|
366
|
-
}
|
|
354
|
+
return Math.max(min, Math.min(max, Number(value)))
|
|
355
|
+
}
|
|
367
356
|
|
|
368
|
-
export type RectResultType<T extends boolean> = T extends true
|
|
369
|
-
? UniApp.NodeInfo[]
|
|
370
|
-
: UniApp.NodeInfo;
|
|
357
|
+
export type RectResultType<T extends boolean> = T extends true ? UniApp.NodeInfo[] : UniApp.NodeInfo
|
|
371
358
|
/**
|
|
372
359
|
* 查询节点信息
|
|
373
360
|
* 目前此方法在支付宝小程序中无法获取组件跟接点的尺寸,为支付宝的bug(2020-07-21)
|
|
@@ -384,31 +371,29 @@ const getRect = (
|
|
|
384
371
|
useFields?: boolean,
|
|
385
372
|
): Promise<RectResultType<T>> => {
|
|
386
373
|
return new Promise<RectResultType<T>>((resolve, reject) => {
|
|
387
|
-
let query: UniNamespace.SelectorQuery | null = null
|
|
374
|
+
let query: UniNamespace.SelectorQuery | null = null
|
|
388
375
|
// TODO: 在微信小程序里,因为utils文件里面获取不到instance值所以必须通过ins这个传过来
|
|
389
376
|
if (ins) {
|
|
390
|
-
query = uni.createSelectorQuery().in(ins)
|
|
377
|
+
query = uni.createSelectorQuery().in(ins)
|
|
391
378
|
} else {
|
|
392
|
-
query = uni.createSelectorQuery()
|
|
379
|
+
query = uni.createSelectorQuery()
|
|
393
380
|
}
|
|
394
|
-
const method = all ?
|
|
381
|
+
const method = all ? 'selectAll' : 'select'
|
|
395
382
|
|
|
396
383
|
const callback = (rect: UniApp.NodeInfo | UniApp.NodeInfo[]) => {
|
|
397
384
|
if (all && Array.isArray(rect) && rect.length > 0) {
|
|
398
|
-
resolve(rect as RectResultType<T>)
|
|
385
|
+
resolve(rect as RectResultType<T>)
|
|
399
386
|
} else if (!all && rect) {
|
|
400
|
-
resolve(rect as RectResultType<T>)
|
|
387
|
+
resolve(rect as RectResultType<T>)
|
|
401
388
|
} else {
|
|
402
|
-
reject(new Error(
|
|
389
|
+
reject(new Error('No nodes found'))
|
|
403
390
|
}
|
|
404
|
-
}
|
|
391
|
+
}
|
|
405
392
|
|
|
406
393
|
if (useFields) {
|
|
407
|
-
query[method](selector)
|
|
408
|
-
.fields({ size: true, node: true }, callback)
|
|
409
|
-
.exec();
|
|
394
|
+
query[method](selector).fields({ size: true, node: true }, callback).exec()
|
|
410
395
|
} else {
|
|
411
|
-
query[method](selector).boundingClientRect(callback).exec()
|
|
396
|
+
query[method](selector).boundingClientRect(callback).exec()
|
|
412
397
|
}
|
|
413
398
|
// // #ifdef MP-WEIXIN
|
|
414
399
|
// instance = ins;
|
|
@@ -428,8 +413,8 @@ const getRect = (
|
|
|
428
413
|
// })
|
|
429
414
|
// .exec();
|
|
430
415
|
// // #endif
|
|
431
|
-
})
|
|
432
|
-
}
|
|
416
|
+
})
|
|
417
|
+
}
|
|
433
418
|
|
|
434
419
|
/**
|
|
435
420
|
* @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.rpx2px进行转换
|
|
@@ -437,21 +422,19 @@ const getRect = (
|
|
|
437
422
|
* @param {boolean} unit
|
|
438
423
|
* @returns {number|string}
|
|
439
424
|
*/
|
|
440
|
-
function getPx(value: string | number, unit: true): string
|
|
441
|
-
function getPx(value: string | number, unit?: false): number
|
|
425
|
+
function getPx(value: string | number, unit: true): string
|
|
426
|
+
function getPx(value: string | number, unit?: false): number
|
|
442
427
|
function getPx(value: string | number, unit: boolean = false): string | number {
|
|
443
|
-
if (isNumber(value) || typeof value ===
|
|
444
|
-
return unit ? `${value}px` : Number(value)
|
|
428
|
+
if (isNumber(value) || typeof value === 'number') {
|
|
429
|
+
return unit ? `${value}px` : Number(value)
|
|
445
430
|
}
|
|
446
431
|
// 如果带有rpx,先取出其数值部分,再转为px值
|
|
447
432
|
if (/(rpx|upx)$/.test(value)) {
|
|
448
|
-
return unit
|
|
449
|
-
? `${uni.rpx2px(parseInt(value))}px`
|
|
450
|
-
: Number(uni.rpx2px(parseInt(value)));
|
|
433
|
+
return unit ? `${uni.rpx2px(parseInt(value))}px` : Number(uni.rpx2px(parseInt(value)))
|
|
451
434
|
} else if (/(px)$/.test(value)) {
|
|
452
|
-
return unit ? value : Number(value.replace(
|
|
435
|
+
return unit ? value : Number(value.replace('px', ''))
|
|
453
436
|
} else {
|
|
454
|
-
return unit ? `${parseInt(value)}px` : Number(value)
|
|
437
|
+
return unit ? `${parseInt(value)}px` : Number(value)
|
|
455
438
|
}
|
|
456
439
|
}
|
|
457
440
|
|
|
@@ -461,8 +444,8 @@ function getPx(value: string | number, unit: boolean = false): string | number {
|
|
|
461
444
|
const formatObject = (obj: CSSProperties) => {
|
|
462
445
|
return Object.entries(obj)
|
|
463
446
|
.map(([key, value]) => `${key.toUpperCase()}: ${value}`)
|
|
464
|
-
.join(
|
|
465
|
-
}
|
|
447
|
+
.join('; ')
|
|
448
|
+
}
|
|
466
449
|
|
|
467
450
|
export {
|
|
468
451
|
encryptData,
|
|
@@ -483,4 +466,4 @@ export {
|
|
|
483
466
|
getRect,
|
|
484
467
|
getPx,
|
|
485
468
|
formatObject,
|
|
486
|
-
}
|
|
469
|
+
}
|