hy-app 0.1.1

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 (206) hide show
  1. package/README.md +42 -0
  2. package/api/http.ts +138 -0
  3. package/api/index.ts +1 -0
  4. package/common/index.ts +1 -0
  5. package/common/versionControl.ts +102 -0
  6. package/components/dialog/TheDialog.vue +128 -0
  7. package/components/dialog/index.ts +38 -0
  8. package/components/hy-address-picker/hy-address-picker.vue +262 -0
  9. package/components/hy-address-picker/props.ts +27 -0
  10. package/components/hy-address-picker/typing.d.ts +98 -0
  11. package/components/hy-avatar/hy-avatar.vue +217 -0
  12. package/components/hy-avatar/props.ts +20 -0
  13. package/components/hy-avatar/typing.d.ts +64 -0
  14. package/components/hy-back-top/hy-back-top.vue +71 -0
  15. package/components/hy-back-top/props.ts +23 -0
  16. package/components/hy-back-top/typing.d.ts +49 -0
  17. package/components/hy-badge/hy-badge.vue +155 -0
  18. package/components/hy-badge/props.ts +19 -0
  19. package/components/hy-badge/typing.d.ts +60 -0
  20. package/components/hy-button/hy-button.vue +394 -0
  21. package/components/hy-button/props.ts +36 -0
  22. package/components/hy-button/typing.d.ts +125 -0
  23. package/components/hy-card/hy-card.vue +198 -0
  24. package/components/hy-card/props.ts +29 -0
  25. package/components/hy-card/typing.d.ts +112 -0
  26. package/components/hy-cell/hy-cell.vue +268 -0
  27. package/components/hy-cell/props.ts +20 -0
  28. package/components/hy-cell/typing.d.ts +98 -0
  29. package/components/hy-check-button/hy-check-button.vue +71 -0
  30. package/components/hy-check-button/props.ts +20 -0
  31. package/components/hy-check-button/typing.d.ts +79 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +299 -0
  33. package/components/hy-checkbox/props.ts +28 -0
  34. package/components/hy-checkbox/typing.d.ts +77 -0
  35. package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
  36. package/components/hy-datetime-picker/props.ts +36 -0
  37. package/components/hy-datetime-picker/typing.d.ts +135 -0
  38. package/components/hy-divider/hy-divider.vue +164 -0
  39. package/components/hy-divider/props.ts +21 -0
  40. package/components/hy-divider/typing.d.ts +64 -0
  41. package/components/hy-empty/hy-empty.vue +122 -0
  42. package/components/hy-empty/props.ts +21 -0
  43. package/components/hy-empty/typing.d.ts +68 -0
  44. package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
  45. package/components/hy-folding-panel/props.ts +17 -0
  46. package/components/hy-folding-panel/typing.d.ts +59 -0
  47. package/components/hy-form/hy-form.vue +372 -0
  48. package/components/hy-form/props.ts +15 -0
  49. package/components/hy-form/typing.d.ts +51 -0
  50. package/components/hy-grid/hy-grid.vue +126 -0
  51. package/components/hy-grid/props.ts +16 -0
  52. package/components/hy-grid/typing.d.ts +62 -0
  53. package/components/hy-icon/hy-icon.vue +207 -0
  54. package/components/hy-icon/props.ts +24 -0
  55. package/components/hy-icon/typing.d.ts +80 -0
  56. package/components/hy-input/hy-input.vue +402 -0
  57. package/components/hy-input/props.ts +41 -0
  58. package/components/hy-input/typing.d.ts +148 -0
  59. package/components/hy-line/hy-line.vue +44 -0
  60. package/components/hy-line/props.ts +12 -0
  61. package/components/hy-line/typing.d.ts +32 -0
  62. package/components/hy-line-progress/hy-line-progress.vue +118 -0
  63. package/components/hy-line-progress/props.ts +12 -0
  64. package/components/hy-line-progress/typing.d.ts +28 -0
  65. package/components/hy-list/hy-list.vue +250 -0
  66. package/components/hy-list/props.ts +18 -0
  67. package/components/hy-list/typing.d.ts +50 -0
  68. package/components/hy-login/ThePhoneLogin.vue +106 -0
  69. package/components/hy-login/TheUserLogin.vue +391 -0
  70. package/components/hy-login/hy-login.vue +283 -0
  71. package/components/hy-login/props.ts +32 -0
  72. package/components/hy-login/typing.d.ts +60 -0
  73. package/components/hy-modal/hy-modal.vue +240 -0
  74. package/components/hy-modal/props.ts +24 -0
  75. package/components/hy-modal/typing.d.ts +70 -0
  76. package/components/hy-navbar/hy-navbar.vue +194 -0
  77. package/components/hy-navbar/props.ts +24 -0
  78. package/components/hy-navbar/typing.d.ts +81 -0
  79. package/components/hy-notice-bar/hy-column-notice.vue +130 -0
  80. package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
  81. package/components/hy-notice-bar/hy-row-notice.vue +182 -0
  82. package/components/hy-notice-bar/props.ts +19 -0
  83. package/components/hy-notice-bar/typing.d.ts +56 -0
  84. package/components/hy-number-step/hy-number-step.vue +428 -0
  85. package/components/hy-number-step/props.ts +29 -0
  86. package/components/hy-number-step/typing.d.ts +104 -0
  87. package/components/hy-overlay/hy-overlay.vue +54 -0
  88. package/components/hy-overlay/props.ts +10 -0
  89. package/components/hy-overlay/typing.d.ts +24 -0
  90. package/components/hy-picker/hy-picker.vue +499 -0
  91. package/components/hy-picker/props.ts +30 -0
  92. package/components/hy-picker/typing.d.ts +115 -0
  93. package/components/hy-popup/hy-popup.vue +269 -0
  94. package/components/hy-popup/props.ts +21 -0
  95. package/components/hy-popup/typing.d.ts +68 -0
  96. package/components/hy-price/hy-price.vue +86 -0
  97. package/components/hy-price/props.ts +13 -0
  98. package/components/hy-price/typing.d.ts +36 -0
  99. package/components/hy-qrcode/hy-qrcode.vue +153 -0
  100. package/components/hy-qrcode/props.ts +20 -0
  101. package/components/hy-qrcode/qrcode.js +1364 -0
  102. package/components/hy-qrcode/typing.d.ts +64 -0
  103. package/components/hy-radio/hy-radio.vue +319 -0
  104. package/components/hy-radio/props.ts +28 -0
  105. package/components/hy-radio/typing.d.ts +85 -0
  106. package/components/hy-rate/hy-rate.vue +261 -0
  107. package/components/hy-rate/props.ts +18 -0
  108. package/components/hy-rate/typing.d.ts +60 -0
  109. package/components/hy-read-more/hy-read-more.vue +134 -0
  110. package/components/hy-read-more/props.ts +20 -0
  111. package/components/hy-read-more/typing.d.ts +44 -0
  112. package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
  113. package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
  114. package/components/hy-scroll-list/props.ts +12 -0
  115. package/components/hy-scroll-list/typing.d.ts +28 -0
  116. package/components/hy-search/hy-search.vue +294 -0
  117. package/components/hy-search/props.ts +29 -0
  118. package/components/hy-search/typing.d.ts +109 -0
  119. package/components/hy-slider/hy-slider.vue +511 -0
  120. package/components/hy-slider/props.ts +21 -0
  121. package/components/hy-slider/typing.d.ts +68 -0
  122. package/components/hy-steps/hy-steps.vue +352 -0
  123. package/components/hy-steps/props.ts +15 -0
  124. package/components/hy-steps/typing.d.ts +58 -0
  125. package/components/hy-subsection/hy-subsection.vue +272 -0
  126. package/components/hy-subsection/props.ts +16 -0
  127. package/components/hy-subsection/typing.d.ts +44 -0
  128. package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
  129. package/components/hy-swiper/hy-swiper.vue +242 -0
  130. package/components/hy-swiper/props.ts +30 -0
  131. package/components/hy-swiper/typing.d.ts +107 -0
  132. package/components/hy-switch/hy-switch.vue +168 -0
  133. package/components/hy-switch/props.ts +16 -0
  134. package/components/hy-switch/typing.d.ts +48 -0
  135. package/components/hy-tabs/hy-tabs.vue +416 -0
  136. package/components/hy-tabs/props.ts +26 -0
  137. package/components/hy-tabs/typing.d.ts +86 -0
  138. package/components/hy-tag/hy-tag.vue +374 -0
  139. package/components/hy-tag/props.ts +22 -0
  140. package/components/hy-tag/typing.d.ts +76 -0
  141. package/components/hy-textarea/hy-textarea.vue +229 -0
  142. package/components/hy-textarea/props.ts +26 -0
  143. package/components/hy-textarea/typing.d.ts +27 -0
  144. package/components/hy-tooltip/hy-tooltip.vue +332 -0
  145. package/components/hy-tooltip/props.ts +17 -0
  146. package/components/hy-tooltip/typing.d.ts +52 -0
  147. package/components/hy-transition/hy-transition.vue +150 -0
  148. package/components/hy-transition/index.scss +113 -0
  149. package/components/hy-transition/props.ts +10 -0
  150. package/components/hy-transition/typing.d.ts +36 -0
  151. package/components/hy-upload/hy-upload.vue +557 -0
  152. package/components/hy-upload/props.ts +29 -0
  153. package/components/hy-upload/typing.d.ts +147 -0
  154. package/components/hy-warn/hy-warn.vue +228 -0
  155. package/components/hy-warn/props.ts +14 -0
  156. package/components/hy-warn/typing.d.ts +40 -0
  157. package/components/hy-waterfall/hy-waterfall.vue +51 -0
  158. package/components/hy-waterfall/props.ts +10 -0
  159. package/components/hy-waterfall/typing.d.ts +20 -0
  160. package/components/index.ts +162 -0
  161. package/components/message/TheMessage.vue +169 -0
  162. package/components/message/index.ts +54 -0
  163. package/components/u-form/form.js +22 -0
  164. package/components/u-form/hy-form.vue +324 -0
  165. package/components/u-form/props.js +49 -0
  166. package/components/u-form/schema.js +1451 -0
  167. package/components/u-form/u-form.vue +267 -0
  168. package/components/u-form/utils.js +65 -0
  169. package/components/u-form-item/formItem.js +24 -0
  170. package/components/u-form-item/hy-form-item.vue +360 -0
  171. package/components/u-form-item/props.js +57 -0
  172. package/components/u-form-item/u-form-item.vue +294 -0
  173. package/components/yk-dialog/yk-dialog.vue +129 -0
  174. package/components/yk-tabbar/props.ts +49 -0
  175. package/components/yk-tabbar/yk-tabbar.vue +224 -0
  176. package/config/color.ts +6 -0
  177. package/config/icon.ts +366 -0
  178. package/config/index.ts +2 -0
  179. package/global/index.ts +6 -0
  180. package/global/register-properties.ts +37 -0
  181. package/index.ts +8 -0
  182. package/libs/css/common.scss +0 -0
  183. package/libs/css/iconfont.css +379 -0
  184. package/libs/css/iconfont.ttf +0 -0
  185. package/libs/css/mixin.scss +15 -0
  186. package/package.json +42 -0
  187. package/public/icons/error.png +0 -0
  188. package/public/icons/success.png +0 -0
  189. package/public/icons/warning.png +0 -0
  190. package/store/index.ts +1 -0
  191. package/store/userInfo.ts +25 -0
  192. package/theme.scss +94 -0
  193. package/typing/index.ts +7 -0
  194. package/typing/modules/common.d.ts +50 -0
  195. package/typing/modules/dialog.ts +17 -0
  196. package/typing/modules/enum.ts +67 -0
  197. package/typing/modules/form.ts +161 -0
  198. package/typing/modules/http.ts +68 -0
  199. package/typing/modules/icon.d.ts +366 -0
  200. package/typing/modules/img.ts +15 -0
  201. package/typing/modules/rect.ts +10 -0
  202. package/utils/address.json +5890 -0
  203. package/utils/base64.ts +119 -0
  204. package/utils/index.ts +3 -0
  205. package/utils/inside.ts +310 -0
  206. package/utils/utils.ts +446 -0
