Showing
3 changed files
with
19 additions
and
32 deletions
| @@ -13,6 +13,7 @@ import { CommonConstants } from 'wdConstant/Index'; | @@ -13,6 +13,7 @@ import { CommonConstants } from 'wdConstant/Index'; | ||
| 13 | import { ProcessUtils } from 'wdRouter/Index'; | 13 | import { ProcessUtils } from 'wdRouter/Index'; |
| 14 | import { TrackConstants, TrackingButton, TrackingPageBrowse } from 'wdTracking/Index'; | 14 | import { TrackConstants, TrackingButton, TrackingPageBrowse } from 'wdTracking/Index'; |
| 15 | import inputMethod from '@ohos.inputMethod'; | 15 | import inputMethod from '@ohos.inputMethod'; |
| 16 | +import { photoPickerUtils } from '../utils/PhotoPickerUtils'; | ||
| 16 | 17 | ||
| 17 | const TAG = 'FeedBackActivity' | 18 | const TAG = 'FeedBackActivity' |
| 18 | 19 | ||
| @@ -163,15 +164,15 @@ export struct FeedBackActivity { | @@ -163,15 +164,15 @@ export struct FeedBackActivity { | ||
| 163 | GridCol({ | 164 | GridCol({ |
| 164 | }) { | 165 | }) { |
| 165 | if(1 == feedbackImageItem.itemType){ | 166 | if(1 == feedbackImageItem.itemType){ |
| 166 | - // Image($r('app.media.feekback_add')) | ||
| 167 | - // .width(60) | ||
| 168 | - // .height(60) | ||
| 169 | - // .onClick(async (event: ClickEvent) => { | ||
| 170 | - // if(await FastClickUtil.isMinDelayTime()){ | ||
| 171 | - // return | ||
| 172 | - // } | ||
| 173 | - // this.callFilePickerSelectImage(); | ||
| 174 | - // }) | 167 | + Image($r('app.media.feekback_add')) |
| 168 | + .width(60) | ||
| 169 | + .height(60) | ||
| 170 | + .onClick(async (event: ClickEvent) => { | ||
| 171 | + if(await FastClickUtil.isMinDelayTime()){ | ||
| 172 | + return | ||
| 173 | + } | ||
| 174 | + this.callFilePickerSelectImage(); | ||
| 175 | + }) | ||
| 175 | }else{ | 176 | }else{ |
| 176 | Stack({alignContent: Alignment.TopEnd}) { | 177 | Stack({alignContent: Alignment.TopEnd}) { |
| 177 | Image(feedbackImageItem.picPath) | 178 | Image(feedbackImageItem.picPath) |
| @@ -347,20 +348,9 @@ export struct FeedBackActivity { | @@ -347,20 +348,9 @@ export struct FeedBackActivity { | ||
| 347 | async callFilePickerSelectImage(): Promise<void> { // async 用于申明一个 function 是异步的 | 348 | async callFilePickerSelectImage(): Promise<void> { // async 用于申明一个 function 是异步的 |
| 348 | let array: string[]; | 349 | let array: string[]; |
| 349 | try { | 350 | try { |
| 350 | - // 设置photoPicker的参数 | ||
| 351 | - let PhotoSelectOptions = new picker.PhotoSelectOptions(); | ||
| 352 | - PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型 | ||
| 353 | - let max = 3-this.pics.length+1 | ||
| 354 | - PhotoSelectOptions.maxSelectNumber = max; // 选择媒体文件的最大数目 | ||
| 355 | let mediaFlag = false; | 351 | let mediaFlag = false; |
| 356 | - let photoPicker = new picker.PhotoViewPicker(); // 使用图库选择器对象前,需要先创建PhotoViewPicker实例 | ||
| 357 | - photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { | ||
| 358 | - Logger.info(TAG, 'PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); // 日志中记录成功信息 | ||
| 359 | - if (PhotoSelectResult !== null && PhotoSelectResult !== undefined) { // 接口采用callback异步返回形式,返回PhotoSelectResult对象,故进行下一步操作前要先判断是否已经成功返回PhotoSelectResult对象了 | ||
| 360 | - | ||
| 361 | - // PhotoSelectResult为返回的结果集。 | ||
| 362 | - // 其中包含Array<string>类型的photoUris,为返回图库选择后的媒体文件的uri数组;还包含boolean类型的isOriginalPhoto,指示返回图库选择后的媒体文件是否为原图。 | ||
| 363 | - // 声明变量array,其取值为PhotoSelectResult中的数组。 | 352 | + photoPickerUtils.getPhotoPicker(3).then(PhotoSelectResult => { |
| 353 | + if (PhotoSelectResult) { | ||
| 364 | array = PhotoSelectResult['photoUris']; | 354 | array = PhotoSelectResult['photoUris']; |
| 365 | let beforeLen = this.pics.length + array.length; | 355 | let beforeLen = this.pics.length + array.length; |
| 366 | let totalLen = this.pics.length+array.length; | 356 | let totalLen = this.pics.length+array.length; |
| @@ -396,9 +386,6 @@ export struct FeedBackActivity { | @@ -396,9 +386,6 @@ export struct FeedBackActivity { | ||
| 396 | this.getFilenameByUriForMedia(array); | 386 | this.getFilenameByUriForMedia(array); |
| 397 | } | 387 | } |
| 398 | }) | 388 | }) |
| 399 | - .catch((err: BusinessError) => { | ||
| 400 | - Logger.error(TAG, 'PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); | ||
| 401 | - }); | ||
| 402 | } catch (err) { | 389 | } catch (err) { |
| 403 | Logger.error(TAG, 'PhotoViewPicker failed with err: ' + err); | 390 | Logger.error(TAG, 'PhotoViewPicker failed with err: ' + err); |
| 404 | } | 391 | } |
| @@ -98,9 +98,9 @@ struct EditUserInfoPage { | @@ -98,9 +98,9 @@ struct EditUserInfoPage { | ||
| 98 | 98 | ||
| 99 | pickerSelect(index:number){ | 99 | pickerSelect(index:number){ |
| 100 | if (index === 0) { | 100 | if (index === 0) { |
| 101 | - photoPickerUtils.getPhotoPicker().then(value => { | ||
| 102 | - if (value.length > 0) { | ||
| 103 | - this.headerImg = value | 101 | + photoPickerUtils.getPhotoPicker(1).then(value => { |
| 102 | + if (value) { | ||
| 103 | + this.headerImg = value['photoUris'][0] | ||
| 104 | } | 104 | } |
| 105 | }) | 105 | }) |
| 106 | }else { | 106 | }else { |
| @@ -11,20 +11,20 @@ const PERMISSIONS: Array<Permissions> = [ | @@ -11,20 +11,20 @@ const PERMISSIONS: Array<Permissions> = [ | ||
| 11 | 11 | ||
| 12 | export class PhotoPickerUtils { | 12 | export class PhotoPickerUtils { |
| 13 | 13 | ||
| 14 | - async getPhotoPicker(){ | 14 | + async getPhotoPicker(maxSelectNumber:number){ |
| 15 | this.pickerPermissions() | 15 | this.pickerPermissions() |
| 16 | 16 | ||
| 17 | let PhotoSelectOptions = new picker.PhotoSelectOptions(); | 17 | let PhotoSelectOptions = new picker.PhotoSelectOptions(); |
| 18 | PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型 | 18 | PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型 |
| 19 | - PhotoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目 | 19 | + PhotoSelectOptions.maxSelectNumber = maxSelectNumber; // 选择媒体文件的最大数目 |
| 20 | let photoPicker = new picker.PhotoViewPicker(); // 使用图库选择器对象前,需要先创建PhotoViewPicker实例 | 20 | let photoPicker = new picker.PhotoViewPicker(); // 使用图库选择器对象前,需要先创建PhotoViewPicker实例 |
| 21 | 21 | ||
| 22 | - return new Promise<string>((success, fail) => { | 22 | + return new Promise<picker.PhotoSelectResult>((success, fail) => { |
| 23 | photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { | 23 | photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { |
| 24 | if (PhotoSelectResult !== null && PhotoSelectResult !== | 24 | if (PhotoSelectResult !== null && PhotoSelectResult !== |
| 25 | undefined) { | 25 | undefined) { |
| 26 | // 接口采用callback异步返回形式,返回PhotoSelectResult对象,故进行下一步操作前要先判断是否已经成功返回PhotoSelectResult对象了 | 26 | // 接口采用callback异步返回形式,返回PhotoSelectResult对象,故进行下一步操作前要先判断是否已经成功返回PhotoSelectResult对象了 |
| 27 | - success(PhotoSelectResult['photoUris'][0]) | 27 | + success(PhotoSelectResult) |
| 28 | } | 28 | } |
| 29 | }) | 29 | }) |
| 30 | }) | 30 | }) |
-
Please register or login to post a comment