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
@@ -0,0 +1,119 @@
1
+ export default class Base64 {
2
+ // 私钥
3
+ _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
4
+ // 加密
5
+ encode = (input: string) => {
6
+ let output = "";
7
+ let chr1;
8
+ let chr2;
9
+ let chr3;
10
+ let enc1;
11
+ let enc2;
12
+ let enc3;
13
+ let enc4;
14
+ let i = 0;
15
+ input = this._utf8_encode(input);
16
+ while (i < input.length) {
17
+ chr1 = input.charCodeAt(i++);
18
+ chr2 = input.charCodeAt(i++);
19
+ chr3 = input.charCodeAt(i++);
20
+ enc1 = chr1 >> 2;
21
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
22
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
23
+ enc4 = chr3 & 63;
24
+ if (isNaN(chr2)) {
25
+ enc3 = enc4 = 64;
26
+ } else if (isNaN(chr3)) {
27
+ enc4 = 64;
28
+ }
29
+ output =
30
+ output +
31
+ this._keyStr.charAt(enc1) +
32
+ this._keyStr.charAt(enc2) +
33
+ this._keyStr.charAt(enc3) +
34
+ this._keyStr.charAt(enc4);
35
+ }
36
+ return output;
37
+ };
38
+ // 解密
39
+ decode = (input: string) => {
40
+ let output = "";
41
+ let chr1;
42
+ let chr2;
43
+ let chr3;
44
+ let enc1;
45
+ let enc2;
46
+ let enc3;
47
+ let enc4;
48
+ let i = 0;
49
+ if (input === undefined || input === null) {
50
+ } else {
51
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
52
+ while (i < input.length) {
53
+ enc1 = this._keyStr.indexOf(input.charAt(i++));
54
+ enc2 = this._keyStr.indexOf(input.charAt(i++));
55
+ enc3 = this._keyStr.indexOf(input.charAt(i++));
56
+ enc4 = this._keyStr.indexOf(input.charAt(i++));
57
+ chr1 = (enc1 << 2) | (enc2 >> 4);
58
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
59
+ chr3 = ((enc3 & 3) << 6) | enc4;
60
+ output += String.fromCharCode(chr1);
61
+ if (enc3 != 64) {
62
+ output += String.fromCharCode(chr2);
63
+ }
64
+ if (enc4 != 64) {
65
+ output += String.fromCharCode(chr3);
66
+ }
67
+ }
68
+ output = this._utf8_decode(output);
69
+ return output;
70
+ }
71
+ };
72
+ // private method for UTF-8 encoding
73
+ _utf8_encode = (string: string) => {
74
+ string = string.replace(/\r\n/g, "\n");
75
+ let utftext = "";
76
+ for (let n = 0; n < string.length; n++) {
77
+ const c = string.charCodeAt(n);
78
+ if (c < 128) {
79
+ utftext += String.fromCharCode(c);
80
+ } else if (c > 127 && c < 2048) {
81
+ utftext += String.fromCharCode((c >> 6) | 192);
82
+ utftext += String.fromCharCode((c & 63) | 128);
83
+ } else {
84
+ utftext += String.fromCharCode((c >> 12) | 224);
85
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
86
+ utftext += String.fromCharCode((c & 63) | 128);
87
+ }
88
+ }
89
+ return utftext;
90
+ };
91
+ // private method for UTF-8 decoding
92
+ _utf8_decode = (utftext: any) => {
93
+ let string = "";
94
+ let i = 0;
95
+ let c = (c1 = c2 = 0);
96
+ var c1 = 0;
97
+ var c2 = 0;
98
+ let c3 = 0;
99
+ while (i < utftext.length) {
100
+ c = utftext.charCodeAt(i);
101
+ if (c < 128) {
102
+ string += String.fromCharCode(c);
103
+ i++;
104
+ } else if (c > 191 && c < 224) {
105
+ c2 = utftext.charCodeAt(i + 1);
106
+ string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
107
+ i += 2;
108
+ } else {
109
+ c2 = utftext.charCodeAt(i + 1);
110
+ c3 = utftext.charCodeAt(i + 2);
111
+ string += String.fromCharCode(
112
+ ((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)
113
+ );
114
+ i += 3;
115
+ }
116
+ }
117
+ return string;
118
+ };
119
+ }
package/utils/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./utils";
2
+ export * from "./base64";
3
+ export * from "./inside";
@@ -0,0 +1,310 @@
1
+ // 内部使用方法
2
+ import { inject } from "vue";
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
+ /**
15
+ * 生成bem规则类名
16
+ * 由于微信小程序,H5,nvue之间绑定class的差异,无法通过:class="[bem()]"的形式进行同用
17
+ * 故采用如下折中做法,最后返回的是数组(一般平台)或字符串(支付宝和字节跳动平台),类似['a', 'b', 'c']或'a b c'的形式
18
+ * @param {String} name 组件名称
19
+ * @param props
20
+ * @param {Array} fixed 一直会存在的类名
21
+ * @param {Array} change 会根据变量值为true或者false而出现或者隐藏的类名
22
+ * @returns {Array|string}
23
+ */
24
+ export const bem = (
25
+ name: string,
26
+ props: Record<string, any>,
27
+ fixed: string[],
28
+ change?: string[]
29
+ ): string | string[] => {
30
+ // 类名前缀
31
+ const prefix = `hy-${name}--`;
32
+ const classes: Record<string, string | boolean> = {};
33
+ if (fixed) {
34
+ fixed.map((item: string) => {
35
+ // 这里的类名,会一直存在
36
+ classes[prefix + props[item]] = true;
37
+ });
38
+ }
39
+ if (change) {
40
+ change.map((item: string) => {
41
+ // 这里的类名,会根据this[item]的值为true或者false,而进行添加或者移除某一个类
42
+ props[item]
43
+ ? (classes[prefix + item] = props[item])
44
+ : delete classes[prefix + item];
45
+ });
46
+ }
47
+ return (
48
+ Object.keys(classes)
49
+ // 支付宝,头条小程序无法动态绑定一个数组类名,否则解析出来的结果会带有",",而导致失效
50
+ // #ifdef MP-ALIPAY || MP-TOUTIAO || MP-LARK
51
+ .join(" ")
52
+ // #endif
53
+ );
54
+ };
55
+
56
+ /**
57
+ * @description 在u-form的子组件内容发生变化,或者失去焦点时,尝试通知u-form执行校验方法
58
+ * @param {*} instance
59
+ * @param {*} event
60
+ */
61
+ export function formValidate(event) {
62
+ // const formItem = $parent.call(instance, "u-form-item");
63
+ const form = inject("uForm");
64
+ console.log(form, "form");
65
+ // 如果发生变化的input或者textarea等,其父组件中有u-form-item或者u-form等,就执行form的validate方法
66
+ // 同时将form-item的pros传递给form,让其进行精确对象验证
67
+ // if (formItem && form) {
68
+ // form.validateField(formItem.prop, () => {}, event);
69
+ // }
70
+ }
71
+
72
+ /**
73
+ * @description error提示
74
+ * @param {*} err 错误内容
75
+ */
76
+ export function error(err: string) {
77
+ // 开发环境才提示,生产环境不会提示
78
+ if (process.env.NODE_ENV === "development") {
79
+ console.error(`华玥组件提示:${err}`);
80
+ }
81
+ }
82
+
83
+ export const sleep = (value = 30) => {
84
+ return new Promise((resolve) => {
85
+ setTimeout(() => {
86
+ resolve();
87
+ }, value);
88
+ });
89
+ };
90
+
91
+ /**
92
+ * @param {Number} len uuid的长度
93
+ * @param {Boolean} firstU 将返回的首字母置为"u"
94
+ * @param {Nubmer} radix 生成uuid的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制
95
+ */
96
+ export function guid(len = 32, firstU = true, radix = null) {
97
+ const chars =
98
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
99
+ const uuid = [];
100
+ radix = radix || chars.length;
101
+
102
+ if (len) {
103
+ // 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
104
+ for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
105
+ } else {
106
+ let r;
107
+ // rfc4122标准要求返回的uuid中,某些位为固定的字符
108
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
109
+ uuid[14] = "4";
110
+
111
+ for (let i = 0; i < 36; i++) {
112
+ if (!uuid[i]) {
113
+ r = 0 | (Math.random() * 16);
114
+ uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
115
+ }
116
+ }
117
+ }
118
+ // 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class
119
+ if (firstU) {
120
+ uuid.shift();
121
+ return `hy${uuid.join("")}`;
122
+ }
123
+ return uuid.join("");
124
+ }
125
+
126
+ export function sys() {
127
+ return uni.getSystemSetting();
128
+ }
129
+ export function getWindowInfo() {
130
+ let ret = {};
131
+ // #ifdef APP || H5 || MP-WEIXIN
132
+ ret = uni.getWindowInfo();
133
+ // #endif
134
+ // #ifndef APP || H5 || MP-WEIXIN
135
+ ret = sys();
136
+ // #endif
137
+ return ret;
138
+ }
139
+
140
+ function pickExclude(obj, keys) {
141
+ // 某些情况下,type可能会为
142
+ if (
143
+ !["[object Object]", "[object File]"].includes(
144
+ Object.prototype.toString.call(obj)
145
+ )
146
+ ) {
147
+ return {};
148
+ }
149
+ return Object.keys(obj).reduce((prev, key) => {
150
+ if (!keys.includes(key)) {
151
+ prev[key] = obj[key];
152
+ }
153
+ return prev;
154
+ }, {});
155
+ }
156
+
157
+ function formatImage(res) {
158
+ return res.tempFiles.map((item) => ({
159
+ ...pickExclude(item, ["path"]),
160
+ type: "image",
161
+ url: item.path,
162
+ thumb: item.path,
163
+ size: item.size,
164
+ // #ifdef H5
165
+ name: item.name,
166
+ file: item
167
+ // #endif
168
+ }));
169
+ }
170
+
171
+ function formatVideo(res) {
172
+ return [
173
+ {
174
+ ...pickExclude(res, ["tempFilePath", "thumbTempFilePath", "errMsg"]),
175
+ type: "video",
176
+ url: res.tempFilePath,
177
+ thumb: res.thumbTempFilePath,
178
+ size: res.size,
179
+ // #ifdef H5
180
+ name: res.name,
181
+ file: res
182
+ // #endif
183
+ }
184
+ ];
185
+ }
186
+
187
+ function formatMedia(res) {
188
+ return res.tempFiles.map((item) => ({
189
+ ...pickExclude(item, ["fileType", "thumbTempFilePath", "tempFilePath"]),
190
+ type: res.type,
191
+ url: item.tempFilePath,
192
+ thumb: res.type === "video" ? item.thumbTempFilePath : item.tempFilePath,
193
+ size: item.size,
194
+ // #ifdef H5
195
+ file: item
196
+ // #endif
197
+ }));
198
+ }
199
+
200
+ function formatFile(res) {
201
+ return res.tempFiles.map((item) => ({
202
+ ...pickExclude(item, ["path"]),
203
+ url: item.path,
204
+ size: item.size,
205
+ // #ifdef H5
206
+ name: item.name,
207
+ type: item.type,
208
+ file: item
209
+ // #endif
210
+ }));
211
+ }
212
+
213
+ export function chooseFile({
214
+ accept,
215
+ multiple,
216
+ capture,
217
+ compressed,
218
+ maxDuration,
219
+ sizeType,
220
+ camera,
221
+ maxCount,
222
+ extension
223
+ }: any) {
224
+ return new Promise((resolve, reject) => {
225
+ switch (accept) {
226
+ case "image":
227
+ uni.chooseImage({
228
+ count: multiple ? Math.min(maxCount, 9) : 1,
229
+ sourceType: capture,
230
+ sizeType,
231
+ success: (res) => resolve(formatImage(res)),
232
+ fail: reject
233
+ });
234
+ break;
235
+ // #ifdef MP-WEIXIN
236
+ // 只有微信小程序才支持chooseMedia接口
237
+ case "media":
238
+ wx.chooseMedia({
239
+ count: multiple ? Math.min(maxCount, 9) : 1,
240
+ sourceType: capture,
241
+ maxDuration,
242
+ sizeType,
243
+ camera,
244
+ success: (res) => resolve(formatMedia(res)),
245
+ fail: reject
246
+ });
247
+ break;
248
+ // #endif
249
+ case "video":
250
+ uni.chooseVideo({
251
+ sourceType: capture,
252
+ compressed,
253
+ maxDuration,
254
+ camera,
255
+ success: (res) => resolve(formatVideo(res)),
256
+ fail: reject
257
+ });
258
+ break;
259
+ // #ifdef MP-WEIXIN || H5
260
+ // 只有微信小程序才支持chooseMessageFile接口
261
+ case "file":
262
+ // #ifdef MP-WEIXIN
263
+ wx.chooseMessageFile({
264
+ count: multiple ? maxCount : 1,
265
+ type: accept,
266
+ success: (res) => resolve(formatFile(res)),
267
+ fail: reject
268
+ });
269
+ // #endif
270
+ // #ifdef H5
271
+ // 需要hx2.9.9以上才支持uni.chooseFile
272
+ let params = {
273
+ count: multiple ? maxCount : 1,
274
+ type: accept,
275
+ success: (res) => resolve(formatFile(res)),
276
+ fail: reject
277
+ };
278
+ if (extension.length && extension.length > 0) {
279
+ params.extension = extension;
280
+ }
281
+ uni.chooseFile(params);
282
+ // #endif
283
+ break;
284
+ // #endif
285
+ default:
286
+ // 此为保底选项,在accept不为上面任意一项的时候选取全部文件
287
+ // #ifdef MP-WEIXIN
288
+ wx.chooseMessageFile({
289
+ count: multiple ? maxCount : 1,
290
+ type: "all",
291
+ success: (res) => resolve(formatFile(res)),
292
+ fail: reject
293
+ });
294
+ // #endif
295
+ // #ifdef H5
296
+ // 需要hx2.9.9以上才支持uni.chooseFile
297
+ let paramsFile = {
298
+ count: multiple ? maxCount : 1,
299
+ type: "all",
300
+ success: (res) => resolve(formatFile(res)),
301
+ fail: reject
302
+ };
303
+ if (extension.length && extension.length > 0) {
304
+ paramsFile.extension = extension;
305
+ }
306
+ uni.chooseFile(paramsFile);
307
+ // #endif
308
+ }
309
+ });
310
+ }