From 110512d9cb2c58adbbc44bde0e71866137f61edc Mon Sep 17 00:00:00 2001 From: XiuYun CHEN Date: Mon, 18 Aug 2025 16:21:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=A4=9A=E5=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chatkit_ui/src/main/ets/pages/ChatP2PPage.ets | 46 +++++++++++++------ .../src/main/ets/pages/ChatTeamPage.ets | 18 ++++---- common/src/main/ets/utils/MediaUtils.ets | 36 ++++++++++++++- 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/chatkit_ui/src/main/ets/pages/ChatP2PPage.ets b/chatkit_ui/src/main/ets/pages/ChatP2PPage.ets index 988117c..8397f44 100644 --- a/chatkit_ui/src/main/ets/pages/ChatP2PPage.ets +++ b/chatkit_ui/src/main/ets/pages/ChatP2PPage.ets @@ -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); + // } + // } }) } diff --git a/chatkit_ui/src/main/ets/pages/ChatTeamPage.ets b/chatkit_ui/src/main/ets/pages/ChatTeamPage.ets index 1422548..4a1f029 100644 --- a/chatkit_ui/src/main/ets/pages/ChatTeamPage.ets +++ b/chatkit_ui/src/main/ets/pages/ChatTeamPage.ets @@ -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 diff --git a/common/src/main/ets/utils/MediaUtils.ets b/common/src/main/ets/utils/MediaUtils.ets index c86467b..f312423 100644 --- a/common/src/main/ets/utils/MediaUtils.ets +++ b/common/src/main/ets/utils/MediaUtils.ets @@ -57,6 +57,38 @@ export class MediaUtils { }); return result; } + static async showMediaPickerMore(mimeType: photoAccessHelper.PhotoViewMIMETypes): Promise { + 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 { @@ -73,9 +105,9 @@ export class MediaUtils { } // 显示相册(图片+视频)选择器 - static async showImageVideoPicker(): Promise { + static async showImageVideoPicker(): Promise { 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; }