|
|
@@ -175,9 +175,11 @@ export interface UploaderProps {
|
|
|
* 选择文件类型
|
|
|
* * image:图片
|
|
|
* * video:视频
|
|
|
+ * * file: 文件(仅H5)
|
|
|
+ * * select:根据用户选择(图片/视频)
|
|
|
* @default 'image'
|
|
|
*/
|
|
|
- chooseType?: 'image'|'video'|'file'|'';
|
|
|
+ chooseType?: 'image'|'video'|'file'|'select'|'';
|
|
|
/**
|
|
|
* 是否是从消息中选择文件
|
|
|
* @default true
|
|
|
@@ -338,14 +340,12 @@ function onUploadPress() {
|
|
|
},
|
|
|
],
|
|
|
showCancel: true,
|
|
|
- onSelect(index, name) {
|
|
|
- },
|
|
|
}).then((index) => {
|
|
|
if (index === 0) {
|
|
|
- chooseLocal();
|
|
|
+ chooseLocal(props.chooseType);
|
|
|
} else if (index === 1) {
|
|
|
uni.chooseMessageFile({
|
|
|
- type: props.chooseType || 'all',
|
|
|
+ type: props.chooseType === 'select' ? 'all' : (props.chooseType || 'all'),
|
|
|
count: props.maxUploadCount - currentUpladList.value.length,
|
|
|
success: (res) => {
|
|
|
LogUtils.printLog(TAG, 'info', 'chooseMessageFile', res);
|
|
|
@@ -359,15 +359,15 @@ function onUploadPress() {
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- chooseLocal();
|
|
|
+ chooseLocal(props.chooseType);
|
|
|
}
|
|
|
//#endif
|
|
|
//#ifndef MP
|
|
|
- chooseLocal();
|
|
|
+ chooseLocal(props.chooseType);
|
|
|
//#endif
|
|
|
|
|
|
- function chooseLocal() {
|
|
|
- switch (props.chooseType) {
|
|
|
+ function chooseLocal(type: UploaderProps['chooseType']) {
|
|
|
+ switch (type) {
|
|
|
case 'video':
|
|
|
uni.chooseVideo().then((res) => handleFiles([
|
|
|
{
|
|
|
@@ -379,6 +379,28 @@ function onUploadPress() {
|
|
|
case 'file':
|
|
|
uni.chooseFile().then((res) => handleFiles(res.tempFiles as { path: string; size: number; }[])).catch(reject);
|
|
|
break;
|
|
|
+ case 'select':
|
|
|
+ actionSheet({
|
|
|
+ title: '您想上传哪种类型的文件?',
|
|
|
+ actions: [
|
|
|
+ {
|
|
|
+ name: '照片',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '视频',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ showCancel: true,
|
|
|
+ onSelect(index, name) {
|
|
|
+ },
|
|
|
+ }).then((index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ chooseLocal('image');
|
|
|
+ } else if (index === 1) {
|
|
|
+ chooseLocal('video');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
default:
|
|
|
case 'image':
|
|
|
uni.chooseImage({
|