package/utils/utils.ts ADDED
@@ -0,0 +1,446 @@
1
+ import Base64 from "./base64";
2
+ import { CSSProperties } from "vue";
3
+ let base64: any = new Base64();
4
+
5
+ /**
6
+ * 加密函数
7
+ * @param {any} data 对象
8
+ * @return { string } 加密字符串
9
+ * */
10
+ function encryptData(data: Record<string, any> | string): string {
11
+ return base64.encode(JSON.stringify(data));
12
+ }
13
+
14
+ /**
15
+ * 解密函数
16
+ * @param {string} encryptedVal 加密字符串
17
+ * @returns { any | any[] } 解码的数据
18
+ * */
19
+ function decryptData(encryptedVal: string): Record<string, any> {
20
+ return JSON.parse(base64.decode(encryptedVal.toString()));
21
+ }
22
+
23
+ /**
24
+ *用于解密使用 AES 加密算法加密的数据
25
+ */
26
+
27
+ // const decrypt = (sessionKey: string, encryptedData: string, iv: string) => {
28
+ // console.log(CryptoJS)
29
+ // let key = CryptoJS.enc.Base64.parse(sessionKey)
30
+ // let ivv = CryptoJS.enc.Base64.parse(iv)
31
+ // let decrypt = CryptoJS.AES.decrypt(encryptedData, key, {
32
+ // iv: ivv,
33
+ // mode: CryptoJS.mode.CBC,
34
+ // padding: CryptoJS.pad.Pkcs7
35
+ // })
36
+ // return JSON.parse(base64.decode(CryptoJS.enc.Base64.stringify(decrypt)))
37
+ // }
38
+
39
+ /**
40
+ * @description 添加单位,如果有rpx,upx,%,px等单位结尾或者值为auto,直接返回,否则加上px单位结尾
41
+ * @param {String|Number} value 需要添加单位的值
42
+ * @param {String} unit 添加的单位名 比如px
43
+ * @returns {String}
44
+ */
45
+ const addUnit = (
46
+ value: string | number = "auto",
47
+ unit: string = ""
48
+ ): string => {
49
+ if (!unit) {
50
+ unit = "px";
51
+ }
52
+ if (unit == "rpx" && isNumber(String(value))) {
53
+ value = Number(value) * 2;
54
+ }
55
+ value = String(value);
56
+ // 用内置验证规则中的number判断是否为数值
57
+ return isNumber(value) ? `${value}${unit}` : value;
58
+ };
59
+ function isNumber(value: string) {
60
+ // 检查是否是数值类型或可以被解析为数值的字符串
61
+ return !isNaN(parseFloat(value)) && isFinite(Number(value));
62
+ }
63
+
64
+ /**
65
+ * @description 日期的月或日补零操作
66
+ * @param {String | Number} value 需要补零的值
67
+ * @returns {String}
68
+ */
69
+ const padZero = (value: string | number): string => {
70
+ return `00${value}`.slice(-2);
71
+ };
72
+
73
+ /**
74
+ * @description 清空对象里面的值
75
+ * @param val 任意类型的值
76
+ * */
77
+ const clearVal = (val: any) => {
78
+ const type = typeof val;
79
+ const isArray = val instanceof Array;
80
+ switch (type) {
81
+ case "string":
82
+ return "";
83
+ case "number":
84
+ return 0;
85
+ case "boolean":
86
+ return false;
87
+ case "undefined":
88
+ return null;
89
+ case "object":
90
+ if (!val) return null;
91
+ if (isArray) {
92
+ val.map((item) => {
93
+ clearVal(item);
94
+ });
95
+ return val;
96
+ } else {
97
+ Object.keys(val).map((k) => {
98
+ val[k] = clearVal(val[k]);
99
+ });
100
+ return val;
101
+ }
102
+ default:
103
+ return "";
104
+ }
105
+ };
106
+
107
+ /**
108
+ * 时间戳格式化
109
+ * @param timestamp 时间戳或者时间格式,例:1702051200000、Sat Apr 06 2024 11:35:56 GMT+0800 (中国标准时间)
110
+ * @param fmt 例:yyyy-MM-dd HH:mm:ss / yyyy-MM-dd
111
+ * @return date 例:2023-12-09
112
+ */
113
+ const formatTime = (
114
+ timestamp: number | string,
115
+ fmt: string = "yyyy-MM-dd HH:mm:ss"
116
+ ): string => {
117
+ let date: any;
118
+ if (timestamp) {
119
+ date = new Date(timestamp) ? new Date(timestamp) : timestamp;
120
+ let ret;
121
+ const opt: any = {
122
+ "y+": date.getFullYear().toString(), //年
123
+ "M+": (date.getMonth() + 1).toString(), //月
124
+ "d+": date.getDate().toString(), //日
125
+ "H+": date.getHours().toString(), //时
126
+ "m+": date.getMinutes().toString(), //分
127
+ "s+": date.getSeconds().toString() //秒
128
+ //如果有其他格式字符需求可以继续添加,必须转化为字符串
129
+ };
130
+ for (let k in opt) {
131
+ ret = new RegExp("(" + k + ")").exec(fmt);
132
+ if (ret) {
133
+ fmt = fmt.replace(
134
+ ret[1],
135
+ ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0")
136
+ );
137
+ }
138
+ }
139
+ return fmt;
140
+ }
141
+ return date;
142
+ };
143
+
144
+ /**
145
+ * @description 时间戳或年月日格式转为多久之前
146
+ * @param {String|Number} timestamp 时间戳/年月日格式
147
+ * @param {String|Boolean} format
148
+ * 格式化规则如果为时间格式字符串,超出一定时间范围,返回固定的时间格式;
149
+ * 如果为布尔值false,无论什么时间,都返回多久以前的格式
150
+ * @returns {string} 转化后的内容
151
+ */
152
+ const formatTimeToString = (
153
+ timestamp: string | number,
154
+ format: string | boolean = "yyyy-mm-dd"
155
+ ): string => {
156
+ const now = new Date();
157
+ const oneYear = new Date(now.getFullYear(), 0, 1).getTime(); // 当年一月一号时间戳
158
+
159
+ if (timestamp == null) timestamp = Number(now);
160
+ timestamp =
161
+ typeof timestamp === "string"
162
+ ? parseInt(timestamp)
163
+ : new Date(timestamp).getTime();
164
+ // 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
165
+ if (timestamp.toString().length == 10) timestamp *= 1000;
166
+ let timer = now.getTime() - timestamp;
167
+ timer = parseInt(String(timer / 1000));
168
+ // 如果小于5分钟,则返回"刚刚",其他以此类推
169
+ let tips = "";
170
+ switch (true) {
171
+ case timer < 300:
172
+ tips = "刚刚";
173
+ break;
174
+ case timer >= 300 && timer < 3600:
175
+ tips = `${parseInt(String(timer / 60))}分钟前`;
176
+ break;
177
+ case timer >= 3600 && timer < 86400:
178
+ tips = `${parseInt(String(timer / 3600))}小时前`;
179
+ break;
180
+ case timer >= 86400 && timer < 2592000:
181
+ tips = `${parseInt(String(timer / 86400))}天前`;
182
+ break;
183
+ default:
184
+ // 如果format为false,则无论什么时间戳,都显示xx之前
185
+ if (format === false) {
186
+ if (timer >= 2592000 && timer < 365 * 86400) {
187
+ tips = `${parseInt(String(timer / (86400 * 30)))}个月前`;
188
+ } else {
189
+ tips = `${parseInt(String(timer / (86400 * 365)))}年前`;
190
+ }
191
+ } else {
192
+ if (timestamp > oneYear) {
193
+ formatTime(timestamp, "MM-dd");
194
+ } else {
195
+ tips =
196
+ format === true
197
+ ? formatTime(timestamp, "yyyy-MM-dd")
198
+ : formatTime(timestamp, format);
199
+ }
200
+ }
201
+ }
202
+ return tips;
203
+ };
204
+
205
+ /**
206
+ * @description 本地图片转base64方法(兼容APP、H5、小程序)
207
+ * @param {string} path 图片本地路径
208
+ * @returns Promise对象
209
+ */
210
+ const imageToBase64 = (path: string) => {
211
+ return new Promise((resolve, reject) => {
212
+ // #ifdef APP-PLUS
213
+ plus.io.resolveLocalFileSystemURL(path, (entry) => {
214
+ entry.file((file) => {
215
+ let fileReader = new plus.io.FileReader();
216
+ fileReader.readAsDataURL(file);
217
+ fileReader.onloadend = (evt) => {
218
+ let base64 = evt.target.result.split(",")[1];
219
+ resolve(base64);
220
+ };
221
+ });
222
+ });
223
+ // #endif
224
+ // #ifdef H5
225
+ uni.request({
226
+ url: path,
227
+ responseType: "arraybuffer",
228
+ success: (res) => {
229
+ resolve(uni.arrayBufferToBase64(res.data));
230
+ }
231
+ });
232
+ // #endif
233
+ // #ifdef MP-WEIXIN
234
+ uni.getFileSystemManager().readFile({
235
+ filePath: path,
236
+ encoding: "base64",
237
+ success: (res) => {
238
+ resolve(res.data);
239
+ }
240
+ });
241
+ // #endif
242
+ });
243
+ };
244
+
245
+ /**
246
+ * 函数防抖:一段实现执行多次,只执行最后一次
247
+ * @param {void} fn 回调函数
248
+ * @param {number} t 节流时间
249
+ * @returns {void}
250
+ * @constructor
251
+ */
252
+ function debounce(fn: () => void, t?: number) {
253
+ const delay = t || 500;
254
+ let timer: any;
255
+ let that = this;
256
+ return function () {
257
+ const args = arguments;
258
+ if (timer) {
259
+ clearTimeout(timer);
260
+ }
261
+ timer = setTimeout(() => {
262
+ timer = null;
263
+ fn.apply(that, args);
264
+ }, delay);
265
+ };
266
+ }
267
+ /**
268
+ * 函数节流: 一段时间执行一次
269
+ * @param {void} fn 回调函数
270
+ * @param {number} t 节流时间
271
+ * @returns {void}
272
+ * @constructor
273
+ */
274
+ let timer;
275
+ let flag: boolean | undefined;
276
+ const throttle = (
277
+ func: Function,
278
+ wait: number = 500,
279
+ immediate: boolean = true
280
+ ): void => {
281
+ if (immediate) {
282
+ if (!flag) {
283
+ flag = true;
284
+ // 如果是立即执行,则在wait毫秒内开始时执行
285
+ typeof func === "function" && func();
286
+ timer = setTimeout(() => {
287
+ flag = false;
288
+ }, wait);
289
+ }
290
+ } else if (!flag) {
291
+ flag = true;
292
+ // 如果是非立即执行,则在wait毫秒内的结束处执行
293
+ timer = setTimeout(() => {
294
+ flag = false;
295
+ typeof func === "function" && func();
296
+ }, wait);
297
+ }
298
+ };
299
+
300
+ /**
301
+ * 递归拷贝对象
302
+ * @param {object} source 对象或数组
303
+ * @returns 深拷贝的数组和对象
304
+ * */
305
+ const deepClone = (source: any) => {
306
+ if (!source && typeof source !== "object") {
307
+ throw new Error("该值不存在或者不是个对象");
308
+ }
309
+ const targetObj: any = source.constructor === Array ? [] : {};
310
+ Object.keys(source).forEach((keys) => {
311
+ if (source[keys] && typeof source[keys] === "object") {
312
+ targetObj[keys] = deepClone(source[keys]);
313
+ } else {
314
+ targetObj[keys] = source[keys];
315
+ }
316
+ });
317
+ return targetObj;
318
+ };
319
+
320
+ /**
321
+ * 字节转化(b/KB/MB/GB)单位
322
+ * @param {number} bytes 字节
323
+ * @returns {string} 返回单位大小
324
+ * */
325
+ const bytesToSize = (bytes: number) => {
326
+ const sizes = ["b", "KB", "MB", "GB", "TB"];
327
+ if (bytes === 0) {
328
+ return "0b";
329
+ }
330
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
331
+ if (i === 0) {
332
+ return `${bytes}${sizes[i]}`;
333
+ }
334
+ return `${(bytes / 1024 ** i).toFixed(1)}${sizes[i]}`;
335
+ };
336
+
337
+ /**
338
+ * @description 将对象转换为 URL 查询参数字符串
339
+ * @param params - 要转换的对象
340
+ * @returns 转换后的查询参数字符串
341
+ */
342
+ const objectToUrlParams = (params: Record<string, any>): string => {
343
+ return Object.entries(params)
344
+ .filter(([key, value]) => value !== undefined && value !== null) // 过滤掉值为 undefined 或 null 的项
345
+ .map(([key, value]) => {
346
+ // 对值进行编码以确保 URL 安全
347
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
348
+ })
349
+ .join("&"); // 使用 & 拼接所有参数
350
+ };
351
+
352
+ /**
353
+ * 获取 [min,max]的随机数
354
+ * Math.floor(Math.random()*10) 可均衡获取 0 到 9 的随机整数
355
+ * @param min 最小值
356
+ * @param max 最大值
357
+ * @returns {Number} string 随机数
358
+ */
359
+ const random = (min: number | string, max: number | string): number => {
360
+ min = Number(min);
361
+ max = Number(max);
362
+ return Math.floor(Math.random() * (max - min + 1) + min) ?? 0;
363
+ };
364
+
365
+ const range = (min = 0, max = 0, value = 0) => {
366
+ return Math.max(min, Math.min(max, Number(value)));
367
+ };
368
+
369
+ /**
370
+ * 查询节点信息
371
+ * 目前此方法在支付宝小程序中无法获取组件跟接点的尺寸,为支付宝的bug(2020-07-21)
372
+ * 解决办法为在组件根部再套一个没有任何作用的view元素
373
+ */
374
+ const getRect = (
375
+ selector: string,
376
+ all?: boolean
377
+ ): Promise<UniApp.NodeInfo | UniApp.NodeInfo[]> => {
378
+ return new Promise((resolve) => {
379
+ // #ifndef APP-NVUE
380
+ uni
381
+ .createSelectorQuery()
382
+ .in(this)
383
+ [all ? "selectAll" : "select"](selector)
384
+ .boundingClientRect((rect) => {
385
+ if (all && Array.isArray(rect) && rect.length) {
386
+ resolve(rect as UniApp.NodeInfo[]);
387
+ }
388
+ if (!all && rect) {
389
+ resolve(rect as UniApp.NodeInfo);
390
+ }
391
+ })
392
+ .exec();
393
+ // #endif
394
+ });
395
+ };
396
+
397
+ /**
398
+ * @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.rpx2px进行转换
399
+ * @param {number|string} value 用户传递值的px值
400
+ * @param {boolean} unit
401
+ * @returns {number|string}
402
+ */
403
+ function getPx(value: string | number, unit: true): string;
404
+ function getPx(value: string | number, unit?: false): number;
405
+ function getPx(value: string | number, unit: boolean = false): string | number {
406
+ if (typeof value === "number") {
407
+ return unit ? `${value}px` : Number(value);
408
+ }
409
+ // 如果带有rpx,先取出其数值部分,再转为px值
410
+ if (/(rpx|upx)$/.test(value)) {
411
+ return unit
412
+ ? `${uni.rpx2px(parseInt(value))}px`
413
+ : Number(uni.rpx2px(parseInt(value)));
414
+ }
415
+ return unit ? `${parseInt(value)}px` : parseInt(value);
416
+ }
417
+
418
+ /**
419
+ * @description 对象转换字符串,用在于style样式上
420
+ * */
421
+ const formatObject = (obj: CSSProperties) => {
422
+ return Object.entries(obj)
423
+ .map(([key, value]) => `${key.toUpperCase()}: ${value}`)
424
+ .join("; ");
425
+ };
426
+
427
+ export {
428
+ encryptData,
429
+ decryptData,
430
+ addUnit,
431
+ padZero,
432
+ clearVal,
433
+ formatTime,
434
+ formatTimeToString,
435
+ imageToBase64,
436
+ debounce,
437
+ throttle,
438
+ deepClone,
439
+ bytesToSize,
440
+ objectToUrlParams,
441
+ random,
442
+ range,
443
+ getRect,
444
+ getPx,
445
+ formatObject
446
+ };