Showing
3 changed files
with
75 additions
and
50 deletions
| @@ -14,18 +14,8 @@ import { TrackConstants } from 'wdTracking/Index'; | @@ -14,18 +14,8 @@ import { TrackConstants } from 'wdTracking/Index'; | ||
| 14 | 14 | ||
| 15 | import { SPHelper } from 'wdKit/Index'; | 15 | import { SPHelper } from 'wdKit/Index'; |
| 16 | import { SpConstants } from 'wdConstant/Index'; | 16 | import { SpConstants } from 'wdConstant/Index'; |
| 17 | +import { photoPickerUtils} from '../../utils/PhotoPickerUtils'; | ||
| 17 | 18 | ||
| 18 | -import { abilityAccessCtrl, common, Permissions } from '@kit.AbilityKit'; | ||
| 19 | -import { picker } from '@kit.CoreFileKit'; | ||
| 20 | -import { camera, cameraPicker } from '@kit.CameraKit'; | ||
| 21 | -import { BusinessError } from '@kit.BasicServicesKit'; | ||
| 22 | - | ||
| 23 | -let mContext = getContext(this) as common.Context; | ||
| 24 | - | ||
| 25 | -const PERMISSIONS: Array<Permissions> = [ | ||
| 26 | - 'ohos.permission.READ_IMAGEVIDEO', | ||
| 27 | - 'ohos.permission.WRITE_IMAGEVIDEO' | ||
| 28 | -]; | ||
| 29 | @Entry | 19 | @Entry |
| 30 | @Component | 20 | @Component |
| 31 | struct EditUserInfoPage { | 21 | struct EditUserInfoPage { |
| @@ -93,11 +83,7 @@ struct EditUserInfoPage { | @@ -93,11 +83,7 @@ struct EditUserInfoPage { | ||
| 93 | builder: CustomDialogUI({ | 83 | builder: CustomDialogUI({ |
| 94 | itemData:['相册','拍照'], | 84 | itemData:['相册','拍照'], |
| 95 | confirmCallback:(index)=>{ | 85 | confirmCallback:(index)=>{ |
| 96 | - if (index === 0) { | ||
| 97 | - this.getPhotoPicker() | ||
| 98 | - }else { | ||
| 99 | - this.getCamera() | ||
| 100 | - } | 86 | + this.pickerSelect(index) |
| 101 | } | 87 | } |
| 102 | }), | 88 | }), |
| 103 | alignment: DialogAlignment.Bottom, | 89 | alignment: DialogAlignment.Bottom, |
| @@ -105,42 +91,23 @@ struct EditUserInfoPage { | @@ -105,42 +91,23 @@ struct EditUserInfoPage { | ||
| 105 | closeAnimation:{duration:0} | 91 | closeAnimation:{duration:0} |
| 106 | }) | 92 | }) |
| 107 | 93 | ||
| 108 | - async getPhotoPicker(){ | ||
| 109 | - ///权限查询 | ||
| 110 | - const context = getContext(this) as common.UIAbilityContext; | ||
| 111 | - const atManager = abilityAccessCtrl.createAtManager(); | ||
| 112 | - await atManager.requestPermissionsFromUser(context, PERMISSIONS); | ||
| 113 | - | ||
| 114 | - let PhotoSelectOptions = new picker.PhotoSelectOptions(); | ||
| 115 | - PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型 | ||
| 116 | - PhotoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目 | ||
| 117 | - let photoPicker = new picker.PhotoViewPicker(); // 使用图库选择器对象前,需要先创建PhotoViewPicker实例 | ||
| 118 | - photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { | ||
| 119 | - if (PhotoSelectResult !== null && PhotoSelectResult !== | ||
| 120 | - undefined) { | ||
| 121 | - // 接口采用callback异步返回形式,返回PhotoSelectResult对象,故进行下一步操作前要先判断是否已经成功返回PhotoSelectResult对象了 | ||
| 122 | - this.headerImg = PhotoSelectResult['photoUris'][0] | ||
| 123 | - } | ||
| 124 | - }) | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - async getCamera(){ | ||
| 128 | - try { | ||
| 129 | - let pickerProfile: cameraPicker.PickerProfile = { | ||
| 130 | - cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK | ||
| 131 | - }; | ||
| 132 | - let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(mContext, | ||
| 133 | - [cameraPicker.PickerMediaType.PHOTO, cameraPicker.PickerMediaType.VIDEO], pickerProfile); | ||
| 134 | - if (pickerResult['resultCode'] === 0) { | ||
| 135 | - this.headerImg = pickerResult['resultUri'] | ||
| 136 | - } | ||
| 137 | - console.log("the pick pickerResult is:" + JSON.stringify(pickerResult)); | ||
| 138 | - } catch (error) { | ||
| 139 | - let err = error as BusinessError; | ||
| 140 | - console.error(`the pick call failed. error code: ${err.code}`); | 94 | + pickerSelect(index:number){ |
| 95 | + if (index === 0) { | ||
| 96 | + photoPickerUtils.getPhotoPicker().then(value => { | ||
| 97 | + if (value.length > 0) { | ||
| 98 | + this.headerImg = value | ||
| 99 | + } | ||
| 100 | + }) | ||
| 101 | + }else { | ||
| 102 | + photoPickerUtils.getCamera().then(value => { | ||
| 103 | + if (value.length > 0) { | ||
| 104 | + this.headerImg = value | ||
| 105 | + } | ||
| 106 | + }) | ||
| 141 | } | 107 | } |
| 142 | } | 108 | } |
| 143 | 109 | ||
| 110 | + | ||
| 144 | aboutToAppear() { | 111 | aboutToAppear() { |
| 145 | let userType = SPHelper.default.getSync(SpConstants.USER_Type,"") as string | 112 | let userType = SPHelper.default.getSync(SpConstants.USER_Type,"") as string |
| 146 | if (userType && userType.length > 0) { | 113 | if (userType && userType.length > 0) { |
| 1 | +import { abilityAccessCtrl, common, Permissions } from '@kit.AbilityKit'; | ||
| 2 | +import { picker } from '@kit.CoreFileKit'; | ||
| 3 | +import { camera, cameraPicker } from '@kit.CameraKit'; | ||
| 4 | +import { BusinessError } from '@kit.BasicServicesKit'; | ||
| 5 | + | ||
| 6 | +let mContext = getContext(this) as common.Context; | ||
| 7 | + | ||
| 8 | +const PERMISSIONS: Array<Permissions> = [ | ||
| 9 | + 'ohos.permission.READ_IMAGEVIDEO', | ||
| 10 | +]; | ||
| 11 | + | ||
| 12 | +export class PhotoPickerUtils { | ||
| 13 | + | ||
| 14 | + async getPhotoPicker(){ | ||
| 15 | + this.pickerPermissions() | ||
| 16 | + | ||
| 17 | + let PhotoSelectOptions = new picker.PhotoSelectOptions(); | ||
| 18 | + PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型 | ||
| 19 | + PhotoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目 | ||
| 20 | + let photoPicker = new picker.PhotoViewPicker(); // 使用图库选择器对象前,需要先创建PhotoViewPicker实例 | ||
| 21 | + | ||
| 22 | + return new Promise<string>((success, fail) => { | ||
| 23 | + photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => { | ||
| 24 | + if (PhotoSelectResult !== null && PhotoSelectResult !== | ||
| 25 | + undefined) { | ||
| 26 | + // 接口采用callback异步返回形式,返回PhotoSelectResult对象,故进行下一步操作前要先判断是否已经成功返回PhotoSelectResult对象了 | ||
| 27 | + success(PhotoSelectResult['photoUris'][0]) | ||
| 28 | + } | ||
| 29 | + }) | ||
| 30 | + }) | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + async getCamera(){ | ||
| 34 | + this.pickerPermissions() | ||
| 35 | + | ||
| 36 | + let pickerProfile: cameraPicker.PickerProfile = { | ||
| 37 | + cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK | ||
| 38 | + }; | ||
| 39 | + let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(mContext, | ||
| 40 | + [cameraPicker.PickerMediaType.PHOTO, cameraPicker.PickerMediaType.VIDEO], pickerProfile); | ||
| 41 | + | ||
| 42 | + return new Promise<string>((success, fail) => { | ||
| 43 | + if (pickerResult['resultCode'] === 0) { | ||
| 44 | + success(pickerResult['resultUri']) | ||
| 45 | + } | ||
| 46 | + }) | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + async pickerPermissions(){ | ||
| 50 | + ///权限查询 | ||
| 51 | + const context = getContext(this) as common.UIAbilityContext; | ||
| 52 | + const atManager = abilityAccessCtrl.createAtManager(); | ||
| 53 | + await atManager.requestPermissionsFromUser(context, PERMISSIONS); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +export const photoPickerUtils: PhotoPickerUtils = new PhotoPickerUtils(); |
| @@ -63,7 +63,7 @@ struct LaunchAdvertisingPage { | @@ -63,7 +63,7 @@ struct LaunchAdvertisingPage { | ||
| 63 | //显示视频播放 | 63 | //显示视频播放 |
| 64 | Video({ | 64 | Video({ |
| 65 | src: this.defaultModel.bootVideoUrl, | 65 | src: this.defaultModel.bootVideoUrl, |
| 66 | - previewUri: this.defaultModel.bootVideoScreenUrl, | 66 | + // previewUri: this.defaultModel.bootVideoScreenUrl, |
| 67 | controller: this.controller | 67 | controller: this.controller |
| 68 | }).controls(false) | 68 | }).controls(false) |
| 69 | .autoPlay(true) | 69 | .autoPlay(true) |
-
Please register or login to post a comment