wangliang_wd

feat:调整相机调用库

@@ -15,6 +15,7 @@ import { TrackConstants } from 'wdTracking/Index'; @@ -15,6 +15,7 @@ import { TrackConstants } from 'wdTracking/Index';
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 import { photoPickerUtils} from '../../utils/PhotoPickerUtils';
  18 +import { cameraPickerUtils } from '../../utils/CameraPickerUtils';
18 19
19 @Entry 20 @Entry
20 @Component 21 @Component
@@ -104,7 +105,7 @@ struct EditUserInfoPage { @@ -104,7 +105,7 @@ struct EditUserInfoPage {
104 } 105 }
105 }) 106 })
106 }else { 107 }else {
107 - photoPickerUtils.getCamera().then(value => { 108 + cameraPickerUtils.getCamera().then(value => {
108 if (value.length > 0) { 109 if (value.length > 0) {
109 this.headerImg = value 110 this.headerImg = value
110 } 111 }
  1 +import { abilityAccessCtrl, common, Permissions } from '@kit.AbilityKit';
  2 +import { camera, cameraPicker as picker } from '@kit.CameraKit';
  3 +let mContext = getContext(this) as common.Context;
  4 +
  5 +const PERMISSIONS: Array<Permissions> = [
  6 + 'ohos.permission.READ_IMAGEVIDEO',
  7 +];
  8 +
  9 +export class CameraPickerUtils {
  10 + async getCamera(){
  11 + this.pickerPermissions()
  12 +
  13 + let pickerProfile: picker.PickerProfile = {
  14 + cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK
  15 + };
  16 + let pickerResult: picker.PickerResult = await picker.pick(mContext,
  17 + [picker.PickerMediaType.PHOTO], pickerProfile);
  18 +
  19 + return new Promise<string>((success, fail) => {
  20 + if (pickerResult['resultCode'] === 0) {
  21 + success(pickerResult['resultUri'])
  22 + }
  23 + })
  24 + }
  25 +
  26 + async pickerPermissions(){
  27 + ///权限查询
  28 + const context = getContext(this) as common.UIAbilityContext;
  29 + const atManager = abilityAccessCtrl.createAtManager();
  30 + await atManager.requestPermissionsFromUser(context, PERMISSIONS);
  31 + }
  32 +
  33 +}
  34 +
  35 +export const cameraPickerUtils: CameraPickerUtils = new CameraPickerUtils();
@@ -30,21 +30,21 @@ export class PhotoPickerUtils { @@ -30,21 +30,21 @@ export class PhotoPickerUtils {
30 }) 30 })
31 } 31 }
32 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 - } 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 48
49 async pickerPermissions(){ 49 async pickerPermissions(){
50 ///权限查询 50 ///权限查询