hy-app 0.1.2 → 0.1.4

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 (247) hide show
  1. package/README.md +1 -1
  2. package/api/http.ts +8 -8
  3. package/components/dialog/index.ts +2 -2
  4. package/components/hy-address-picker/hy-address-picker.vue +3 -29
  5. package/components/hy-address-picker/index.scss +27 -0
  6. package/components/hy-avatar/hy-avatar.vue +1 -45
  7. package/components/hy-avatar/index.scss +45 -0
  8. package/components/hy-avatar/typing.d.ts +1 -1
  9. package/components/hy-back-top/hy-back-top.vue +7 -22
  10. package/components/hy-back-top/index.scss +16 -0
  11. package/components/hy-back-top/props.ts +4 -4
  12. package/components/hy-back-top/typing.d.ts +2 -3
  13. package/components/hy-badge/hy-badge.vue +1 -72
  14. package/components/hy-badge/index.scss +72 -0
  15. package/components/hy-button/hy-button.vue +17 -128
  16. package/components/hy-button/index.scss +116 -0
  17. package/components/hy-button/typing.d.ts +1 -1
  18. package/components/hy-calendar/header.vue +76 -0
  19. package/components/hy-calendar/hy-calendar.vue +366 -0
  20. package/components/hy-calendar/index.scss +171 -0
  21. package/components/hy-calendar/month.vue +524 -0
  22. package/components/hy-calendar/props.ts +37 -0
  23. package/components/hy-calendar/typing.d.ts +126 -0
  24. package/components/hy-card/hy-card.vue +21 -84
  25. package/components/hy-card/index.scss +57 -0
  26. package/components/hy-card/props.ts +2 -2
  27. package/components/hy-card/typing.d.ts +1 -1
  28. package/components/hy-cell/hy-cell.vue +1 -137
  29. package/components/hy-cell/index.scss +137 -0
  30. package/components/hy-check-button/hy-check-button.vue +1 -0
  31. package/components/hy-check-button/index.scss +5 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +2 -95
  33. package/components/hy-checkbox/index.scss +94 -0
  34. package/components/hy-checkbox/typing.d.ts +1 -2
  35. package/components/hy-count-down/hy-count-down.vue +150 -0
  36. package/components/hy-count-down/index.scss +6 -0
  37. package/components/hy-count-down/index.ts +52 -0
  38. package/components/hy-count-down/props.ts +10 -0
  39. package/components/hy-count-down/typing.d.ts +20 -0
  40. package/components/hy-count-to/hy-count-to.vue +213 -0
  41. package/components/hy-count-to/index.scss +6 -0
  42. package/components/hy-count-to/props.ts +17 -0
  43. package/components/hy-count-to/typing.d.ts +48 -0
  44. package/components/hy-datetime-picker/hy-datetime-picker.vue +2 -28
  45. package/components/hy-datetime-picker/index.scss +28 -0
  46. package/components/hy-divider/hy-divider.vue +24 -49
  47. package/components/hy-divider/index.scss +26 -0
  48. package/components/hy-divider/props.ts +2 -2
  49. package/components/hy-divider/typing.d.ts +1 -1
  50. package/components/hy-dropdown/hy-dropdown.vue +43 -0
  51. package/components/hy-dropdown/index.scss +17 -0
  52. package/components/hy-dropdown/props.ts +17 -0
  53. package/components/hy-dropdown/typing.d.ts +48 -0
  54. package/components/hy-dropdown-item/hy-dropdown-item.vue +194 -0
  55. package/components/hy-dropdown-item/index.scss +96 -0
  56. package/components/hy-dropdown-item/props.ts +10 -0
  57. package/components/hy-dropdown-item/typing.d.ts +31 -0
  58. package/components/hy-empty/hy-empty.vue +8 -26
  59. package/components/hy-empty/index.scss +19 -0
  60. package/components/hy-empty/props.ts +2 -2
  61. package/components/hy-empty/typing.d.ts +1 -1
  62. package/components/hy-float-button/hy-float-button.vue +217 -0
  63. package/components/hy-float-button/index.scss +67 -0
  64. package/components/hy-float-button/props.ts +25 -0
  65. package/components/hy-float-button/typing.d.ts +93 -0
  66. package/components/hy-folding-panel/hy-folding-panel.vue +9 -12
  67. package/components/hy-folding-panel/index.scss +6 -0
  68. package/components/hy-folding-panel/props.ts +2 -2
  69. package/components/hy-folding-panel/typing.d.ts +2 -2
  70. package/components/hy-form/hy-form.vue +17 -34
  71. package/components/hy-form/index.scss +30 -0
  72. package/components/hy-form/props.ts +2 -0
  73. package/components/hy-form/typing.d.ts +9 -1
  74. package/components/hy-grid/hy-grid.vue +1 -43
  75. package/components/hy-grid/index.scss +40 -0
  76. package/components/hy-icon/hy-icon.vue +1 -93
  77. package/components/hy-icon/index.scss +84 -0
  78. package/components/hy-image/hy-image.vue +216 -0
  79. package/components/hy-image/index.scss +26 -0
  80. package/components/hy-image/props.ts +24 -0
  81. package/components/hy-image/typing.d.ts +76 -0
  82. package/components/hy-input/hy-input.vue +2 -72
  83. package/components/hy-input/index.scss +65 -0
  84. package/components/hy-line/hy-line.vue +4 -8
  85. package/components/hy-line/index.scss +5 -0
  86. package/components/hy-line/props.ts +3 -3
  87. package/components/hy-line/typing.d.ts +2 -2
  88. package/components/hy-line-progress/hy-line-progress.vue +15 -44
  89. package/components/hy-line-progress/index.scss +38 -0
  90. package/components/hy-line-progress/props.ts +2 -2
  91. package/components/hy-line-progress/typing.d.ts +1 -1
  92. package/components/hy-list/hy-list.vue +11 -41
  93. package/components/hy-list/index.scss +32 -0
  94. package/components/hy-list/props.ts +2 -2
  95. package/components/hy-loading/hy-loading.vue +95 -0
  96. package/components/hy-loading/index.scss +103 -0
  97. package/components/hy-loading/props.ts +17 -0
  98. package/components/hy-loading/typing.d.ts +53 -0
  99. package/components/hy-login/TheUserLogin.vue +20 -88
  100. package/components/hy-login/hy-login.vue +9 -9
  101. package/components/hy-login/props.ts +4 -4
  102. package/components/hy-modal/hy-modal.vue +11 -89
  103. package/components/hy-modal/index.scss +77 -0
  104. package/components/hy-modal/props.ts +2 -2
  105. package/components/hy-modal/typing.d.ts +1 -1
  106. package/components/hy-navbar/hy-navbar.vue +20 -92
  107. package/components/hy-navbar/index.scss +67 -0
  108. package/components/hy-navbar/props.ts +2 -2
  109. package/components/hy-navbar/typing.d.ts +1 -1
  110. package/components/hy-notice-bar/hy-column-notice.vue +11 -39
  111. package/components/hy-notice-bar/hy-notice-bar.vue +10 -12
  112. package/components/hy-notice-bar/hy-row-notice.vue +16 -58
  113. package/components/hy-notice-bar/index.scss +93 -0
  114. package/components/hy-notice-bar/props.ts +4 -2
  115. package/components/hy-notice-bar/typing.d.ts +13 -3
  116. package/components/hy-number-step/hy-number-step.vue +1 -70
  117. package/components/hy-number-step/index.scss +71 -0
  118. package/components/hy-overlay/hy-overlay.vue +2 -14
  119. package/components/hy-overlay/index.scss +9 -0
  120. package/components/hy-parse/hy-parse.vue +499 -0
  121. package/components/hy-parse/index.scss +9 -0
  122. package/components/hy-parse/node/node.vue +584 -0
  123. package/components/hy-parse/parser.js +1337 -0
  124. package/components/hy-parse/props.ts +19 -0
  125. package/components/hy-parse/typing.d.ts +68 -0
  126. package/components/hy-picker/hy-picker.vue +1 -68
  127. package/components/hy-picker/index.scss +68 -0
  128. package/components/hy-popup/hy-popup.vue +1 -74
  129. package/components/hy-popup/index.scss +60 -0
  130. package/components/hy-price/hy-price.vue +7 -19
  131. package/components/hy-price/index.scss +11 -0
  132. package/components/hy-price/props.ts +4 -3
  133. package/components/hy-price/typing.d.ts +8 -4
  134. package/components/hy-qrcode/hy-qrcode.vue +15 -37
  135. package/components/hy-qrcode/index.scss +23 -0
  136. package/components/hy-qrcode/props.ts +2 -2
  137. package/components/hy-qrcode/typing.d.ts +2 -2
  138. package/components/hy-radio/hy-radio.vue +2 -101
  139. package/components/hy-radio/index.scss +93 -0
  140. package/components/hy-radio/typing.d.ts +1 -2
  141. package/components/hy-rate/hy-rate.vue +1 -33
  142. package/components/hy-rate/index.scss +33 -0
  143. package/components/hy-read-more/hy-read-more.vue +7 -30
  144. package/components/hy-read-more/index.scss +25 -0
  145. package/components/hy-read-more/props.ts +3 -3
  146. package/components/hy-read-more/typing.d.ts +1 -1
  147. package/components/hy-safe-bottom/hy-safe-bottom.vue +5 -9
  148. package/components/hy-safe-bottom/index.scss +5 -0
  149. package/components/hy-scroll-list/hy-scroll-list.vue +13 -43
  150. package/components/hy-scroll-list/index.scss +34 -0
  151. package/components/hy-scroll-list/props.ts +2 -2
  152. package/components/hy-scroll-list/typing.d.ts +1 -1
  153. package/components/hy-search/hy-search.vue +1 -83
  154. package/components/hy-search/index.scss +83 -0
  155. package/components/hy-slider/hy-slider.vue +18 -95
  156. package/components/hy-slider/index.scss +77 -0
  157. package/components/hy-status-bar/hy-status-bar.vue +41 -0
  158. package/components/hy-status-bar/index.scss +6 -0
  159. package/components/hy-status-bar/props.ts +8 -0
  160. package/components/hy-status-bar/typing.d.ts +12 -0
  161. package/components/hy-steps/hy-steps.vue +36 -163
  162. package/components/hy-steps/index.scss +131 -0
  163. package/components/hy-steps/props.ts +2 -2
  164. package/components/hy-steps/typing.d.ts +2 -2
  165. package/components/hy-submitBar/Index.vue +17 -0
  166. package/components/hy-submitBar/hy-submitBar.vue +216 -0
  167. package/components/hy-submitBar/index.scss +9 -0
  168. package/components/hy-submitBar/props.ts +22 -0
  169. package/components/hy-submitBar/typing.d.ts +88 -0
  170. package/components/hy-subsection/hy-subsection.vue +40 -132
  171. package/components/hy-subsection/index.scss +82 -0
  172. package/components/hy-subsection/props.ts +1 -0
  173. package/components/hy-subsection/typing.d.ts +13 -4
  174. package/components/hy-swipe-action/hy-swipe-action.vue +294 -0
  175. package/components/hy-swipe-action/index.scss +9 -0
  176. package/components/hy-swipe-action/index.wxs +235 -0
  177. package/components/hy-swipe-action/props.ts +16 -0
  178. package/components/hy-swipe-action/typing.d.ts +55 -0
  179. package/components/hy-swipe-action/wxs.js +15 -0
  180. package/components/hy-swiper/hy-swiper-indicator.vue +5 -35
  181. package/components/hy-swiper/hy-swiper.vue +1 -54
  182. package/components/hy-swiper/index.scss +82 -0
  183. package/components/hy-switch/hy-switch.vue +62 -72
  184. package/components/hy-switch/index.scss +46 -0
  185. package/components/hy-switch/props.ts +4 -1
  186. package/components/hy-switch/typing.d.ts +14 -1
  187. package/components/hy-tabs/hy-tabs.vue +22 -81
  188. package/components/hy-tabs/index.scss +63 -0
  189. package/components/hy-tabs/props.ts +5 -5
  190. package/components/hy-tabs/typing.d.ts +1 -1
  191. package/components/hy-tag/hy-tag.vue +25 -220
  192. package/components/hy-tag/index.scss +205 -0
  193. package/components/hy-text/hy-text.vue +238 -0
  194. package/components/hy-text/index.scss +70 -0
  195. package/components/hy-text/index.ts +0 -0
  196. package/components/hy-text/props.ts +30 -0
  197. package/components/hy-text/typing.d.ts +98 -0
  198. package/components/hy-textarea/hy-textarea.vue +1 -46
  199. package/components/hy-textarea/index.scss +40 -0
  200. package/components/hy-toast/hy-toast.vue +175 -0
  201. package/components/hy-toast/index.scss +77 -0
  202. package/components/hy-toast/props.ts +3 -0
  203. package/components/hy-toast/typing.d.ts +38 -0
  204. package/components/hy-tooltip/hy-tooltip.vue +42 -95
  205. package/components/hy-tooltip/index.scss +64 -0
  206. package/components/hy-tooltip/props.ts +2 -2
  207. package/components/hy-tooltip/typing.d.ts +1 -1
  208. package/components/hy-transition/hy-transition.vue +4 -2
  209. package/components/hy-transition/typing.d.ts +1 -13
  210. package/components/hy-upload/hy-upload.vue +37 -182
  211. package/components/hy-upload/index.scss +147 -0
  212. package/components/hy-upload/props.ts +2 -2
  213. package/components/hy-upload/typing.d.ts +11 -11
  214. package/components/hy-warn/hy-warn.vue +17 -144
  215. package/components/hy-warn/index.scss +109 -0
  216. package/components/hy-warn/props.ts +3 -3
  217. package/components/hy-warn/typing.d.ts +4 -3
  218. package/components/hy-waterfall/hy-waterfall.vue +168 -38
  219. package/components/hy-waterfall/index.scss +16 -0
  220. package/components/hy-waterfall/props.ts +4 -5
  221. package/components/hy-waterfall/typing.d.ts +5 -9
  222. package/components/index.ts +25 -1
  223. package/components/message/index.ts +54 -54
  224. package/composables/index.ts +1 -0
  225. package/composables/useShare.ts +27 -0
  226. package/config/color.ts +3 -2
  227. package/config/icon.ts +21 -1
  228. package/global/index.ts +6 -6
  229. package/global/register-properties.ts +2 -2
  230. package/index.scss +2 -1
  231. package/index.ts +9 -8
  232. package/libs/css/common.scss +14 -2
  233. package/package.json +3 -2
  234. package/{libs/css → public/font}/iconfont.css +4 -4
  235. package/theme.scss +6 -4
  236. package/typing/index.ts +1 -1
  237. package/typing/modules/common.d.ts +36 -1
  238. package/utils/calendar.js +1021 -0
  239. package/utils/colorGradient.ts +112 -0
  240. package/utils/index.ts +2 -0
  241. package/utils/inside.ts +80 -34
  242. package/utils/inspect.ts +115 -0
  243. package/utils/utils.ts +20 -19
  244. package/libs/css/download.zip +0 -0
  245. /package/{libs/css → public/font}/iconfont.ttf +0 -0
  246. /package/{libs/css → public/font}/iconfont.woff +0 -0
  247. /package/{libs/css → public/font}/iconfont.woff2 +0 -0
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @description 求两个颜色之间的渐变值
3
+ * @param {string} startColor 开始的颜色
4
+ * @param {string} endColor 结束的颜色
5
+ * @param {number} step 颜色等分的份额
6
+ * */
7
+ export const colorGradient = (
8
+ startColor: string = "rgb(0, 0, 0)",
9
+ endColor: string = "rgb(255, 255, 255)",
10
+ step: number = 10,
11
+ ): any[] => {
12
+ const startRGB = hexToRgb(startColor, false); // 转换为rgb数组模式
13
+
14
+ const endRGB = hexToRgb(endColor, false);
15
+
16
+ if (typeof startRGB !== "string" && typeof endRGB !== "string") {
17
+ const startR = startRGB[0];
18
+ const startG = startRGB[1];
19
+ const startB = startRGB[2];
20
+
21
+ const endR = endRGB[0];
22
+ const endG = endRGB[1];
23
+ const endB = endRGB[2];
24
+
25
+ const sR = (endR - startR) / step; // 总差值
26
+ const sG = (endG - startG) / step;
27
+ const sB = (endB - startB) / step;
28
+ const colorArr = [];
29
+ for (let i = 0; i < step; i++) {
30
+ // 计算每一步的hex值
31
+ let hex = rgbToHex(
32
+ `rgb(${Math.round(sR * i + startR)},${Math.round(sG * i + startG)},${Math.round(
33
+ sB * i + startB,
34
+ )})`,
35
+ );
36
+ // 确保第一个颜色值为startColor的值
37
+ if (i === 0) hex = rgbToHex(startColor);
38
+ // 确保最后一个颜色值为endColor的值
39
+ if (i === step - 1) hex = rgbToHex(endColor);
40
+ colorArr.push(hex);
41
+ }
42
+ return colorArr;
43
+ }
44
+
45
+ return [];
46
+ };
47
+
48
+ // 将hex表示方式转换为rgb表示方式(这里返回rgb数组模式)
49
+ export function hexToRgb(sColor: string, str = true): string | number[] {
50
+ const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
51
+ sColor = String(sColor).toLowerCase();
52
+ if (sColor && reg.test(sColor)) {
53
+ if (sColor.length === 4) {
54
+ let sColorNew = "#";
55
+ for (let i = 1; i < 4; i += 1) {
56
+ sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
57
+ }
58
+ sColor = sColorNew;
59
+ }
60
+ // 处理六位的颜色值
61
+ const sColorChange = [];
62
+ for (let i = 1; i < 7; i += 2) {
63
+ sColorChange.push(parseInt(`0x${sColor.slice(i, i + 2)}`));
64
+ }
65
+ if (!str) {
66
+ return sColorChange;
67
+ }
68
+ return `rgb(${sColorChange[0]},${sColorChange[1]},${sColorChange[2]})`;
69
+ }
70
+ if (/^(rgb|RGB)/.test(sColor)) {
71
+ const arr = sColor.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
72
+ return arr.map((val) => Number(val));
73
+ }
74
+ return sColor;
75
+ }
76
+
77
+ // 将rgb表示方式转换为hex表示方式
78
+ export function rgbToHex(rgb: string) {
79
+ const _this = rgb;
80
+ const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
81
+ if (/^(rgb|RGB)/.test(_this)) {
82
+ const aColor = _this.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
83
+ let strHex = "#";
84
+ for (let i = 0; i < aColor.length; i++) {
85
+ let hex = Number(aColor[i]).toString(16);
86
+ hex = String(hex).length == 1 ? `${0}${hex}` : hex; // 保证每个rgb的值为2位
87
+ if (hex === "0") {
88
+ hex += hex;
89
+ }
90
+ strHex += hex;
91
+ }
92
+ if (strHex.length !== 7) {
93
+ strHex = _this;
94
+ }
95
+ return strHex;
96
+ }
97
+ if (reg.test(_this)) {
98
+ const aNum = _this.replace(/#/, "").split("");
99
+ if (aNum.length === 6) {
100
+ return _this;
101
+ }
102
+ if (aNum.length === 3) {
103
+ let numHex = "#";
104
+ for (let i = 0; i < aNum.length; i += 1) {
105
+ numHex += aNum[i] + aNum[i];
106
+ }
107
+ return numHex;
108
+ }
109
+ } else {
110
+ return _this;
111
+ }
112
+ }
package/utils/index.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from "./utils";
2
+ export * from "./inspect";
2
3
  export * from "./base64";
3
4
  export * from "./inside";
5
+ export * from "./colorGradient";
package/utils/inside.ts CHANGED
@@ -1,16 +1,6 @@
1
1
  // 内部使用方法
2
2
  import { inject } from "vue";
3
3
 
4
- /**
5
- * 是否视频格式
6
- * @param {String} value
7
- */
8
- export function isVideo(value: string): boolean {
9
- const VIDEO_REGEXP =
10
- /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|m3u8)/i;
11
- return VIDEO_REGEXP.test(value);
12
- }
13
-
14
4
  /**
15
5
  * 生成bem规则类名
16
6
  * 由于微信小程序,H5,nvue之间绑定class的差异,无法通过:class="[bem()]"的形式进行同用
@@ -25,7 +15,7 @@ export const bem = (
25
15
  name: string,
26
16
  props: Record<string, any>,
27
17
  fixed: string[],
28
- change?: string[]
18
+ change?: string[],
29
19
  ): string | string[] => {
30
20
  // 类名前缀
31
21
  const prefix = `hy-${name}--`;
@@ -123,25 +113,22 @@ export function guid(len = 32, firstU = true, radix = null) {
123
113
  return uuid.join("");
124
114
  }
125
115
 
126
- export function sys() {
127
- return uni.getSystemSetting();
128
- }
129
- export function getWindowInfo() {
130
- let ret = {};
116
+ /**
117
+ * @description 获取设备信息
118
+ * */
119
+ export const getWindowInfo = (): UniNamespace.GetWindowInfoResult => {
120
+ let ret: UniNamespace.GetWindowInfoResult;
131
121
  // #ifdef APP || H5 || MP-WEIXIN
132
122
  ret = uni.getWindowInfo();
133
123
  // #endif
134
- // #ifndef APP || H5 || MP-WEIXIN
135
- ret = sys();
136
- // #endif
137
124
  return ret;
138
- }
125
+ };
139
126
 
