Browse Source

feat: 获取相册,调用api:checkDeviceCamera

TIANYONG 7 months ago
parent
commit
43df9266ee

+ 12 - 5
src/components/col-upload/index.tsx

@@ -54,6 +54,10 @@ export default defineComponent({
     disabled: {
       type: Boolean,
       default: false
+    },
+    hasDeviceAuth: {
+      type: Boolean,
+      default: true
     }
   },
   methods: {
@@ -192,11 +196,14 @@ export default defineComponent({
                 {this.tips && <p class={styles.uploaderText}>{this.tips}</p>}
               </div>
             )}
-            <ColCropper
-              disabled={this.disabled}
-              option={this.options}
-              getFile={this.getFile}
-            />
+            {
+              this.hasDeviceAuth && 
+              <ColCropper
+                disabled={this.disabled }
+                option={this.options}
+                getFile={this.getFile}
+              />              
+            }
           </div>
         ) : this.native ? (
           <div

+ 54 - 15
src/views/creation/edit/index.tsx

@@ -22,7 +22,9 @@ export default defineComponent({
       playType: '',
       desc: '',
       videoImg: '', // 视频封面
-      img: ''
+      img: '',
+      needCheckDevice: true,
+      hasDeviceAuth: false, // 有设备相机权限
     })
 
     const onSubmit = async () => {
@@ -49,7 +51,39 @@ export default defineComponent({
         //
       }
     }
-
+    // 初始化获取是否已经授权
+    const initDeviceAuth = () => {
+      postMessage(
+        {
+          api: 'checkDeviceCamera',
+          content: {
+            hideAlert: true
+          }
+        },
+        res => {
+          if (res?.content.status) {
+            state.hasDeviceAuth = true
+          }
+        }
+      )
+    }
+    // 校验是否已经授权
+    const checkDeviceAuth = () => {
+      console.log('校验app',state.needCheckDevice)
+      if (state.needCheckDevice) {
+        postMessage({ api: 'checkDeviceCamera' }, res => {
+          const { content } = res as any
+          if (content?.status) {
+            state.hasDeviceAuth = true
+          } else {
+            // 没有权限不能获取图片
+            state.hasDeviceAuth = false
+          }
+        })
+      } else {
+        state.hasDeviceAuth = true
+      }
+    }
     // 截图
     const onCropper = () => {
       postMessage(
@@ -74,6 +108,7 @@ export default defineComponent({
       });
     }
     onMounted(async () => {
+      initDeviceAuth();
       setStatusBarTextColor(false);
       try {
         const { data } = await api_userMusicDetail(state.id)
@@ -107,6 +142,7 @@ export default defineComponent({
               cropper
               tips={''}
               deletable={false}
+              needCheckDevice={true}
               v-model:modelValue={state.img}
             />
             {/* <div class={styles.tip}>选封面</div> */}
@@ -120,19 +156,22 @@ export default defineComponent({
           <div class={[styles.section, styles.sectionVideo]}>
             <img src={state.videoImg || videoBg} class={styles.videoBg} />
             <div class={styles.btnGroup}>
-              <MUploader
-                class={styles.btnImg}
-                cropper
-                tips=""
-                deletable={false}
-                onUploadChange={img => {
-                  console.log(img, 'img')
-                  state.videoImg = img
-                }}
-                options={{
-                  fixedNumber: [16, 9]
-                }}
-              />
+              <div onClick={checkDeviceAuth}>
+                <MUploader
+                  class={styles.btnImg}
+                  cropper
+                  tips=""
+                  deletable={false}
+                  hasDeviceAuth={state.hasDeviceAuth}
+                  onUploadChange={img => {
+                    console.log(img, 'img')
+                    state.videoImg = img
+                  }}
+                  options={{
+                    fixedNumber: [16, 9]
+                  }}
+                />
+              </div>
               <div class={styles.btnCropper} onClick={onCropper}>
                 视频截取封面
               </div>

+ 0 - 1
src/views/creation/index.module.less

@@ -45,7 +45,6 @@
     height: 40px;
     bottom: -40px;
     left: 0;
-    background: linear-gradient( 180deg, #444B68 0%, rgba(57,77,95,0) 100%);
     pointer-events: none;
   }
   :global {

+ 1 - 1
src/views/creation/share-model/index.tsx

@@ -231,7 +231,7 @@ export default defineComponent({
             <div class={styles.qrtips}>
               <div>温馨提示:</div>
               <p class={styles.tip}>
-                保存图片到相册或长按识别二维码进入查看喔
+                保存图片到相册后,请在微信里扫码查看
               </p>
               <img src={iconLogo} class={styles.iconLogo} />
               {/* <p class={styles.downTip}>扫码下载音乐数字课堂App</p> */}

+ 1 - 1
vite.config.ts

@@ -12,7 +12,7 @@ function resolve(dir: string) {
 // https://vitejs.dev/config/
 // https://github.com/vitejs/vite/issues/1930 .env
 // const proxyUrl = 'https://online.colexiu.com/'
-const proxyUrl = 'https://dev.colexiu.com/'
+const proxyUrl = 'https://test.colexiu.com/'
 // const proxyUrl = 'http://192.168.3.14:8000/'
 export default defineConfig({
   base: './',