Procházet zdrojové kódy

fix: 23982 (v1.1.0全景看看)管理中心-我的素材-全景图模块上传非全景图失败

任一存 před 4 roky
rodič
revize
0659b9cdce
2 změnil soubory, kde provedl 46 přidání a 30 odebrání
  1. 21 29
      src/utils/file.js
  2. 25 1
      src/views/material/pano/index.vue

+ 21 - 29
src/utils/file.js

@@ -106,35 +106,27 @@ export const blobToBase64 = function (blob) {
  * 获取图片文件尺寸
  * 获取图片文件尺寸
  * @param {*} file 
  * @param {*} file 
  */
  */
-export const getImgWH = (data) => {
-    let file = data.file
-
-    return new Promise((resolve) => {
-        var reader = new FileReader();
-        //读取图片文件
-        reader.readAsDataURL(file);
-        reader.onload = function (e) {
-            //初始化JavaScript图片对象
-            var image = new Image();
-            //FileReader获得Base64字符串
-            image.src = e.target.result;
-            image.onload = function () {
-                //获得图片高宽
-                var height = this.height;
-                var width = this.width;
-                resolve({
-                    WH: {
-                        height,
-                        width
-                    },
-                    list:data.list,
-                    file
-                })
-            };
-        }
-    })
-
-
+export const getImgWH = (file) => {
+  return new Promise((resolve) => {
+    var reader = new FileReader()
+    //读取图片文件
+    reader.readAsDataURL(file)
+    reader.onload = function (e) {
+      //初始化JavaScript图片对象
+      var image = new Image()
+      //FileReader获得Base64字符串
+      image.src = e.target.result
+      image.onload = function () {
+        //获得图片高宽
+        var height = this.height
+        var width = this.width
+        resolve({
+          height,
+          width
+        })
+      }
+    }
+  })
 }
 }
 
 
 
 

+ 25 - 1
src/views/material/pano/index.vue

@@ -407,7 +407,7 @@ export default {
       this.$refs['image-previewer'].show(index)
       this.$refs['image-previewer'].show(index)
     },
     },
     onFileChange(e) {
     onFileChange(e) {
-      e.files.forEach((eachFile, i) => {
+      e.files.forEach(async (eachFile, i) => {
         if (
         if (
           eachFile.name.toLowerCase().indexOf("jpeg") <= -1 &&
           eachFile.name.toLowerCase().indexOf("jpeg") <= -1 &&
           eachFile.name.toLowerCase().indexOf("jpg") <= -1
           eachFile.name.toLowerCase().indexOf("jpg") <= -1
@@ -431,6 +431,30 @@ export default {
           return;
           return;
         }
         }
 
 
+        let WHRate = null
+        try {
+          const {width, height} = await getImgWH(eachFile)
+          WHRate = width / height
+        } catch(e) {
+          console.error('获取图像宽高失败:', e)
+          setTimeout(() => {
+            this.$msg({
+              message: `“${eachFile.name}”格式错误,请上传2:1、120MB以内、jpg格式的全景图片`,
+              type: "error",
+            });
+          }, i * 100);
+          return
+        }
+        if (WHRate !== 2) {
+          setTimeout(() => {
+            this.$msg({
+              message: `“${eachFile.name}”格式错误,请上传2:1、120MB以内、jpg格式的全景图片`,
+              type: "error",
+            });
+          }, i * 100);
+          return
+        }
+
         let itemInUploadList = {
         let itemInUploadList = {
           title: eachFile.name,
           title: eachFile.name,
           ifKnowProgress: true,
           ifKnowProgress: true,