140
127
  function pickExclude(obj, keys) {
141
128
  // 某些情况下,type可能会为
142
129
  if (
143
130
  !["[object Object]", "[object File]"].includes(
144
- Object.prototype.toString.call(obj)
131
+ Object.prototype.toString.call(obj),
145
132
  )
146
133
  ) {
147
134
  return {};
@@ -163,7 +150,7 @@ function formatImage(res) {
163
150
  size: item.size,
164
151
  // #ifdef H5
165
152
  name: item.name,
166
- file: item
153
+ file: item,
167
154
  // #endif
168
155
  }));
169
156
  }
@@ -178,9 +165,9 @@ function formatVideo(res) {
178
165
  size: res.size,
179
166
  // #ifdef H5
180
167
  name: res.name,
181
- file: res
168
+ file: res,
182
169
  // #endif
183
- }
170
+ },
184
171
  ];
185
172
  }
186
173
 
@@ -192,7 +179,7 @@ function formatMedia(res) {
192
179
  thumb: res.type === "video" ? item.thumbTempFilePath : item.tempFilePath,
193
180
  size: item.size,
194
181
  // #ifdef H5
195
- file: item
182
+ file: item,
196
183
  // #endif
197
184
  }));
198
185
  }
@@ -205,7 +192,7 @@ function formatFile(res) {
205
192
  // #ifdef H5
206
193
  name: item.name,
207
194
  type: item.type,
208
- file: item
195
+ file: item,
209
196
  // #endif
210
197
  }));
