guojy преди 1 година
родител
ревизия
ebd1c4a64d
променени са 2 файла, в които са добавени 85 реда и са изтрити 25 реда
  1. 30 1
      src/components/common/OssUploader.vue
  2. 55 24
      src/components/common/vue-img-cropper.vue

+ 30 - 1
src/components/common/OssUploader.vue

@@ -182,8 +182,9 @@ export default {
       } else {
         ctx.drawImage(img, 0, 0, width, height)
       }
+      let brand = this.judgeBrand(navigator.userAgent.toLowerCase());
       // 修复ios上传图片的时候 被旋转的问题
-      if (Orientation != '' && Orientation != 1) {
+      if (Orientation != '' && Orientation != 1&&(brand=='xiaomi'||brand=='samsung')) {
         switch (Orientation) {
           case 6: // 需要顺时针(向左)90度旋转
             this.rotateImg(img, 'left', canvas)
@@ -202,6 +203,34 @@ export default {
       tCanvas.width = tCanvas.height = canvas.width = canvas.height = 0
       return ndata
     },
+    judgeBrand(sUserAgent) {
+       var isIphone = sUserAgent.match(/iphone/i) == "iphone";
+       var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
+       var isHonor = sUserAgent.match(/honor/i) == "honor";
+       var isOppo = sUserAgent.match(/oppo/i) == "oppo";
+       var isOppoR15 = sUserAgent.match(/pacm00/i) == "pacm00";
+       var isVivo = sUserAgent.match(/vivo/i) == "vivo";
+       var isXiaomi = sUserAgent.match(/mi\s/i) == "mi ";
+       var isXiaomi2s = sUserAgent.match(/mix\s/i) == "mix ";
+       var isRedmi = sUserAgent.match(/redmi/i) == "redmi";
+       var isSamsung = sUserAgent.match(/sm-/i) == "sm-";
+    
+       if (isIphone) {
+           return 'iphone';
+       } else if (isHuawei || isHonor) {
+           return 'huawei';
+       } else if (isOppo || isOppoR15) {
+           return 'oppo';
+       } else if (isVivo) {
+           return 'vivo';
+       } else if (isXiaomi || isRedmi || isXiaomi2s) {
+           return 'xiaomi';
+       } else if (isSamsung) {
+           return 'samsung';
+       } else {
+           return 'default';
+       }
+    },
     // 旋转图片
     rotateImg (img, direction, canvas) {
       // 最小与最大旋转方向,图片旋转4次后回到原方向

+ 55 - 24
src/components/common/vue-img-cropper.vue

@@ -158,6 +158,34 @@ export default {
     }
   },
   methods: {
+    judgeBrand(sUserAgent) {
+       var isIphone = sUserAgent.match(/iphone/i) == "iphone";
+       var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
+       var isHonor = sUserAgent.match(/honor/i) == "honor";
+       var isOppo = sUserAgent.match(/oppo/i) == "oppo";
+       var isOppoR15 = sUserAgent.match(/pacm00/i) == "pacm00";
+       var isVivo = sUserAgent.match(/vivo/i) == "vivo";
+       var isXiaomi = sUserAgent.match(/mi\s/i) == "mi ";
+       var isXiaomi2s = sUserAgent.match(/mix\s/i) == "mix ";
+       var isRedmi = sUserAgent.match(/redmi/i) == "redmi";
+       var isSamsung = sUserAgent.match(/sm-/i) == "sm-";
+    
+       if (isIphone) {
+           return 'iphone';
+       } else if (isHuawei || isHonor) {
+           return 'huawei';
+       } else if (isOppo || isOppoR15) {
+           return 'oppo';
+       } else if (isVivo) {
+           return 'vivo';
+       } else if (isXiaomi || isRedmi || isXiaomi2s) {
+           return 'xiaomi';
+       } else if (isSamsung) {
+           return 'samsung';
+       } else {
+           return 'default';
+       }
+    },
     getImg () {
       this.$refs.fileInput.click()
     },
@@ -214,31 +242,34 @@ export default {
             canvas.width = width = drawWidth
             canvas.height = height = drawHeight
             let context = canvas.getContext('2d')
+            let brand = self.judgeBrand(navigator.userAgent.toLowerCase());
             // 判断图片方向,重置canvas大小,确定旋转角度,iphone默认的是home键在右方的横屏拍摄方式
-            switch (orientation) {
-              // iphone横屏拍摄,此时home键在左侧
-              case 3:
-                degree = 180
-                drawWidth = -width
-                drawHeight = -height
-                break
-                // iphone竖屏拍摄,此时home键在下方(正常拿手机的方向)
-              case 6:
-                canvas.width = height
-                canvas.height = width
-                degree = 90
-                drawWidth = width
-                drawHeight = -height
-                break
-                // iphone竖屏拍摄,此时home键在上方
-              case 8:
-                canvas.width = height
-                canvas.height = width
-                degree = 270
-                drawWidth = -width
-                drawHeight = height
-                break
-            }
+             if((brand=='xiaomi'||brand=='samsung')&&orientation){
+                switch (orientation) {
+                  // iphone横屏拍摄,此时home键在左侧
+                  case 3:
+                    degree = 180
+                    drawWidth = -width
+                    drawHeight = -height
+                    break
+                    // iphone竖屏拍摄,此时home键在下方(正常拿手机的方向)
+                  case 6:
+                    canvas.width = height
+                    canvas.height = width
+                    degree = 90
+                    drawWidth = width
+                    drawHeight = -height
+                    break
+                    // iphone竖屏拍摄,此时home键在上方
+                  case 8:
+                    canvas.width = height
+                    canvas.height = width
+                    degree = 270
+                    drawWidth = -width
+                    drawHeight = height
+                    break
+                }
+              }  
 
             context.rotate(degree * Math.PI / 180)
             context.drawImage(this, 0, 0, drawWidth, drawHeight)