@nutui/nutui-react-taro 2.7.15-beta.1 → 2.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/esm/Uploader.js +1 -1
- package/dist/esm/nutui-react.es.js +1 -1
- package/dist/esm/{uploader.taro-S9pOua4j.js → uploader.taro-D3zeUFqf.js} +114 -6
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/tr-TR.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +122 -6
- package/dist/nutui.react.umd.js +122 -6
- package/dist/types/packages/uploader/chooseFile.d.ts +4 -0
- package/dist/types/packages/uploader/uploader.taro.d.ts +10 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# v2.7.15
|
|
2
|
+
`2026-03-09`
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
* 🏡 chore: 升级版本
|
|
6
|
+
* :sparkles: feat: 调整button圆角、dialog内边间距 (#3321)
|
|
7
|
+
* :bug: fix: uploader上传组件taro版本h5端支持文件选择 (#3424)
|
|
8
|
+
* :bug: fix(uploader): 修复H5上传 (#3421)
|
|
9
|
+
* :bug: fix(form): setFieldValue与setFieldsValue 重复触发notifyWatch (#3228)
|
|
10
|
+
|
|
11
|
+
|
|
1
12
|
# v2.7.14
|
|
2
13
|
|
|
3
14
|
`2025-04-30`
|
package/dist/esm/Uploader.js
CHANGED
|
@@ -47,7 +47,7 @@ import { S as S8 } from "./shortpassword.taro--atvsdZp.js";
|
|
|
47
47
|
import { S as S9 } from "./signature.taro-BW4eiGIR.js";
|
|
48
48
|
import { S as S10 } from "./switch.taro-CdBmDo18.js";
|
|
49
49
|
import { T as T5 } from "./textarea.taro-CGMI5QNw.js";
|
|
50
|
-
import { U } from "./uploader.taro-
|
|
50
|
+
import { U } from "./uploader.taro-D3zeUFqf.js";
|
|
51
51
|
import { A as A2 } from "./actionsheet.taro-kMhbV73n.js";
|
|
52
52
|
import { B as B3 } from "./badge.taro-W8s89KAj.js";
|
|
53
53
|
import { B as B4 } from "./dialog.taro-1Vukbvap.js";
|
|
@@ -138,6 +138,105 @@ class FileItem {
|
|
|
138
138
|
this.formData = {};
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
+
const chooseFile = (options) => {
|
|
142
|
+
const shouldBeObjectNative = (options2) => {
|
|
143
|
+
const isObject2 = options2 !== null && typeof options2 === "object" && !Array.isArray(options2);
|
|
144
|
+
if (!isObject2) {
|
|
145
|
+
return {
|
|
146
|
+
flag: false,
|
|
147
|
+
msg: "parameter should be Object"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
flag: true,
|
|
152
|
+
msg: ""
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
const isObject = shouldBeObjectNative(options);
|
|
156
|
+
if (!isObject.flag) {
|
|
157
|
+
const res2 = { errMsg: `taroChooseFile:fail ${isObject.msg}` };
|
|
158
|
+
console.error(res2.errMsg);
|
|
159
|
+
return Promise.reject(res2);
|
|
160
|
+
}
|
|
161
|
+
const { count = 1, success, fail, complete, imageId = "taroChooseFile", sourceType = ["album", "camera"] } = options;
|
|
162
|
+
const res = {
|
|
163
|
+
tempFilePaths: [],
|
|
164
|
+
tempFiles: [],
|
|
165
|
+
errMsg: ""
|
|
166
|
+
};
|
|
167
|
+
const handleSuccess = (data = {}, resolve = Promise.resolve.bind(Promise)) => {
|
|
168
|
+
if (!data.errMsg) {
|
|
169
|
+
data.errMsg = "taroChooseFile:ok";
|
|
170
|
+
}
|
|
171
|
+
typeof success === "function" && success(data);
|
|
172
|
+
typeof complete === "function" && complete(data);
|
|
173
|
+
return resolve(data);
|
|
174
|
+
};
|
|
175
|
+
const handleFail = (data = {}, reject = Promise.reject.bind(Promise)) => {
|
|
176
|
+
if (!data.errMsg) {
|
|
177
|
+
data.errMsg = "taroChooseFile:fail";
|
|
178
|
+
} else {
|
|
179
|
+
data.errMsg = `taroChooseFile:fail ${data.errMsg}`;
|
|
180
|
+
}
|
|
181
|
+
console.error(data.errMsg);
|
|
182
|
+
typeof fail === "function" && fail(data);
|
|
183
|
+
typeof complete === "function" && complete(data);
|
|
184
|
+
return reject(data);
|
|
185
|
+
};
|
|
186
|
+
const sourceTypeString = sourceType && sourceType.toString();
|
|
187
|
+
const acceptableSourceType = ["user", "environment", "camera"];
|
|
188
|
+
if (count && typeof count !== "number") {
|
|
189
|
+
res.errMsg = `parameter error: count should be number, but got ${typeof count}`;
|
|
190
|
+
return handleFail(res);
|
|
191
|
+
}
|
|
192
|
+
const el = document.getElementById(imageId);
|
|
193
|
+
if (!el) {
|
|
194
|
+
res.errMsg = "taroChooseFile:fail element not found";
|
|
195
|
+
return handleFail(res);
|
|
196
|
+
}
|
|
197
|
+
if (count > 1) {
|
|
198
|
+
el.setAttribute("multiple", "multiple");
|
|
199
|
+
} else {
|
|
200
|
+
el.removeAttribute("multiple");
|
|
201
|
+
}
|
|
202
|
+
if (acceptableSourceType.indexOf(sourceTypeString) > -1) {
|
|
203
|
+
el.setAttribute("capture", sourceTypeString);
|
|
204
|
+
} else {
|
|
205
|
+
el.removeAttribute("capture");
|
|
206
|
+
}
|
|
207
|
+
return new Promise((resolve) => {
|
|
208
|
+
if (el) {
|
|
209
|
+
const evt = new MouseEvent("click", {
|
|
210
|
+
bubbles: true,
|
|
211
|
+
cancelable: true,
|
|
212
|
+
view: window
|
|
213
|
+
});
|
|
214
|
+
el.dispatchEvent(evt);
|
|
215
|
+
el.onchange = (e) => {
|
|
216
|
+
const target = e.target;
|
|
217
|
+
if (target) {
|
|
218
|
+
const files = target.files || [];
|
|
219
|
+
const arr = Array.from(files);
|
|
220
|
+
arr.forEach((item) => {
|
|
221
|
+
const blob = new Blob([item], {
|
|
222
|
+
type: item.type
|
|
223
|
+
});
|
|
224
|
+
const url = URL.createObjectURL(blob);
|
|
225
|
+
res.tempFilePaths.push(url);
|
|
226
|
+
res.tempFiles.push({
|
|
227
|
+
path: url,
|
|
228
|
+
size: item.size,
|
|
229
|
+
type: item.type,
|
|
230
|
+
originalFileObj: item
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
handleSuccess(res, resolve);
|
|
234
|
+
target.value = "";
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
};
|
|
141
240
|
const Preview = ({ fileList, previewType, deletable, onDeleteItem, handleItemClick, previewUrl, deleteIcon, children }) => {
|
|
142
241
|
const renderIcon = (item) => {
|
|
143
242
|
if (item.status === ERROR) {
|
|
@@ -206,7 +305,7 @@ const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { url:
|
|
|
206
305
|
} });
|
|
207
306
|
const InternalUploader = (props, ref) => {
|
|
208
307
|
const { locale } = useConfig();
|
|
209
|
-
const _a = Object.assign(Object.assign({}, defaultProps), props), { children, uploadIcon, deleteIcon, uploadLabel, accept, name, camera, defaultValue, value, previewType, fit, disabled, multiple, url, previewUrl, headers, timeout, method, xhrState, data, preview, deletable, maxCount, maxFileSize, mediaType, className, autoUpload, sizeType, sourceType, maxDuration, onStart, onDelete, onChange, onFileItemClick, onProgress, onSuccess, onUpdate, onFailure, onOversize, beforeUpload, beforeXhrUpload, beforeDelete } = _a, restProps = __rest(_a, ["children", "uploadIcon", "deleteIcon", "uploadLabel", "accept", "name", "camera", "defaultValue", "value", "previewType", "fit", "disabled", "multiple", "url", "previewUrl", "headers", "timeout", "method", "xhrState", "data", "preview", "deletable", "maxCount", "maxFileSize", "mediaType", "className", "autoUpload", "sizeType", "sourceType", "maxDuration", "onStart", "onDelete", "onChange", "onFileItemClick", "onProgress", "onSuccess", "onUpdate", "onFailure", "onOversize", "beforeUpload", "beforeXhrUpload", "beforeDelete"]);
|
|
308
|
+
const _a = Object.assign(Object.assign({}, defaultProps), props), { children, uploadIcon, deleteIcon, uploadLabel, accept, name, camera, defaultValue, value, previewType, fit, disabled, multiple, url, previewUrl, headers, timeout, method, xhrState, data, preview, deletable, maxCount, maxFileSize, mediaType, className, autoUpload, sizeType, sourceType, maxDuration, onStart, onDelete, onChange, onFileItemClick, onProgress, onSuccess, onUpdate, onFailure, onOversize, beforeUpload, beforeXhrUpload, beforeDelete, needChooseFile } = _a, restProps = __rest(_a, ["children", "uploadIcon", "deleteIcon", "uploadLabel", "accept", "name", "camera", "defaultValue", "value", "previewType", "fit", "disabled", "multiple", "url", "previewUrl", "headers", "timeout", "method", "xhrState", "data", "preview", "deletable", "maxCount", "maxFileSize", "mediaType", "className", "autoUpload", "sizeType", "sourceType", "maxDuration", "onStart", "onDelete", "onChange", "onFileItemClick", "onProgress", "onSuccess", "onUpdate", "onFailure", "onOversize", "beforeUpload", "beforeXhrUpload", "beforeDelete", "needChooseFile"]);
|
|
210
309
|
const [fileList, setFileList] = usePropsValue({
|
|
211
310
|
value,
|
|
212
311
|
defaultValue,
|
|
@@ -244,20 +343,29 @@ const InternalUploader = (props, ref) => {
|
|
|
244
343
|
if (disabled) {
|
|
245
344
|
return;
|
|
246
345
|
}
|
|
247
|
-
if (Taro.getEnv() === "WEB") {
|
|
248
|
-
const el = document.getElementById("
|
|
346
|
+
if (Taro.getEnv() === "WEB" && needChooseFile) {
|
|
347
|
+
const el = document.getElementById("taroChooseFile");
|
|
249
348
|
if (el) {
|
|
250
349
|
el === null || el === void 0 ? void 0 : el.setAttribute("accept", accept);
|
|
251
350
|
} else {
|
|
252
351
|
const obj = document.createElement("input");
|
|
253
352
|
obj.setAttribute("type", "file");
|
|
254
|
-
obj.setAttribute("id", "
|
|
353
|
+
obj.setAttribute("id", "taroChooseFile");
|
|
255
354
|
obj.setAttribute("accept", accept);
|
|
256
355
|
obj.setAttribute("style", "position: fixed; top: -4000px; left: -3000px; z-index: -300;");
|
|
257
356
|
document.body.appendChild(obj);
|
|
258
357
|
}
|
|
259
|
-
|
|
260
|
-
|
|
358
|
+
chooseFile({
|
|
359
|
+
count: multiple ? maxCount * 1 - fileList.length : 1,
|
|
360
|
+
// 可以指定是原图还是压缩图,默认二者都有
|
|
361
|
+
sizeType,
|
|
362
|
+
sourceType,
|
|
363
|
+
success: onChangeImage,
|
|
364
|
+
fail: (res) => {
|
|
365
|
+
onFailure && onFailure(res);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
} else if (["WEAPP", "JD", "WEB"].includes(getEnv()) && chooseMedia) {
|
|
261
369
|
chooseMedia({
|
|
262
370
|
count: multiple ? maxCount * 1 - fileList.length : 1,
|
|
263
371
|
/** 文件类型 */
|
package/dist/locales/base.js
CHANGED
package/dist/locales/en-US.js
CHANGED
package/dist/locales/id-ID.js
CHANGED
package/dist/locales/tr-TR.js
CHANGED
package/dist/locales/zh-CN.js
CHANGED
package/dist/locales/zh-TW.js
CHANGED
package/dist/locales/zh-UG.js
CHANGED
package/dist/nutui.react.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @nutui/nutui-react-taro v2.7.15
|
|
2
|
+
* @nutui/nutui-react-taro v2.7.15 Mon Mar 09 2026 10:28:24 GMT+0800 (中国标准时间)
|
|
3
3
|
* (c) 2023 @jdf2e.
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -13246,6 +13246,112 @@ class FileItem {
|
|
|
13246
13246
|
this.formData = {};
|
|
13247
13247
|
}
|
|
13248
13248
|
}
|
|
13249
|
+
const chooseFile = (options) => {
|
|
13250
|
+
const shouldBeObjectNative = (options2) => {
|
|
13251
|
+
const isObject22 = options2 !== null && typeof options2 === "object" && !Array.isArray(options2);
|
|
13252
|
+
if (!isObject22) {
|
|
13253
|
+
return {
|
|
13254
|
+
flag: false,
|
|
13255
|
+
msg: "parameter should be Object"
|
|
13256
|
+
};
|
|
13257
|
+
}
|
|
13258
|
+
return {
|
|
13259
|
+
flag: true,
|
|
13260
|
+
msg: ""
|
|
13261
|
+
};
|
|
13262
|
+
};
|
|
13263
|
+
const isObject2 = shouldBeObjectNative(options);
|
|
13264
|
+
if (!isObject2.flag) {
|
|
13265
|
+
const res2 = { errMsg: `taroChooseFile:fail ${isObject2.msg}` };
|
|
13266
|
+
console.error(res2.errMsg);
|
|
13267
|
+
return Promise.reject(res2);
|
|
13268
|
+
}
|
|
13269
|
+
const {
|
|
13270
|
+
count = 1,
|
|
13271
|
+
success,
|
|
13272
|
+
fail,
|
|
13273
|
+
complete,
|
|
13274
|
+
imageId = "taroChooseFile",
|
|
13275
|
+
sourceType = ["album", "camera"]
|
|
13276
|
+
} = options;
|
|
13277
|
+
const res = {
|
|
13278
|
+
tempFilePaths: [],
|
|
13279
|
+
tempFiles: [],
|
|
13280
|
+
errMsg: ""
|
|
13281
|
+
};
|
|
13282
|
+
const handleSuccess = (data = {}, resolve = Promise.resolve.bind(Promise)) => {
|
|
13283
|
+
if (!data.errMsg) {
|
|
13284
|
+
data.errMsg = "taroChooseFile:ok";
|
|
13285
|
+
}
|
|
13286
|
+
typeof success === "function" && success(data);
|
|
13287
|
+
typeof complete === "function" && complete(data);
|
|
13288
|
+
return resolve(data);
|
|
13289
|
+
};
|
|
13290
|
+
const handleFail = (data = {}, reject = Promise.reject.bind(Promise)) => {
|
|
13291
|
+
if (!data.errMsg) {
|
|
13292
|
+
data.errMsg = "taroChooseFile:fail";
|
|
13293
|
+
} else {
|
|
13294
|
+
data.errMsg = `taroChooseFile:fail ${data.errMsg}`;
|
|
13295
|
+
}
|
|
13296
|
+
console.error(data.errMsg);
|
|
13297
|
+
typeof fail === "function" && fail(data);
|
|
13298
|
+
typeof complete === "function" && complete(data);
|
|
13299
|
+
return reject(data);
|
|
13300
|
+
};
|
|
13301
|
+
const sourceTypeString = sourceType && sourceType.toString();
|
|
13302
|
+
const acceptableSourceType = ["user", "environment", "camera"];
|
|
13303
|
+
if (count && typeof count !== "number") {
|
|
13304
|
+
res.errMsg = `parameter error: count should be number, but got ${typeof count}`;
|
|
13305
|
+
return handleFail(res);
|
|
13306
|
+
}
|
|
13307
|
+
const el = document.getElementById(imageId);
|
|
13308
|
+
if (!el) {
|
|
13309
|
+
res.errMsg = "taroChooseFile:fail element not found";
|
|
13310
|
+
return handleFail(res);
|
|
13311
|
+
}
|
|
13312
|
+
if (count > 1) {
|
|
13313
|
+
el.setAttribute("multiple", "multiple");
|
|
13314
|
+
} else {
|
|
13315
|
+
el.removeAttribute("multiple");
|
|
13316
|
+
}
|
|
13317
|
+
if (acceptableSourceType.indexOf(sourceTypeString) > -1) {
|
|
13318
|
+
el.setAttribute("capture", sourceTypeString);
|
|
13319
|
+
} else {
|
|
13320
|
+
el.removeAttribute("capture");
|
|
13321
|
+
}
|
|
13322
|
+
return new Promise((resolve) => {
|
|
13323
|
+
if (el) {
|
|
13324
|
+
const evt = new MouseEvent("click", {
|
|
13325
|
+
bubbles: true,
|
|
13326
|
+
cancelable: true,
|
|
13327
|
+
view: window
|
|
13328
|
+
});
|
|
13329
|
+
el.dispatchEvent(evt);
|
|
13330
|
+
el.onchange = (e2) => {
|
|
13331
|
+
const target = e2.target;
|
|
13332
|
+
if (target) {
|
|
13333
|
+
const files = target.files || [];
|
|
13334
|
+
const arr = Array.from(files);
|
|
13335
|
+
arr.forEach((item) => {
|
|
13336
|
+
const blob = new Blob([item], {
|
|
13337
|
+
type: item.type
|
|
13338
|
+
});
|
|
13339
|
+
const url2 = URL.createObjectURL(blob);
|
|
13340
|
+
res.tempFilePaths.push(url2);
|
|
13341
|
+
res.tempFiles.push({
|
|
13342
|
+
path: url2,
|
|
13343
|
+
size: item.size,
|
|
13344
|
+
type: item.type,
|
|
13345
|
+
originalFileObj: item
|
|
13346
|
+
});
|
|
13347
|
+
});
|
|
13348
|
+
handleSuccess(res, resolve);
|
|
13349
|
+
target.value = "";
|
|
13350
|
+
}
|
|
13351
|
+
};
|
|
13352
|
+
}
|
|
13353
|
+
});
|
|
13354
|
+
};
|
|
13249
13355
|
const defaultProps$I = {
|
|
13250
13356
|
...ComponentDefaults,
|
|
13251
13357
|
percent: 0,
|
|
@@ -13557,6 +13663,7 @@ const InternalUploader = (props, ref) => {
|
|
|
13557
13663
|
beforeUpload,
|
|
13558
13664
|
beforeXhrUpload,
|
|
13559
13665
|
beforeDelete,
|
|
13666
|
+
needChooseFile,
|
|
13560
13667
|
...restProps
|
|
13561
13668
|
} = { ...defaultProps$H, ...props };
|
|
13562
13669
|
const [fileList, setFileList] = usePropsValue({
|
|
@@ -13596,14 +13703,14 @@ const InternalUploader = (props, ref) => {
|
|
|
13596
13703
|
if (disabled) {
|
|
13597
13704
|
return;
|
|
13598
13705
|
}
|
|
13599
|
-
if (Taro.getEnv() === "WEB") {
|
|
13600
|
-
const el = document.getElementById("
|
|
13706
|
+
if (Taro.getEnv() === "WEB" && needChooseFile) {
|
|
13707
|
+
const el = document.getElementById("taroChooseFile");
|
|
13601
13708
|
if (el) {
|
|
13602
13709
|
el == null ? void 0 : el.setAttribute("accept", accept);
|
|
13603
13710
|
} else {
|
|
13604
13711
|
const obj = document.createElement("input");
|
|
13605
13712
|
obj.setAttribute("type", "file");
|
|
13606
|
-
obj.setAttribute("id", "
|
|
13713
|
+
obj.setAttribute("id", "taroChooseFile");
|
|
13607
13714
|
obj.setAttribute("accept", accept);
|
|
13608
13715
|
obj.setAttribute(
|
|
13609
13716
|
"style",
|
|
@@ -13611,8 +13718,17 @@ const InternalUploader = (props, ref) => {
|
|
|
13611
13718
|
);
|
|
13612
13719
|
document.body.appendChild(obj);
|
|
13613
13720
|
}
|
|
13614
|
-
|
|
13615
|
-
|
|
13721
|
+
chooseFile({
|
|
13722
|
+
count: multiple ? maxCount * 1 - fileList.length : 1,
|
|
13723
|
+
// 可以指定是原图还是压缩图,默认二者都有
|
|
13724
|
+
sizeType,
|
|
13725
|
+
sourceType,
|
|
13726
|
+
success: onChangeImage,
|
|
13727
|
+
fail: (res) => {
|
|
13728
|
+
onFailure && onFailure(res);
|
|
13729
|
+
}
|
|
13730
|
+
});
|
|
13731
|
+
} else if (["WEAPP", "JD", "WEB"].includes(getEnv()) && chooseMedia) {
|
|
13616
13732
|
chooseMedia({
|
|
13617
13733
|
count: multiple ? maxCount * 1 - fileList.length : 1,
|
|
13618
13734
|
/** 文件类型 */
|
package/dist/nutui.react.umd.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("@tarojs/taro"), require("@tarojs/components"), require("react-dom")) : typeof define === "function" && define.amd ? define(["exports", "react", "@tarojs/taro", "@tarojs/components", "react-dom"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory((global2.nutui = global2.nutui || {}, global2.nutui.react = {}), global2.React, global2.Taro, global2.components, global2.ReactDOM));
|
|
3
3
|
})(this, function(exports2, React, Taro, components, ReactDOM) {
|
|
4
4
|
"use strict";/*!
|
|
5
|
-
* @nutui/nutui-react-taro v2.7.15
|
|
5
|
+
* @nutui/nutui-react-taro v2.7.15 Mon Mar 09 2026 10:28:24 GMT+0800 (中国标准时间)
|
|
6
6
|
* (c) 2023 @jdf2e.
|
|
7
7
|
* Released under the MIT License.
|
|
8
8
|
*/
|
|
@@ -13262,6 +13262,112 @@
|
|
|
13262
13262
|
this.formData = {};
|
|
13263
13263
|
}
|
|
13264
13264
|
}
|
|
13265
|
+
const chooseFile = (options) => {
|
|
13266
|
+
const shouldBeObjectNative = (options2) => {
|
|
13267
|
+
const isObject22 = options2 !== null && typeof options2 === "object" && !Array.isArray(options2);
|
|
13268
|
+
if (!isObject22) {
|
|
13269
|
+
return {
|
|
13270
|
+
flag: false,
|
|
13271
|
+
msg: "parameter should be Object"
|
|
13272
|
+
};
|
|
13273
|
+
}
|
|
13274
|
+
return {
|
|
13275
|
+
flag: true,
|
|
13276
|
+
msg: ""
|
|
13277
|
+
};
|
|
13278
|
+
};
|
|
13279
|
+
const isObject2 = shouldBeObjectNative(options);
|
|
13280
|
+
if (!isObject2.flag) {
|
|
13281
|
+
const res2 = { errMsg: `taroChooseFile:fail ${isObject2.msg}` };
|
|
13282
|
+
console.error(res2.errMsg);
|
|
13283
|
+
return Promise.reject(res2);
|
|
13284
|
+
}
|
|
13285
|
+
const {
|
|
13286
|
+
count = 1,
|
|
13287
|
+
success,
|
|
13288
|
+
fail,
|
|
13289
|
+
complete,
|
|
13290
|
+
imageId = "taroChooseFile",
|
|
13291
|
+
sourceType = ["album", "camera"]
|
|
13292
|
+
} = options;
|
|
13293
|
+
const res = {
|
|
13294
|
+
tempFilePaths: [],
|
|
13295
|
+
tempFiles: [],
|
|
13296
|
+
errMsg: ""
|
|
13297
|
+
};
|
|
13298
|
+
const handleSuccess = (data = {}, resolve = Promise.resolve.bind(Promise)) => {
|
|
13299
|
+
if (!data.errMsg) {
|
|
13300
|
+
data.errMsg = "taroChooseFile:ok";
|
|
13301
|
+
}
|
|
13302
|
+
typeof success === "function" && success(data);
|
|
13303
|
+
typeof complete === "function" && complete(data);
|
|
13304
|
+
return resolve(data);
|
|
13305
|
+
};
|
|
13306
|
+
const handleFail = (data = {}, reject = Promise.reject.bind(Promise)) => {
|
|
13307
|
+
if (!data.errMsg) {
|
|
13308
|
+
data.errMsg = "taroChooseFile:fail";
|
|
13309
|
+
} else {
|
|
13310
|
+
data.errMsg = `taroChooseFile:fail ${data.errMsg}`;
|
|
13311
|
+
}
|
|
13312
|
+
console.error(data.errMsg);
|
|
13313
|
+
typeof fail === "function" && fail(data);
|
|
13314
|
+
typeof complete === "function" && complete(data);
|
|
13315
|
+
return reject(data);
|
|
13316
|
+
};
|
|
13317
|
+
const sourceTypeString = sourceType && sourceType.toString();
|
|
13318
|
+
const acceptableSourceType = ["user", "environment", "camera"];
|
|
13319
|
+
if (count && typeof count !== "number") {
|
|
13320
|
+
res.errMsg = `parameter error: count should be number, but got ${typeof count}`;
|
|
13321
|
+
return handleFail(res);
|
|
13322
|
+
}
|
|
13323
|
+
const el = document.getElementById(imageId);
|
|
13324
|
+
if (!el) {
|
|
13325
|
+
res.errMsg = "taroChooseFile:fail element not found";
|
|
13326
|
+
return handleFail(res);
|
|
13327
|
+
}
|
|
13328
|
+
if (count > 1) {
|
|
13329
|
+
el.setAttribute("multiple", "multiple");
|
|
13330
|
+
} else {
|
|
13331
|
+
el.removeAttribute("multiple");
|
|
13332
|
+
}
|
|
13333
|
+
if (acceptableSourceType.indexOf(sourceTypeString) > -1) {
|
|
13334
|
+
el.setAttribute("capture", sourceTypeString);
|
|
13335
|
+
} else {
|
|
13336
|
+
el.removeAttribute("capture");
|
|
13337
|
+
}
|
|
13338
|
+
return new Promise((resolve) => {
|
|
13339
|
+
if (el) {
|
|
13340
|
+
const evt = new MouseEvent("click", {
|
|
13341
|
+
bubbles: true,
|
|
13342
|
+
cancelable: true,
|
|
13343
|
+
view: window
|
|
13344
|
+
});
|
|
13345
|
+
el.dispatchEvent(evt);
|
|
13346
|
+
el.onchange = (e2) => {
|
|
13347
|
+
const target = e2.target;
|
|
13348
|
+
if (target) {
|
|
13349
|
+
const files = target.files || [];
|
|
13350
|
+
const arr = Array.from(files);
|
|
13351
|
+
arr.forEach((item) => {
|
|
13352
|
+
const blob = new Blob([item], {
|
|
13353
|
+
type: item.type
|
|
13354
|
+
});
|
|
13355
|
+
const url = URL.createObjectURL(blob);
|
|
13356
|
+
res.tempFilePaths.push(url);
|
|
13357
|
+
res.tempFiles.push({
|
|
13358
|
+
path: url,
|
|
13359
|
+
size: item.size,
|
|
13360
|
+
type: item.type,
|
|
13361
|
+
originalFileObj: item
|
|
13362
|
+
});
|
|
13363
|
+
});
|
|
13364
|
+
handleSuccess(res, resolve);
|
|
13365
|
+
target.value = "";
|
|
13366
|
+
}
|
|
13367
|
+
};
|
|
13368
|
+
}
|
|
13369
|
+
});
|
|
13370
|
+
};
|
|
13265
13371
|
const defaultProps$I = {
|
|
13266
13372
|
...ComponentDefaults,
|
|
13267
13373
|
percent: 0,
|
|
@@ -13573,6 +13679,7 @@
|
|
|
13573
13679
|
beforeUpload,
|
|
13574
13680
|
beforeXhrUpload,
|
|
13575
13681
|
beforeDelete,
|
|
13682
|
+
needChooseFile,
|
|
13576
13683
|
...restProps
|
|
13577
13684
|
} = { ...defaultProps$H, ...props };
|
|
13578
13685
|
const [fileList, setFileList] = usePropsValue({
|
|
@@ -13612,14 +13719,14 @@
|
|
|
13612
13719
|
if (disabled) {
|
|
13613
13720
|
return;
|
|
13614
13721
|
}
|
|
13615
|
-
if (Taro.getEnv() === "WEB") {
|
|
13616
|
-
const el = document.getElementById("
|
|
13722
|
+
if (Taro.getEnv() === "WEB" && needChooseFile) {
|
|
13723
|
+
const el = document.getElementById("taroChooseFile");
|
|
13617
13724
|
if (el) {
|
|
13618
13725
|
el == null ? void 0 : el.setAttribute("accept", accept);
|
|
13619
13726
|
} else {
|
|
13620
13727
|
const obj = document.createElement("input");
|
|
13621
13728
|
obj.setAttribute("type", "file");
|
|
13622
|
-
obj.setAttribute("id", "
|
|
13729
|
+
obj.setAttribute("id", "taroChooseFile");
|
|
13623
13730
|
obj.setAttribute("accept", accept);
|
|
13624
13731
|
obj.setAttribute(
|
|
13625
13732
|
"style",
|
|
@@ -13627,8 +13734,17 @@
|
|
|
13627
13734
|
);
|
|
13628
13735
|
document.body.appendChild(obj);
|
|
13629
13736
|
}
|
|
13630
|
-
|
|
13631
|
-
|
|
13737
|
+
chooseFile({
|
|
13738
|
+
count: multiple ? maxCount * 1 - fileList.length : 1,
|
|
13739
|
+
// 可以指定是原图还是压缩图,默认二者都有
|
|
13740
|
+
sizeType,
|
|
13741
|
+
sourceType,
|
|
13742
|
+
success: onChangeImage,
|
|
13743
|
+
fail: (res) => {
|
|
13744
|
+
onFailure && onFailure(res);
|
|
13745
|
+
}
|
|
13746
|
+
});
|
|
13747
|
+
} else if (["WEAPP", "JD", "WEB"].includes(Taro.getEnv()) && Taro.chooseMedia) {
|
|
13632
13748
|
Taro.chooseMedia({
|
|
13633
13749
|
count: multiple ? maxCount * 1 - fileList.length : 1,
|
|
13634
13750
|
/** 文件类型 */
|
|
@@ -97,7 +97,11 @@ export interface UploaderProps extends BasicComponent {
|
|
|
97
97
|
* @default file
|
|
98
98
|
*/
|
|
99
99
|
name: string
|
|
100
|
-
|
|
100
|
+
/**
|
|
101
|
+
* H5 端 input 的 accept 属性,用于限制选择的文件类型(仅 H5 端生效)
|
|
102
|
+
* @default *
|
|
103
|
+
*/
|
|
104
|
+
accept: string
|
|
101
105
|
/**
|
|
102
106
|
* 是否禁用文件上传
|
|
103
107
|
* @default false
|
|
@@ -228,6 +232,11 @@ export interface UploaderProps extends BasicComponent {
|
|
|
228
232
|
* @default -
|
|
229
233
|
*/
|
|
230
234
|
onFileItemClick?: (file: FileItem, index: number) => void
|
|
235
|
+
/**
|
|
236
|
+
* 是否在 H5 端使用原生 input 选择文件(配合 accept 自定义文件类型,仅 H5 端生效)
|
|
237
|
+
* @default false
|
|
238
|
+
*/
|
|
239
|
+
needChooseFile?: boolean
|
|
231
240
|
}
|
|
232
241
|
export declare const Uploader: React.ForwardRefExoticComponent<Partial<UploaderProps> & {
|
|
233
242
|
children?: React.ReactNode | undefined;
|