211
198
  }
@@ -219,7 +206,7 @@ export function chooseFile({
219
206
  sizeType,
220
207
  camera,
221
208
  maxCount,
222
- extension
209
+ extension,
223
210
  }: any) {
224
211
  return new Promise((resolve, reject) => {
225
212
  switch (accept) {
@@ -229,7 +216,7 @@ export function chooseFile({
229
216
  sourceType: capture,
230
217
  sizeType,
231
218
  success: (res) => resolve(formatImage(res)),
232
- fail: reject
219
+ fail: reject,
233
220
  });
234
221
  break;
235
222
  // #ifdef MP-WEIXIN
@@ -242,7 +229,7 @@ export function chooseFile({
242
229
  sizeType,
243
230
  camera,
244
231
  success: (res) => resolve(formatMedia(res)),
245
- fail: reject
232
+ fail: reject,
246
233
  });
247
234
  break;
248
235
  // #endif
@@ -253,7 +240,7 @@ export function chooseFile({
253
240
  maxDuration,
254
241
  camera,
255
242
  success: (res) => resolve(formatVideo(res)),
256
- fail: reject
243
+ fail: reject,
257
244
  });
258
245
  break;
259
246
  // #ifdef MP-WEIXIN || H5
@@ -264,7 +251,7 @@ export function chooseFile({
264
251
  count: multiple ? maxCount : 1,
265
252
  type: accept,
266
253
  success: (res) => resolve(formatFile(res)),
267
- fail: reject
254
+ fail: reject,
268
255
  });
269
256
  // #endif
270
257
  // #ifdef H5
@@ -273,7 +260,7 @@ export function chooseFile({
273
260
  count: multiple ? maxCount : 1,
274
261
  type: accept,
275
262
  success: (res) => resolve(formatFile(res)),
276
- fail: reject
263
+ fail: reject,
277
264
  };
278
265
  if (extension.length && extension.length > 0) {
279
266
  params.extension = extension;
@@ -289,7 +276,7 @@ export function chooseFile({
289
276
  count: multiple ? maxCount : 1,
290
277
  type: "all",
291
278
  success: (res) => resolve(formatFile(res)),
292
- fail: reject
279
+ fail: reject,
293
280
  });
294
281
  // #endif
295
282
  // #ifdef H5
@@ -298,7 +285,7 @@ export function chooseFile({
298
285
  count: multiple ? maxCount : 1,
299
286
  type: "all",
300
287
  success: (res) => resolve(formatFile(res)),
301
- fail: reject
288
+ fail: reject,
302
289
  };
303
290
  if (extension.length && extension.length > 0) {
304
291
  paramsFile.extension = extension;
@@ -308,3 +295,62 @@ export function chooseFile({
308
295
  }
309
296
  });
310
297
  }
298
+
299
+ /**
300
+ * @description 数字格式化
301
+ * @param {number|string} number 要格式化的数字
302
+ * @param {number} decimals 保留几位小数
303
+ * @param {string} decimalPoint 小数点符号
304
+ * @param {string} thousandsSeparator 千分位符号
305
+ * @returns {string} 格式化后的数字
306
+ */
307
+ export function priceFormat(
308
+ number: string | number,
309
+ decimals = 0,
310
+ decimalPoint = ".",
311
+ thousandsSeparator = ",",
312
+ ) {
313
+ number = `${number}`.replace(/[^0-9+-Ee.]/g, "");
314
+ const n = !isFinite(+number) ? 0 : +number;
315
+ const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
316
+ const sep =
317
+ typeof thousandsSeparator === "undefined" ? "," : thousandsSeparator;
318
+ const dec = typeof decimalPoint === "undefined" ? "." : decimalPoint;
319
+ let s = "";
320
+
321
+ s = (prec ? n + "" : `${Math.round(n)}`).split(".");
322
+ const re = /(-?\d+)(\d{3})/;
323
+ while (re.test(s[0])) {
324
+ s[0] = s[0].replace(re, `$1${sep}$2`);
325
+ }
326
+
327
+ if ((s[1] || "").length < prec) {
328
+ s[1] = s[1] || "";
329
+ s[1] += new Array(prec - s[1].length + 1).join("0");
330
+ }
331
+ return s.join(dec);
332
+ }
333
+
334
+ /**
335
+ * @description 默认的姓名脱敏规则
336
+ * @param name 名字
337
+ * @return {string}
338
+ * */
339
+ export const formatName = (name: string): string => {
340
+ let value = "";
341
+ if (name.length === 2) {
342
+ value = name.substring(0, 1) + "*";
343
+ } else if (name.length > 2) {
344
+ let char = "";
345
+ for (let i = 0, len = name.length - 2; i < len; i++) {
346
+ char += "*";
347
+ }
348
+ value =
349
+ name.substring(0, 1) +
350
+ char +
351
+ name.substring(name.length - 1, name.length);
352
+ } else {
353
+ value = name;
354
+ }
355
+ return value;
356
+ };
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @description 判断字符串是否是数字
3
+ * @param {string | number} text 值
4
+ * @return {boolean}
5
+ * */
6
+ export const isNumericString = (text: string | number): boolean => {
7
+ return typeof text === "string" && !isNaN(Number(text));
8
+ };
9
+
10
+ /**
11
+ * @description 判断是否是数字
12
+ * @param {string | number} text 值
13
+ * @return {boolean}
14
+ * */
15
+ export const isNumber = (text: string | number): boolean => {
16
+ return typeof text === "number" || isNumericString(text);
17
+ };
18
+
19
+ /**
20
+ * @description 判断是否数组
21
+ * @param arr 传入数组值
22
+ * @return {boolean}
23
+ */
24
+ export const isArray = (arr: any): boolean => {
25
+ if (typeof Array.isArray === "function") {
26
+ return Array.isArray(arr);
27
+ }
28
+ return Object.prototype.toString.call(arr) === "[object Array]";
29
+ };
30
+
31
+ /**
32
+ * @description 判断是否对象
33
+ * @param obj 传入对象值
34
+ * @return {boolean}
35
+ */
36
+ export const isObject = (obj: any): boolean => {
37
+ return Object.prototype.toString.call(obj) === "[object Object]";
38
+ };
39
+
40
+ /**
41
+ * 是否视频格式
42
+ * @param {String} value
43
+ */
44
+ export function isVideo(value: string): boolean {
45
+ const VIDEO_REGEXP =
46
+ /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|m3u8)/i;
47
+ return VIDEO_REGEXP.test(value);
48
+ }
49
+
50
+ /**
51
+ * 判断是否是日期格式
52
+ * @param {number | string} value yyyy-mm-dd hh:mm:ss 或 时间戳
53
+ */
54
+ export const isDate = (value: string | number) => {
55
+ if (!value) return false;
56
+ // number类型,判断是否是时间戳
57
+ if (typeof value === "number") {
58
+ // len === 10 秒级时间戳 len === 13 毫秒级时间戳
59
+ if (value.toString().length !== 10 && value.toString().length !== 13) {
60
+ return false;
61
+ }
62
+ return !isNaN(new Date(value).getTime());
63
+ }
64
+ if (typeof value === "string") {
65
+ // 是否为string类型时间戳
66
+ const numV = Number(value);
67
+ if (!isNaN(numV)) {
68
+ if (numV.toString().length === 10 || numV.toString().length === 13) {
69
+ return !isNaN(new Date(numV).getTime());
70
+ }
71
+ }
72
+ // 非时间戳,且长度在yyyy-mm-dd 至 yyyy-mm-dd hh:mm:ss 之间
73
+ if (value.length < 10 || value.length > 19) {
74
+ return false;
75
+ }
76
+ const dateRegex = /^\d{4}[-\/]\d{2}[-\/]\d{2}( \d{1,2}:\d{2}(:\d{2})?)?$/;
77
+ if (!dateRegex.test(value)) {
78
+ return false;
79
+ }
80
+ // 检查是否为有效日期
81
+ const dateValue = new Date(value);
82
+ return !isNaN(dateValue.getTime());
83
+ }
84
+ // 非number和string类型,不做校验
85
+ return false;
86
+ };
87
+
88
+ /**
89
+ * @description 验证是否是手机号格式
90
+ * @param phone {string} 手机号
91
+ */
92
+ export const isPhone = (phone: string): boolean => {
93
+ return /^1[23456789]\d{9}$/.test(phone);
94
+ };
95
+
96
+ /**
97
+ * @description 验证身份证号码
98
+ * @param idCard {string} 身份证号
99
+ * @return {boolean}
100
+ */
101
+ export const isIdCard = (idCard: string): boolean => {
102
+ return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(
103
+ idCard,
104
+ );
105
+ };
106
+
107
+ /**
108
+ * @description 验证是否是中文
109
+ * @param {string} zh 校验值
110
+ * @return {boolean}
111
+ */
112
+ export const isChinese = (zh: string): boolean => {
113
+ const reg = /^[\u4e00-\u9fa5]+$/gi;
114
+ return reg.test(zh);
115
+ };
package/utils/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Base64 from "./base64";
2
- import { getCurrentInstance } from "vue";
3
2
  import type { CSSProperties } from "vue";
3
+ import { isNumber } from "./index";
4
4
  let base64: any = new Base64();
5
5
 
6
6
  /**
@@ -57,10 +57,6 @@ const addUnit = (
57
57
  // 用内置验证规则中的number判断是否为数值
58
58
  return isNumber(value) ? `${value}${unit}` : value;
59
59
  };
60
- function isNumber(value: string) {
61
- // 检查是否是数值类型或可以被解析为数值的字符串
62
- return !isNaN(parseFloat(value)) && isFinite(Number(value));
63
- }
64
60
 
65
61
  /**
66
62
  * @description 日期的月或日补零操作
@@ -250,7 +246,7 @@ const imageToBase64 = (path: string) => {
250
246
  * @returns {void}
251
247
  * @constructor
252
248
  */
253
- function debounce(fn: () => void, t?: number) {
249
+ function debounce(fn: Function, t?: number) {
254
250
  const delay = t || 500;
255
251
  let timer: any;
256
252
  let that = this;
@@ -265,17 +261,19 @@ function debounce(fn: () => void, t?: number) {
265
261
  }, delay);
266
262
  };
267
263
  }
264
+
265
+ let timer;
266
+ let flag: boolean | undefined;
268
267
  /**
269
268
  * 函数节流: 一段时间执行一次
270
269
  * @param {void} fn 回调函数
271
- * @param {number} t 节流时间
270
+ * @param {number} wait 节流等待时间
271
+ * @param {boolean} immediate 是否立马执行
272
272
  * @returns {void}
273
273
  * @constructor
274
274
  */
275
- let timer;
276
- let flag: boolean | undefined;
277
275
  const throttle = (
278
- func: Function,
276
+ fn: Function,
279
277
  wait: number = 500,
280
278
  immediate: boolean = true,
281
279
  ): void => {
@@ -283,7 +281,7 @@ const throttle = (
283
281
  if (!flag) {
284
282
  flag = true;
285
283
  // 如果是立即执行,则在wait毫秒内开始时执行
286
- typeof func === "function" && func();
284
+ typeof fn === "function" && fn();
287
285
  timer = setTimeout(() => {
288
286
  flag = false;
289
287
  }, wait);
@@ -293,7 +291,7 @@ const throttle = (
293
291
  // 如果是非立即执行,则在wait毫秒内的结束处执行
294
292
  timer = setTimeout(() => {
295
293
  flag = false;
296
- typeof func === "function" && func();
294
+ typeof fn === "function" && fn();
297
295
  }, wait);
298
296
  }
299
297
  };
@@ -367,13 +365,13 @@ const range = (min = 0, max = 0, value = 0) => {
367
365
  return Math.max(min, Math.min(max, Number(value)));
368
366
  };
369
367
  let instance: any;
370
- // #ifndef H5
371
- instance = getCurrentInstance();
372
- // #endif
373
368
  /**
374
369
  * 查询节点信息
375
370
  * 目前此方法在支付宝小程序中无法获取组件跟接点的尺寸,为支付宝的bug(2020-07-21)
376
371
  * 解决办法为在组件根部再套一个没有任何作用的view元素
372
+ * @param selector 元素类名或id
373
+ * @param all 是否获取多个相同元素数值
374
+ * @param ins 在微信小程序里,因为utils文件里面获取不到instance值所以必须通过ins这个传过来
377
375
  */
378
376
  const getRect = (
379
377
  selector: string,
@@ -382,8 +380,8 @@ const getRect = (
382
380
  ): Promise<UniApp.NodeInfo | UniApp.NodeInfo[]> => {
383
381
  return new Promise((resolve) => {
384
382
  // TODO: 在微信小程序里,因为utils文件里面获取不到instance值所以必须通过ins这个传过来
385
- // #ifndef H5
386
- instance = instance || ins;
383
+ // #ifdef MP-WEIXIN
384
+ instance = ins;
387
385
  // #endif
388
386
  // #ifndef APP-NVUE
389
387
  uni
@@ -412,7 +410,7 @@ const getRect = (
412
410
  function getPx(value: string | number, unit: true): string;
413
411
  function getPx(value: string | number, unit?: false): number;
414
412
  function getPx(value: string | number, unit: boolean = false): string | number {
415
- if (typeof value === "number") {
413
+ if (isNumber(value) || typeof value === "number") {
416
414
  return unit ? `${value}px` : Number(value);
417
415
  }
418
416
  // 如果带有rpx,先取出其数值部分,再转为px值
@@ -420,8 +418,11 @@ function getPx(value: string | number, unit: boolean = false): string | number {
420
418
  return unit
421
419
  ? `${uni.rpx2px(parseInt(value))}px`
422
420
  : Number(uni.rpx2px(parseInt(value)));
421
+ } else if (/(px)$/.test(value)) {
422
+ return unit ? value : Number(value.replace("px", ""));
423
+ } else {
424
+ return unit ? `${parseInt(value)}px` : Number(value);
423
425
  }
424
- return unit ? `${parseInt(value)}px` : parseInt(value);
425
426
  }
426
427
 
427
428
  /**
Binary file
File without changes
File without changes
File without changes