hy-app 0.5.11 → 0.5.13
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/components/hy-button/hy-button.vue +289 -275
- package/components/hy-button/index.scss +24 -1
- package/components/hy-button/props.ts +143 -135
- package/components/hy-button/typing.d.ts +35 -30
- package/components/hy-coupon/hy-coupon.vue +183 -172
- package/components/hy-coupon/index.scss +20 -23
- package/components/hy-coupon/props.ts +108 -103
- package/components/hy-form/hy-form.vue +220 -220
- package/components/hy-input/hy-input.vue +333 -333
- package/components/hy-input/index.scss +1 -2
- package/components/hy-input/props.ts +186 -186
- package/components/hy-notice-bar/hy-row-notice.vue +121 -121
- package/components/hy-parse/node/node.vue +619 -422
- package/components/hy-parse/parser.js +1253 -1060
- package/components/hy-table/hy-table.vue +579 -358
- package/components/hy-table/index.scss +134 -159
- package/components/hy-table/props.ts +62 -47
- package/components/hy-table/typing.d.ts +29 -34
- package/components/hy-tabs/hy-tabs.vue +335 -335
- package/components/hy-tag/index.scss +1 -0
- package/components/hy-text/hy-text.vue +237 -237
- package/components/hy-text/props.ts +115 -115
- package/components/hy-textarea/hy-textarea.vue +198 -197
- package/components/hy-textarea/index.scss +2 -3
- package/components/hy-toast/hy-toast.vue +190 -190
- package/libs/css/theme.scss +1 -0
- package/libs/css/vars.scss +2 -2
- package/libs/typing/modules/common.d.ts +139 -139
- package/libs/utils/inside.ts +336 -350
- package/package.json +2 -2
- package/web-types.json +1 -1
package/libs/utils/inside.ts
CHANGED
|
@@ -1,350 +1,336 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @param {
|
|
9
|
-
* @
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
let value = ''
|
|
338
|
-
if (name.length === 2) {
|
|
339
|
-
value = name.substring(0, 1) + '*'
|
|
340
|
-
} else if (name.length > 2) {
|
|
341
|
-
let char = ''
|
|
342
|
-
for (let i = 0, len = name.length - 2; i < len; i++) {
|
|
343
|
-
char += '*'
|
|
344
|
-
}
|
|
345
|
-
value = name.substring(0, 1) + char + name.substring(name.length - 1, name.length)
|
|
346
|
-
} else {
|
|
347
|
-
value = name
|
|
348
|
-
}
|
|
349
|
-
return value
|
|
350
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 生成bem规则类名
|
|
3
|
+
* 由于微信小程序,H5,nvue之间绑定class的差异,无法通过:class="[bem()]"的形式进行同用
|
|
4
|
+
* 故采用如下折中做法,最后返回的是数组(一般平台)或字符串(支付宝和字节跳动平台),类似['a', 'b', 'c']或'a b c'的形式
|
|
5
|
+
* @param {String} name 组件名称
|
|
6
|
+
* @param props
|
|
7
|
+
* @param {Array} fixed 一直会存在的类名
|
|
8
|
+
* @param {Array} change 会根据变量值为true或者false而出现或者隐藏的类名
|
|
9
|
+
* @returns {Array|string}
|
|
10
|
+
*/
|
|
11
|
+
export const bem = (
|
|
12
|
+
name: string,
|
|
13
|
+
props: Record<string, any>,
|
|
14
|
+
fixed: string[],
|
|
15
|
+
change?: string[]
|
|
16
|
+
): string | string[] => {
|
|
17
|
+
// 类名前缀
|
|
18
|
+
const prefix = `hy-${name}--`
|
|
19
|
+
const classes: Record<string, string | boolean> = {}
|
|
20
|
+
if (fixed) {
|
|
21
|
+
fixed.map((item: string) => {
|
|
22
|
+
// 这里的类名,会一直存在
|
|
23
|
+
classes[prefix + props[item]] = true
|
|
24
|
+
if (item === 'type' && props['plain']) {
|
|
25
|
+
classes[prefix + props[item] + '__plain'] = true
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
if (change) {
|
|
30
|
+
change.map((item: string) => {
|
|
31
|
+
// 这里的类名,会根据this[item]的值为true或者false,而进行添加或者移除某一个类
|
|
32
|
+
props[item] ? (classes[prefix + item] = props[item]) : delete classes[prefix + item]
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
return (
|
|
36
|
+
Object.keys(classes)
|
|
37
|
+
// 支付宝,头条小程序无法动态绑定一个数组类名,否则解析出来的结果会带有",",而导致失效
|
|
38
|
+
// #ifdef MP-ALIPAY || MP-TOUTIAO || MP-LARK
|
|
39
|
+
.join(' ')
|
|
40
|
+
// #endif
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @description error提示
|
|
46
|
+
* @param {*} err 错误内容
|
|
47
|
+
*/
|
|
48
|
+
export function error(err: string) {
|
|
49
|
+
// 开发环境才提示,生产环境不会提示
|
|
50
|
+
if (process.env.NODE_ENV === 'development') {
|
|
51
|
+
console.error(`华玥组件提示:${err}`)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 定时器同步执行,等待时间
|
|
57
|
+
* @param {Number} value 等待时间
|
|
58
|
+
*/
|
|
59
|
+
export const sleep = (value: number = 100) => {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
resolve(null)
|
|
63
|
+
}, value)
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {Number} len uuid的长度
|
|
69
|
+
* @param {Boolean} firstU 将返回的首字母置为"hy"
|
|
70
|
+
* @param {Number | Null} radix 生成uuid的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制
|
|
71
|
+
*/
|
|
72
|
+
export function guid(len: number = 32, firstU: boolean = true, radix: number | null = null) {
|
|
73
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
|
|
74
|
+
const uuid = []
|
|
75
|
+
radix = radix || chars.length
|
|
76
|
+
|
|
77
|
+
if (len) {
|
|
78
|
+
// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
|
|
79
|
+
for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)]
|
|
80
|
+
} else {
|
|
81
|
+
let r
|
|
82
|
+
// rfc4122标准要求返回的uuid中,某些位为固定的字符
|
|
83
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
|
|
84
|
+
uuid[14] = '4'
|
|
85
|
+
|
|
86
|
+
for (let i = 0; i < 36; i++) {
|
|
87
|
+
if (!uuid[i]) {
|
|
88
|
+
r = 0 | (Math.random() * 16)
|
|
89
|
+
uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class
|
|
94
|
+
if (firstU) {
|
|
95
|
+
uuid.shift()
|
|
96
|
+
return `hy${uuid.join('')}`
|
|
97
|
+
}
|
|
98
|
+
return uuid.join('')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @description 获取设备信息
|
|
103
|
+
* */
|
|
104
|
+
export const getWindowInfo = (): UniNamespace.GetWindowInfoResult => {
|
|
105
|
+
let ret: UniNamespace.GetWindowInfoResult
|
|
106
|
+
// #ifdef APP || H5
|
|
107
|
+
ret = uni.getWindowInfo()
|
|
108
|
+
// #endif
|
|
109
|
+
// #ifndef APP || H5
|
|
110
|
+
ret = uni.getSystemInfoSync()
|
|
111
|
+
// #endif
|
|
112
|
+
return ret
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function pickExclude(obj, keys) {
|
|
116
|
+
// 某些情况下,type可能会为
|
|
117
|
+
if (!['[object Object]', '[object File]'].includes(Object.prototype.toString.call(obj))) {
|
|
118
|
+
return {}
|
|
119
|
+
}
|
|
120
|
+
return Object.keys(obj).reduce((prev, key) => {
|
|
121
|
+
if (!keys.includes(key)) {
|
|
122
|
+
prev[key] = obj[key]
|
|
123
|
+
}
|
|
124
|
+
return prev
|
|
125
|
+
}, {})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function formatImage(res) {
|
|
129
|
+
return res.tempFiles.map((item) => ({
|
|
130
|
+
...pickExclude(item, ['path']),
|
|
131
|
+
type: 'image',
|
|
132
|
+
url: item.path,
|
|
133
|
+
thumb: item.path,
|
|
134
|
+
size: item.size,
|
|
135
|
+
// #ifdef H5
|
|
136
|
+
name: item.name,
|
|
137
|
+
file: item
|
|
138
|
+
// #endif
|
|
139
|
+
}))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function formatVideo(res) {
|
|
143
|
+
return [
|
|
144
|
+
{
|
|
145
|
+
...pickExclude(res, ['tempFilePath', 'thumbTempFilePath', 'errMsg']),
|
|
146
|
+
type: 'video',
|
|
147
|
+
url: res.tempFilePath,
|
|
148
|
+
thumb: res.thumbTempFilePath,
|
|
149
|
+
size: res.size,
|
|
150
|
+
// #ifdef H5
|
|
151
|
+
name: res.name,
|
|
152
|
+
file: res
|
|
153
|
+
// #endif
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function formatMedia(res) {
|
|
159
|
+
return res.tempFiles.map((item) => ({
|
|
160
|
+
...pickExclude(item, ['fileType', 'thumbTempFilePath', 'tempFilePath']),
|
|
161
|
+
type: res.type,
|
|
162
|
+
url: item.tempFilePath,
|
|
163
|
+
thumb: res.type === 'video' ? item.thumbTempFilePath : item.tempFilePath,
|
|
164
|
+
size: item.size,
|
|
165
|
+
// #ifdef H5
|
|
166
|
+
file: item
|
|
167
|
+
// #endif
|
|
168
|
+
}))
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function formatFile(res) {
|
|
172
|
+
return res.tempFiles.map((item) => ({
|
|
173
|
+
...pickExclude(item, ['path']),
|
|
174
|
+
url: item.path,
|
|
175
|
+
size: item.size,
|
|
176
|
+
// #ifdef H5
|
|
177
|
+
name: item.name,
|
|
178
|
+
type: item.type,
|
|
179
|
+
file: item
|
|
180
|
+
// #endif
|
|
181
|
+
}))
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function chooseFile({
|
|
185
|
+
accept,
|
|
186
|
+
multiple,
|
|
187
|
+
capture,
|
|
188
|
+
compressed,
|
|
189
|
+
maxDuration,
|
|
190
|
+
sizeType,
|
|
191
|
+
camera,
|
|
192
|
+
maxCount,
|
|
193
|
+
extension
|
|
194
|
+
}: any) {
|
|
195
|
+
return new Promise((resolve, reject) => {
|
|
196
|
+
switch (accept) {
|
|
197
|
+
case 'image':
|
|
198
|
+
uni.chooseImage({
|
|
199
|
+
count: multiple ? Math.min(maxCount, 9) : 1,
|
|
200
|
+
sourceType: capture,
|
|
201
|
+
sizeType,
|
|
202
|
+
success: (res) => resolve(formatImage(res)),
|
|
203
|
+
fail: reject
|
|
204
|
+
})
|
|
205
|
+
break
|
|
206
|
+
// #ifdef MP-WEIXIN
|
|
207
|
+
// 只有微信小程序才支持chooseMedia接口
|
|
208
|
+
case 'media':
|
|
209
|
+
wx.chooseMedia({
|
|
210
|
+
count: multiple ? Math.min(maxCount, 9) : 1,
|
|
211
|
+
sourceType: capture,
|
|
212
|
+
maxDuration,
|
|
213
|
+
sizeType,
|
|
214
|
+
camera,
|
|
215
|
+
success: (res) => resolve(formatMedia(res)),
|
|
216
|
+
fail: reject
|
|
217
|
+
})
|
|
218
|
+
break
|
|
219
|
+
// #endif
|
|
220
|
+
case 'video':
|
|
221
|
+
uni.chooseVideo({
|
|
222
|
+
sourceType: capture,
|
|
223
|
+
compressed,
|
|
224
|
+
maxDuration,
|
|
225
|
+
camera,
|
|
226
|
+
success: (res) => resolve(formatVideo(res)),
|
|
227
|
+
fail: reject
|
|
228
|
+
})
|
|
229
|
+
break
|
|
230
|
+
// #ifdef MP-WEIXIN || H5
|
|
231
|
+
// 只有微信小程序才支持chooseMessageFile接口
|
|
232
|
+
case 'file':
|
|
233
|
+
// #ifdef MP-WEIXIN
|
|
234
|
+
wx.chooseMessageFile({
|
|
235
|
+
count: multiple ? maxCount : 1,
|
|
236
|
+
type: accept,
|
|
237
|
+
success: (res) => resolve(formatFile(res)),
|
|
238
|
+
fail: reject
|
|
239
|
+
})
|
|
240
|
+
// #endif
|
|
241
|
+
// #ifdef H5
|
|
242
|
+
// 需要hx2.9.9以上才支持uni.chooseFile
|
|
243
|
+
let params = {
|
|
244
|
+
count: multiple ? maxCount : 1,
|
|
245
|
+
type: accept,
|
|
246
|
+
success: (res) => resolve(formatFile(res)),
|
|
247
|
+
fail: reject
|
|
248
|
+
}
|
|
249
|
+
if (extension.length && extension.length > 0) {
|
|
250
|
+
params.extension = extension
|
|
251
|
+
}
|
|
252
|
+
uni.chooseFile(params)
|
|
253
|
+
// #endif
|
|
254
|
+
break
|
|
255
|
+
// #endif
|
|
256
|
+
default:
|
|
257
|
+
// 此为保底选项,在accept不为上面任意一项的时候选取全部文件
|
|
258
|
+
// #ifdef MP-WEIXIN
|
|
259
|
+
wx.chooseMessageFile({
|
|
260
|
+
count: multiple ? maxCount : 1,
|
|
261
|
+
type: 'all',
|
|
262
|
+
success: (res) => resolve(formatFile(res)),
|
|
263
|
+
fail: reject
|
|
264
|
+
})
|
|
265
|
+
// #endif
|
|
266
|
+
// #ifdef H5
|
|
267
|
+
// 需要hx2.9.9以上才支持uni.chooseFile
|
|
268
|
+
let paramsFile = {
|
|
269
|
+
count: multiple ? maxCount : 1,
|
|
270
|
+
type: 'all',
|
|
271
|
+
success: (res) => resolve(formatFile(res)),
|
|
272
|
+
fail: reject
|
|
273
|
+
}
|
|
274
|
+
if (extension.length && extension.length > 0) {
|
|
275
|
+
paramsFile.extension = extension
|
|
276
|
+
}
|
|
277
|
+
uni.chooseFile(paramsFile)
|
|
278
|
+
// #endif
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @description 数字格式化
|
|
285
|
+
* @param {number|string} number 要格式化的数字
|
|
286
|
+
* @param {number} decimals 保留几位小数
|
|
287
|
+
* @param {string} decimalPoint 小数点符号
|
|
288
|
+
* @param {string} thousandsSeparator 千分位符号
|
|
289
|
+
* @returns {string} 格式化后的数字
|
|
290
|
+
*/
|
|
291
|
+
export function priceFormat(
|
|
292
|
+
number: string | number,
|
|
293
|
+
decimals: number = 0,
|
|
294
|
+
decimalPoint: string = '.',
|
|
295
|
+
thousandsSeparator: string = ','
|
|
296
|
+
) {
|
|
297
|
+
number = `${number}`.replace(/[^0-9+-Ee.]/g, '')
|
|
298
|
+
const n = !isFinite(+number) ? 0 : +number
|
|
299
|
+
const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals)
|
|
300
|
+
const sep = typeof thousandsSeparator === 'undefined' ? ',' : thousandsSeparator
|
|
301
|
+
const dec = typeof decimalPoint === 'undefined' ? '.' : decimalPoint
|
|
302
|
+
let s = ''
|
|
303
|
+
|
|
304
|
+
s = (prec ? n + '' : `${Math.round(n)}`).split('.')
|
|
305
|
+
const re = /(-?\d+)(\d{3})/
|
|
306
|
+
while (re.test(s[0])) {
|
|
307
|
+
s[0] = s[0].replace(re, `$1${sep}$2`)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if ((s[1] || '').length < prec) {
|
|
311
|
+
s[1] = s[1] || ''
|
|
312
|
+
s[1] += new Array(prec - s[1].length + 1).join('0')
|
|
313
|
+
}
|
|
314
|
+
return s.join(dec)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* @description 默认的姓名脱敏规则
|
|
319
|
+
* @param name 名字
|
|
320
|
+
* @return {string}
|
|
321
|
+
* */
|
|
322
|
+
export const formatName = (name: string): string => {
|
|
323
|
+
let value = ''
|
|
324
|
+
if (name.length === 2) {
|
|
325
|
+
value = name.substring(0, 1) + '*'
|
|
326
|
+
} else if (name.length > 2) {
|
|
327
|
+
let char = ''
|
|
328
|
+
for (let i = 0, len = name.length - 2; i < len; i++) {
|
|
329
|
+
char += '*'
|
|
330
|
+
}
|
|
331
|
+
value = name.substring(0, 1) + char + name.substring(name.length - 1, name.length)
|
|
332
|
+
} else {
|
|
333
|
+
value = name
|
|
334
|
+
}
|
|
335
|
+
return value
|
|
336
|
+
}
|