liucf před 5 roky
rodič
revize
e27df0519e
3 změnil soubory, kde provedl 34 přidání a 12 odebrání
  1. 18 3
      src/common/UploadImg.vue
  2. 4 8
      src/components/PathInfo.vue
  3. 12 1
      src/utils/tools.js

+ 18 - 3
src/common/UploadImg.vue

@@ -3,7 +3,7 @@
     <div class="box">
       <ul class="upload-imgs">
         <li
-          v-if="imgLen>=6 ? false : true"
+          v-if="imgLen<6"
           class="uploadBox"
           @click="handleUpload"
         >
@@ -37,19 +37,30 @@
   </div>
 </template>
 <script type="text/javascript">
+import {isIos,isWX} from '@utils/tools';
+import $ from 'jquery';
 export default {
   name: 'UploadImg',
   data() {
     return {
       mag: "上传图片",
       imgs: {},
-      imgLen: 0
+      imgLen: 0,
+      flag:true //图片处理完成后才可以再次点击上传
     }
   },
   props: ['item', 'moduleType', 'imgList'],//moduleType-哪个模块下上传的图
   mounted() {
     this.imgs = this.imgList; //回读
+    this.imgLen = Object.keys(this.imgList).length;
     this.$previewRefresh();//预览刷新
+    if(isIos()){
+      $('.upload').removeAttr("capture")
+    }else if(!isWX()){ 
+    // 微信端添加这个属性直接调拍照
+    //安卓手机且非微信端添加相机属性,否则QQ浏览器打不开相机
+      $('.upload').attr("capture","camera")
+    }
   },
   methods: {
     handleUpload() {
@@ -61,7 +72,9 @@ export default {
         alert("请开启权限设置")
       })*/
       const inp = this.$refs.inp;
-      inp.click();
+      if(this.flag){
+        inp.click();
+      } 
     },
     delImg(key) {
       let obj = this.imgs;
@@ -73,6 +86,7 @@ export default {
     },
     addImg() {
       // 上传图片进行压缩,压缩后超过4M则不允许上传
+      this.flag = false;
       let fileTag = this.$refs.inp;
       // let img = this.$refs.img;
       let file = fileTag.files[0];
@@ -106,6 +120,7 @@ export default {
         }
         // that.$refs.inp.value = '';
         fileTag.value = '';
+        that.flag = true
       });
     },
     imgBase64(file, callback) {

+ 4 - 8
src/components/PathInfo.vue

@@ -101,7 +101,6 @@
       }
     },
     created(){
-      // this.ifWX();
       this.getPathInfo();
       this.getSysConfig();
       this.$store.commit('initAllData');//初始化store数据
@@ -188,13 +187,10 @@
           this.submit = false
           clearTimeout(timer)
         }, 2000);
-      },
-      ifWX(){
-        let us = navigator.userAgent.toLowerCase();
-        if(us.indexOf('micromessenger') == -1){
-          console.log("非微信打开")
-        }
-      }
+      }, 
+    },
+    components:{
+      Submit
     },
     components:{
       Submit

+ 12 - 1
src/utils/tools.js

@@ -176,6 +176,16 @@ function isIos(){
   }
 }
 
+// 是否在微信打开
+function isWX(){
+  let us = navigator.userAgent.toLowerCase();
+  if(us.indexOf('micromessenger') == -1){
+    return false;
+  }else{
+    return true;
+  }
+}
+
 // 监听键盘是否弹起
 function fixedKeyboard() {
   var win_h = $(window).height();
@@ -267,7 +277,8 @@ module.exports =  {
   scrollToV,
   isIos,
   trimDots,
-  concatVal
+  concatVal,
+  isWX
 }