hy-app 0.6.4 → 0.6.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.
Files changed (106) hide show
  1. package/attributes.json +1 -1
  2. package/components/hy-address-picker/hy-address-picker.vue +249 -249
  3. package/components/hy-address-picker/props.ts +103 -103
  4. package/components/hy-button/hy-button.vue +320 -289
  5. package/components/hy-button/props.ts +143 -143
  6. package/components/hy-button/typing.d.ts +43 -35
  7. package/components/hy-calendar/header.vue +58 -58
  8. package/components/hy-calendar/hy-calendar.vue +8 -6
  9. package/components/hy-calendar/month.vue +402 -402
  10. package/components/hy-calendar/props.ts +169 -169
  11. package/components/hy-calendar/typing.d.ts +47 -45
  12. package/components/hy-cell-item/hy-cell-item.vue +161 -161
  13. package/components/hy-cell-item/props.ts +59 -59
  14. package/components/hy-check-button/hy-check-button.vue +135 -135
  15. package/components/hy-code-input/hy-code-input.vue +231 -231
  16. package/components/hy-code-input/props.ts +90 -90
  17. package/components/hy-config-provider/hy-config-provider.vue +53 -53
  18. package/components/hy-config-provider/props.ts +30 -30
  19. package/components/hy-coupon/hy-coupon.vue +183 -183
  20. package/components/hy-coupon/props.ts +108 -108
  21. package/components/hy-datetime-picker/hy-datetime-picker.vue +41 -55
  22. package/components/hy-datetime-picker/props.ts +144 -144
  23. package/components/hy-datetime-picker/typing.d.ts +2 -0
  24. package/components/hy-divider/props.ts +83 -83
  25. package/components/hy-empty/icon.ts +72 -72
  26. package/components/hy-folding-panel/hy-folding-panel-group.vue +162 -162
  27. package/components/hy-form/hy-form.vue +220 -220
  28. package/components/hy-icon/hy-icon.vue +112 -112
  29. package/components/hy-index-bar/hy-index-bar.vue +185 -185
  30. package/components/hy-index-bar/index.scss +64 -64
  31. package/components/hy-index-bar/props.ts +94 -94
  32. package/components/hy-index-bar/typing.d.ts +36 -36
  33. package/components/hy-input/hy-input.vue +333 -333
  34. package/components/hy-input/props.ts +186 -186
  35. package/components/hy-modal/hy-modal.vue +211 -211
  36. package/components/hy-modal/props.ts +94 -94
  37. package/components/hy-modal/typing.d.ts +16 -16
  38. package/components/hy-notice-bar/hy-row-notice.vue +121 -121
  39. package/components/hy-notify/hy-notify.vue +174 -174
  40. package/components/hy-number-step/hy-number-step.vue +367 -367
  41. package/components/hy-overlay/hy-overlay.vue +61 -61
  42. package/components/hy-overlay/props.ts +38 -38
  43. package/components/hy-pagination/hy-pagination.vue +136 -136
  44. package/components/hy-pagination/props.ts +58 -58
  45. package/components/hy-parse/hy-parse.vue +550 -550
  46. package/components/hy-parse/node/node.vue +781 -781
  47. package/components/hy-parse/parser.js +1455 -1455
  48. package/components/hy-parse/props.ts +19 -19
  49. package/components/hy-parse/typing.d.ts +68 -68
  50. package/components/hy-picker/hy-picker.vue +435 -435
  51. package/components/hy-picker/props.ts +122 -122
  52. package/components/hy-picker/typing.d.ts +38 -38
  53. package/components/hy-qrcode/props.ts +72 -72
  54. package/components/hy-qrcode/qrcode.js.bak +1433 -1433
  55. package/components/hy-radio/props.ts +97 -97
  56. package/components/hy-read-more/props.ts +48 -48
  57. package/components/hy-search/props.ts +133 -133
  58. package/components/hy-signature/canvasHelper.ts +51 -51
  59. package/components/hy-signature/props.ts +121 -121
  60. package/components/hy-skeleton/hy-skeleton.vue +142 -142
  61. package/components/hy-skeleton/props.ts +46 -46
  62. package/components/hy-skeleton/typing.d.ts +31 -31
  63. package/components/hy-steps/hy-steps.vue +275 -275
  64. package/components/hy-steps/typing.d.ts +25 -25
  65. package/components/hy-swiper/hy-swiper.vue +3 -3
  66. package/components/hy-swiper/index.scss +5 -5
  67. package/components/hy-swiper/props.ts +0 -1
  68. package/components/hy-table/hy-table.vue +630 -630
  69. package/components/hy-table/props.ts +62 -62
  70. package/components/hy-table/typing.d.ts +29 -29
  71. package/components/hy-tabs/hy-tabs.vue +336 -335
  72. package/components/hy-tabs/props.ts +84 -77
  73. package/components/hy-tag/hy-tag.vue +173 -173
  74. package/components/hy-tag/props.ts +89 -89
  75. package/components/hy-text/hy-text.vue +237 -237
  76. package/components/hy-text/props.ts +115 -115
  77. package/components/hy-textarea/hy-textarea.vue +198 -198
  78. package/components/hy-toast/hy-toast.vue +200 -200
  79. package/components/hy-toast/props.ts +3 -3
  80. package/components/hy-transition/hy-transition.vue +157 -157
  81. package/components/hy-transition/props.ts +32 -32
  82. package/components/hy-upload/hy-upload.vue +384 -384
  83. package/components/hy-watermark/hy-watermark.vue +1058 -1058
  84. package/components/hy-watermark/props.ts +109 -109
  85. package/global.d.ts +94 -94
  86. package/libs/api/http.ts +119 -119
  87. package/libs/composables/index.ts +8 -8
  88. package/libs/composables/useMessage.ts +149 -149
  89. package/libs/composables/useToast.ts +45 -45
  90. package/libs/composables/useTranslate.ts +10 -10
  91. package/libs/css/_config.scss +5 -5
  92. package/libs/index.ts +8 -8
  93. package/libs/locale/index.ts +32 -32
  94. package/libs/locale/lang/en-US.ts +84 -84
  95. package/libs/locale/lang/zh-CN.ts +87 -87
  96. package/libs/typing/index.ts +2 -2
  97. package/libs/typing/modules/common.d.ts +139 -139
  98. package/libs/typing/modules/form.ts +176 -176
  99. package/libs/typing/modules/http.d.ts +19 -19
  100. package/libs/typing/modules/index.d.ts +12 -12
  101. package/libs/utils/inside.ts +340 -340
  102. package/libs/utils/inspect.ts +140 -140
  103. package/libs/utils/utils.ts +525 -525
  104. package/package.json +81 -81
  105. package/tags.json +1 -1
  106. package/web-types.json +1 -1
@@ -1,340 +1,340 @@
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
- * 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
- * 获取设备信息
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
- * 数字格式化
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
- * 默认的姓名脱敏规则
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
- }
337
-
338
- export function getByPath(obj: Record<string, any>, path: string): unknown {
339
- return path.split('.').reduce((o, k) => o?.[k], obj)
340
- }
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
+ * 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
+ * 获取设备信息
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
+ * 数字格式化
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
+ * 默认的姓名脱敏规则
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
+ }
337
+
338
+ export function getByPath(obj: Record<string, any>, path: string): unknown {
339
+ return path.split('.').reduce((o, k) => o?.[k], obj)
340
+ }