选择多张图片

This commit is contained in:
XiuYun CHEN 2025-08-18 16:21:56 +08:00
parent f1032ddef1
commit 110512d9cb
3 changed files with 75 additions and 25 deletions

View File

@ -871,14 +871,20 @@ export struct ChatP2PPage {
},
onDidClickImage: () => {
this.showOperationView = false
MediaUtils.showImageVideoPicker().then((result) => {
if (result.errorMsg == null && result.uri) {
if (result.type === photoAccessHelper.PhotoType.IMAGE) {
this.chatViewModel.sendImageMessage(result.uri);
} else if (result.type === photoAccessHelper.PhotoType.VIDEO) {
this.chatViewModel.sendVideoMessage(result.uri, result.duration, result.width, result.height);
}
MediaUtils.showImageVideoPicker().then((results) => {
if(results!=null&&results.length>0)
{
results.forEach(result=>{
if (result.errorMsg == null && result.uri) {
if (result.type === photoAccessHelper.PhotoType.IMAGE) {
this.chatViewModel.sendImageMessage(result.uri);
} else if (result.type === photoAccessHelper.PhotoType.VIDEO) {
this.chatViewModel.sendVideoMessage(result.uri, result.duration, result.width, result.height);
}
}
})
}
})
},
onDidClickAudio: () => {
@ -1018,14 +1024,26 @@ export struct ChatP2PPage {
})
} else if (data.type == NEChatMoreOperationType.Image) {
this.showOperationView = false
MediaUtils.showImageVideoPicker().then((result) => {
if (result.errorMsg == null && result.uri) {
if (result.type === photoAccessHelper.PhotoType.IMAGE) {
this.chatViewModel.sendImageMessage(result.uri);
} else if (result.type === photoAccessHelper.PhotoType.VIDEO) {
this.chatViewModel.sendVideoMessage(result.uri, result.duration, result.width, result.height);
}
MediaUtils.showImageVideoPicker().then((results) => {
if(results!=null&&results.length>0)
{
results.forEach(result=>{
if (result.errorMsg == null && result.uri) {
if (result.type === photoAccessHelper.PhotoType.IMAGE) {
this.chatViewModel.sendImageMessage(result.uri);
} else if (result.type === photoAccessHelper.PhotoType.VIDEO) {
this.chatViewModel.sendVideoMessage(result.uri, result.duration, result.width, result.height);
}
}
})
}
// if (result.errorMsg == null && result.uri) {
// if (result.type === photoAccessHelper.PhotoType.IMAGE) {
// this.chatViewModel.sendImageMessage(result.uri);
// } else if (result.type === photoAccessHelper.PhotoType.VIDEO) {
// this.chatViewModel.sendVideoMessage(result.uri, result.duration, result.width, result.height);
// }
// }
})
}

View File

@ -778,15 +778,15 @@ export struct ChatTeamPage {
},
onDidClickImage: () => {
this.showOperationView = false
MediaUtils.showImageVideoPicker().then((result) => {
if (result.errorMsg == null && result.uri) {
if (result.type === photoAccessHelper.PhotoType.IMAGE) {
this.chatViewModel.sendImageMessage(result.uri);
} else if (result.type === photoAccessHelper.PhotoType.VIDEO) {
this.chatViewModel.sendVideoMessage(result.uri, result.duration, result.width, result.height);
}
}
})
// MediaUtils.showImageVideoPicker().then((result) => {
// if (result.errorMsg == null && result.uri) {
// if (result.type === photoAccessHelper.PhotoType.IMAGE) {
// this.chatViewModel.sendImageMessage(result.uri);
// } else if (result.type === photoAccessHelper.PhotoType.VIDEO) {
// this.chatViewModel.sendVideoMessage(result.uri, result.duration, result.width, result.height);
// }
// }
// })
},
onDidClickAudio: () => {
let context = getContext(this) as common.UIAbilityContext

View File

@ -57,6 +57,38 @@ export class MediaUtils {
});
return result;
}
static async showMediaPickerMore(mimeType: photoAccessHelper.PhotoViewMIMETypes): Promise<SelectResult[]> {
console.log("net ease show photo picker");
const result: SelectResult[] = await new Promise((resolve: Function) => {
const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
// 过滤选择媒体文件类型为IMAGE
photoSelectOptions.MIMEType = mimeType;
// 选择媒体文件的最大数目
photoSelectOptions.maxSelectNumber = 5;
const photoViewPicker = new photoAccessHelper.PhotoViewPicker();
photoViewPicker.select(photoSelectOptions)
.then(async (photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
const context = getContext(photoSelectOptions)
const uri = photoSelectResult.photoUris;
let selectResult:SelectResult[]=[]
// const uri = photoSelectResult.photoUris[0];
await uri.forEach(async values=>{
selectResult.push(await MediaUtils.getMediaInfo(context, values))
})
// const selectResult = MediaUtils.getMediaInfo(context, uri)
resolve(selectResult);
})
.catch((err: BusinessError) => {
console.error(`net ease Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
const selectResult = new SelectResult();
selectResult.errorMsg =
`net ease Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`;
resolve(selectResult);
})
});
return result;
}
// 显示相册(图片)选择器
static async showImagePicker(): Promise<SelectResult> {
@ -73,9 +105,9 @@ export class MediaUtils {
}
// 显示相册(图片+视频)选择器
static async showImageVideoPicker(): Promise<SelectResult> {
static async showImageVideoPicker(): Promise<SelectResult[]> {
console.log("net ease show photo picker");
const result: SelectResult = await MediaUtils.showMediaPicker(photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE)
const result: SelectResult[] = await MediaUtils.showMediaPickerMore(photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE)
return result;
}