import permision from "@/utils/permission.js"

const {platform} = uni.getSystemInfoSync()

//判断相册是否开启
 async function album(){
  if (platform == 'ios') {
    var result = await permision.judgeIosPermission('photoLibrary')
  } else {
    var result = await permision.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE')
  }
  if (result == true || result == 1) {
    return true
  } else {
    if (result === 0) {
    // await  permision.gotoAppPermissionSetting()
    } else {
      uni.showModal({
        content: '相册权限未开启，是否去授权',
        success: async (res) => {
          if (res.confirm) {
            await permision.gotoAppPermissionSetting()
          }
        }
      });
    }
    return false
  }
}

//判断摄像头是否开启
 async function camera(){
  if (platform == 'ios') {
    var result = await permision.judgeIosPermission('camera')
  } else {
    var result = await permision.requestAndroidPermission('android.permission.CAMERA')
  }
  if (result == true || result == 1) {
    return true
  } else {
    if (result === 0) {
    // await  permision.gotoAppPermissionSetting()
    } else {
      uni.showModal({
        content: '摄像头权限未开启，是否去授权',
        success: async (res) => {
          if (res.confirm) {
            await permision.gotoAppPermissionSetting()
          }
        }
      });
    }
    return false
  }
}
module.exports = {
	album,
  camera
}
