Browse Source

Merge branch 'iteration-login'

lex 1 year ago
parent
commit
c057c55d56

+ 0 - 0
src/components/card-type/video-player /index.module.less → src/components/card-type/video-player/index.module.less


+ 0 - 0
src/components/card-type/video-player /index.tsx → src/components/card-type/video-player/index.tsx


+ 0 - 0
src/views/natural-resources/components/my-resources /index.module.less → src/views/natural-resources/components/my-resources/index.module.less


+ 0 - 0
src/views/natural-resources/components/my-resources /index.tsx → src/views/natural-resources/components/my-resources/index.tsx


+ 0 - 0
src/views/natural-resources/components/my-resources /search-group-resources.tsx → src/views/natural-resources/components/my-resources/search-group-resources.tsx


+ 0 - 0
src/views/natural-resources/components/my-resources /upload-modal/index.module.less → src/views/natural-resources/components/my-resources/upload-modal/index.module.less


+ 0 - 0
src/views/natural-resources/components/my-resources /upload-modal/index.tsx → src/views/natural-resources/components/my-resources/upload-modal/index.tsx


+ 73 - 70
src/views/natural-resources/components/my-resources /upload-modal/upload-file.tsx → src/views/natural-resources/components/my-resources/upload-modal/upload-file.tsx

@@ -222,7 +222,7 @@ export default defineComponent({
       reader.readAsDataURL(img);
     };
 
-    const onFinish = (options: any) => {
+    const onFinish = async (options: any) => {
       const url = ossUploadUrl + state.key;
       const type = formatUrlType(url);
       let coverImg = '';
@@ -232,8 +232,8 @@ export default defineComponent({
         coverImg = PageEnum.SONG_DEFAULT_COVER;
       } else if (type === 'VIDEO') {
         // 获取视频封面图
-        // await getVideoCoverImg();
-        coverImg = 'https://gyt.ks3-cn-beijing.ksyuncs.com/1688997532875.png';
+        await getVideoCoverImg();
+        // coverImg = 'https://gyt.ks3-cn-beijing.ksyuncs.com/1688997532875.png';
       }
       emit('update:fileList', url);
       emit('readFileInputEventAsArrayBuffer', tempFiileBuffer.value);
@@ -248,77 +248,80 @@ export default defineComponent({
     };
 
     // 获取文件流
-    // const base64ImgtoFile = (dataurl: string, filename = 'file') => {
-    //   const arr: any = dataurl.split(',');
-    //   const mime = arr[0].match(/:(.*?);/)[1];
-    //   const suffix = mime.split('/')[1];
-    //   const bstr = atob(arr[1]);
-    //   let n = bstr.length;
-    //   const u8arr = new Uint8Array(n);
-    //   while (n--) {
-    //     u8arr[n] = bstr.charCodeAt(n);
-    //   }
-    //   return new File([u8arr], `${filename}.${suffix}`, {
-    //     type: mime
-    //   });
-    // };
+    const base64ImgtoFile = (dataurl: string, filename = 'file') => {
+      const arr: any = dataurl.split(',');
+      const mime = arr[0].match(/:(.*?);/)[1];
+      const suffix = mime.split('/')[1];
+      const bstr = atob(arr[1]);
+      let n = bstr.length;
+      const u8arr = new Uint8Array(n);
+      while (n--) {
+        u8arr[n] = bstr.charCodeAt(n);
+      }
+      return new File([u8arr], `${filename}.${suffix}`, {
+        type: mime
+      });
+    };
 
-    // const getVideoMsg = (file: any) => {
-    //   return new Promise(resolve => {
-    //     let dataURL = '';
-    //     const videoElement = document.createElement('video');
-    //     videoElement.currentTime = 1;
-    //     videoElement.src = URL.createObjectURL(file);
-    //     videoElement.addEventListener('loadeddata', function () {
-    //       const canvas: any = document.createElement('canvas'),
-    //         width = videoElement.videoWidth, //canvas的尺寸和图片一样
-    //         height = videoElement.videoHeight;
-    //       canvas.width = width;
-    //       canvas.height = height;
-    //       canvas.getContext('2d').drawImage(videoElement, 0, 0, width, height); //绘制canvas
-    //       dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
-    //       resolve(dataURL);
-    //     });
-    //   });
-    // };
+    const getVideoMsg = (file: any) => {
+      return new Promise(resolve => {
+        let dataURL = '';
+        const videoElement = document.createElement('video');
+        videoElement.currentTime = 1;
+        videoElement.src = URL.createObjectURL(file);
+        videoElement.addEventListener('loadeddata', function () {
+          const canvas: any = document.createElement('canvas'),
+            width = videoElement.videoWidth, //canvas的尺寸和图片一样
+            height = videoElement.videoHeight;
+          canvas.width = width;
+          canvas.height = height;
+          canvas.getContext('2d').drawImage(videoElement, 0, 0, width, height); //绘制canvas
+          dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
+          resolve(dataURL);
+        });
+      });
+    };
 
-    // const getVideoCoverImg = async () => {
-    //   try {
-    //     btnLoading.value = true;
-    //     const imgBlob: any = await getVideoMsg(tempFiileBuffer.value);
-    //     const fileName = `${props.path}${Date.now() + '.png'}`;
-    //     const obj = {
-    //       filename: fileName,
-    //       bucketName: props.bucketName,
-    //       postData: {
-    //         filename: fileName,
-    //         acl: 'public-read',
-    //         key: fileName,
-    //         unknowValueField: []
-    //       }
-    //     };
-    //     const { data } = await policy(obj);
+    const getVideoCoverImg = async () => {
+      try {
+        btnLoading.value = true;
+        const imgBlob: any = await getVideoMsg(tempFiileBuffer.value);
+        console.log(imgBlob, 'downloading');
+        const fileName = `${props.path}${Date.now() + '.jpeg'}`;
+        const obj = {
+          filename: fileName,
+          bucketName: props.bucketName,
+          postData: {
+            filename: fileName,
+            acl: 'public-read',
+            key: fileName,
+            unknowValueField: []
+          }
+        };
+        const { data } = await policy(obj);
 
-    //     const fileParams = {
-    //       policy: data.policy,
-    //       signature: data.signature,
-    //       key: fileName,
-    //       KSSAccessKeyId: data.kssAccessKeyId,
-    //       name: fileName
-    //     } as any;
-    //     const formData = new FormData();
-    //     for (const key in fileParams) {
-    //       formData.append(key, fileParams[key]);
-    //     }
-    //     formData.append('file', base64ImgtoFile(imgBlob));
-    //     await axios.post(ossUploadUrl, formData);
+        const fileParams = {
+          policy: data.policy,
+          signature: data.signature,
+          key: fileName,
+          KSSAccessKeyId: data.kssAccessKeyId,
+          name: fileName
+        } as any;
+        const formData = new FormData();
+        for (const key in fileParams) {
+          formData.append(key, fileParams[key]);
+        }
+        console.log(base64ImgtoFile(imgBlob), 'base64ImgtoFile(imgBlob)');
+        formData.append('file', base64ImgtoFile(imgBlob), fileName);
+        await axios.post(ossUploadUrl, formData);
 
-    //     const url = ossUploadUrl + fileName;
-    //     return url;
-    //   } finally {
-    //     btnLoading.value = false;
-    //   }
-    // };
+        const url = ossUploadUrl + fileName;
+        console.log(url, '12312312');
+        return url;
+      } finally {
+        btnLoading.value = false;
+      }
+    };
 
     const onRemove = async () => {
       emit('update:fileList', '');