li.shaoyi 5 місяців тому
батько
коміт
b46155e597

+ 1 - 1
src/packages/mobile/components/base/uploader/index.vue

@@ -1,6 +1,6 @@
 <template>
     <div class="app-uploader">
-        <span class="app-uploader__button" @click="onClickUpload" v-if="!hasPermission"></span>
+        <!-- <span class="app-uploader__button" @click="onClickUpload" v-if="!hasPermission"></span> -->
         <Uploader ref="uploaderRef" v-model="fileList" :max-count="maxCount" :max-size="5 * 1024 * 1024"
             @oversize="onOversize" :after-read="onAfterRead" @delete="onDelete" reupload />
         <Notify v-model:show="showNotify" :duration="0" :title="$t('common.tips30')" :content="$t('common.tips31')" />

+ 42 - 7
src/utils/h5plus/index.ts

@@ -1,6 +1,6 @@
 /* eslint-disable */
 import { v4 } from 'uuid'
-import { SystemInfo, ShareMessage, HttpRequestConfig, Download } from './types'
+import { SystemInfo, ShareMessage, HttpRequestConfig, Download,AndroidPermissions } from './types'
 import { urlScheme } from './constants'
 
 declare global {
@@ -518,12 +518,46 @@ export default new (class {
      * 检查运行环境的权限
      * https://www.html5plus.org/doc/zh_cn/navigator.html#plus.navigator.checkPermission
      */
-    checkPermission() {
-        this.onPlusReady((plus) => {
-            const res = plus.navigator.checkPermission('READ_EXTERNAL_STORAGE')
+    checkPermission(permissions: keyof typeof AndroidPermissions) {
+        if (this.hasPlus() && this.getSystemInfo('os') === 'Android') {
+            this.onPlusReady((plus) => {
+                const [majorVersion] = plus.os.version.split('.') // 获取系统主版本号
+
+                // 检查相册权限
+                const checkImagesPermission = () => {
+                    switch (true) {
+                        case (+majorVersion <= 12):
+                            return plus.navigator.checkPermission('android.permission.READ_EXTERNAL_STORAGE')
+                        case (+majorVersion === 13):
+                            return plus.navigator.checkPermission('android.permission.READ_MEDIA_IMAGES')
+                        default:
+                            return plus.navigator.checkPermission('android.permission.READ_MEDIA_VISUAL_USER_SELECTED')
+                    }
+                }
 
-            console.log(res)
-        })
+                // 检查视频权限
+                const checkVideoPermission = () => {
+                    switch (true) {
+                        case (+majorVersion <= 12):
+                            return plus.navigator.checkPermission('android.permission.READ_EXTERNAL_STORAGE')
+                        case (+majorVersion === 13):
+                            return plus.navigator.checkPermission('android.permission.READ_MEDIA_VIDEO')
+                        default:
+                            return plus.navigator.checkPermission('android.permission.READ_MEDIA_VISUAL_USER_SELECTED')
+                    }
+                }
+
+                switch (permissions) {
+                    case 'IMAGES':
+                        return checkImagesPermission()
+                    case 'VIDEO':
+                        return checkVideoPermission()
+                    default:
+                        return 'unknown'
+                }
+            })
+        }
+        return 'authorized'
     }
 
     /**
@@ -563,8 +597,9 @@ export default new (class {
      */
     requestPermissionReadExternalStorage(options: Partial<{ onSuccess: () => void; onError: (message: string) => void; }> = {}) {
         // https://ask.dcloud.net.cn/question/190261
+        // https://developer.android.google.cn/about/versions/14/changes/partial-photo-video-access?hl=zh-cn
         this.requestPermission({
-            permissions: ['android.permission.READ_EXTERNAL_STORAGE', 'android.permission.READ_MEDIA_IMAGES'],
+            permissions: ['android.permission.READ_EXTERNAL_STORAGE', 'android.permission.READ_MEDIA_IMAGES', 'android.permission.READ_MEDIA_VISUAL_USER_SELECTED'],
             errorMessage: '请打开存储权限',
             refuseMessage: '访问存储被拒绝',
             onSuccess: options.onSuccess,

+ 5 - 0
src/utils/h5plus/types.ts

@@ -69,4 +69,9 @@ export interface Download {
     filename: string;
     downloadedSize: number;
     totalSize: number;
+}
+
+export enum AndroidPermissions {
+    IMAGES,
+    VIDEO
 }