Bläddra i källkod

使用原生手机拍照,优化企业微信拍照模糊问题

zhujindu 8 månader sedan
förälder
incheckning
d98e96bf1e
1 ändrade filer med 70 tillägg och 41 borttagningar
  1. 70 41
      src/components/uploadVNormal.vue

+ 70 - 41
src/components/uploadVNormal.vue

@@ -6,7 +6,11 @@
       <van-icon class="photo photos" name="photograph" size="22px" color="#969696" />
     </div>
     <!-- 原生自带拍照 -->
-    <H5Camera @getImg="getImg" :capture="pictureSource == '1' ? '' : 'camera'" v-else />
+    <H5Camera
+      @getImg="getImg"
+      ref="H5Camera"
+      :capture="pictureSource == '1' ? '' : 'camera'"
+      v-else />
     <div id="allmap"></div>
     <div class="mask" v-if="progressFlag">
       <el-progress
@@ -22,7 +26,7 @@
       :imageAIVerifyFlag="imageAIVerifyFlag"
       :imageAIVerifyData="imageAIVerifyData"
       @confirmUpload="confirmUpload"
-      @uploadImgFun="uploadImg"
+      @uploadImgFun="uploadImgFun"
       :source="'visit'"
       @normalFlow="normalFlow"
       @close="close"></imageAIVerifyErr>
@@ -136,6 +140,7 @@ export default {
       meidaId: '', //当前上传图片id
       addressesRemark: '', //当前位置信息
       controller: null, //取消请求状态
+      fileUrl: '',
     };
   },
   methods: {
@@ -152,46 +157,56 @@ export default {
       uploadAliOss(base64, imgName)
         .then((res) => {
           if (res.url && res.url.indexOf('http') != -1) {
-            var form = {
-              fileUrl: res.url,
-              collectionItemId: this.collectionId,
-              objectType: this.objectType,
-              storeGroupId: this.storeGroupId,
-              taskId: this.taskId,
-              visitsId: localStorage.getItem('visitId'),
-              visitModel: this.visitModel,
-              visitSource: '1',
-              locationRemark: '',
-              parentCollectionId: this.parentCollectionId || '',
-              secondCollectionId: this.secondCollectionId || '',
-              firstCollectionId: this.firstCollectionId || '',
-              fourthCollectionId: this.fourthCollectionId || '',
-              thirdCollectionId: this.thirdCollectionId || '',
-              deviceCode: this.deviceCode, //设备编号
-              putInCode: this.putInCode, //投放编号
-            };
-            this.controller = null;
-            // 需要图匠校验的添加参数和loading
-            if (this.photoIdentifyType) {
-              form.photoIdentifyType = this.photoIdentifyType;
-              this.progress();
-              this.controller = new AbortController(); //取消请求
-            } else {
-              this.toastLoading(0, '上传中...', true);
-            }
-            addH5Photo(form, this.controller ? this.controller.signal : null)
-              .then((res) => {
-                this.requestThen(res);
-              })
-              .catch((error) => {
-                this.requestCatch(error);
-              });
+            this.fileUrl = res.url;
+            this.uploadImagev();
+            // var form = {
+            //   fileUrl: res.url,
+            //   collectionItemId: this.collectionId,
+            //   objectType: this.objectType,
+            //   storeGroupId: this.storeGroupId,
+            //   taskId: this.taskId,
+            //   visitsId: localStorage.getItem('visitId'),
+            //   visitModel: this.visitModel,
+            //   visitSource: '1',
+            //   locationRemark: '',
+            //   parentCollectionId: this.parentCollectionId || '',
+            //   secondCollectionId: this.secondCollectionId || '',
+            //   firstCollectionId: this.firstCollectionId || '',
+            //   fourthCollectionId: this.fourthCollectionId || '',
+            //   thirdCollectionId: this.thirdCollectionId || '',
+            //   deviceCode: this.deviceCode, //设备编号
+            //   putInCode: this.putInCode, //投放编号
+            // };
+            // this.controller = null;
+            // // 需要图匠校验的添加参数和loading
+            // if (this.photoIdentifyType) {
+            //   form.photoIdentifyType = this.photoIdentifyType;
+            //   this.progress();
+            //   this.controller = new AbortController(); //取消请求
+            // } else {
+            //   this.toastLoading(0, '上传中...', true);
+            // }
+            // addH5Photo(form, this.controller ? this.controller.signal : null)
+            //   .then((res) => {
+            //     this.requestThen(res);
+            //   })
+            //   .catch((error) => {
+            //     this.requestCatch(error);
+            //   });
           }
         })
         .catch((err) => {
           console.log('err:' + err);
         });
     },
+    uploadImgFun() {
+      // 0=企业微信,1=H5相机
+      if (this.userInfo.photoMethod == '0') {
+        this.uploadImg();
+      } else {
+        this.$refs.H5Camera.camera();
+      }
+    },
     uploadImg() {
       var map = new TMap.Map('allmap', {
         zoom: 14,
@@ -281,7 +296,8 @@ export default {
                     localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得
                     isShowProgressTips: 1, // 默认为1,显示进度提示
                     success: function (res) {
-                      that.uploadImagev(res.serverId, addressesRemark);
+                      this.meidaId = meidaId;
+                      this.uploadImagev(addressesRemark);
                     },
                   });
                 },
@@ -290,7 +306,7 @@ export default {
           }
         });
     },
-    uploadImagev(meidaId, addressesRemark) {
+    uploadImagev(addressesRemark = '') {
       // 初始化重置 图匠校验
       this.resetProgress();
       this.close();
@@ -315,10 +331,10 @@ export default {
       if (that.thirdCollectionId != null && that.thirdCollectionId != 'null') {
         thirdCollectionId = that.thirdCollectionId;
       }
-      this.meidaId = meidaId;
       this.addressesRemark = addressesRemark;
       var form = {
-        mediaId: meidaId,
+        mediaId: '',
+        fileUrl: '',
         collectionItemId: that.collectionId,
         objectType: that.objectType,
         storeGroupId: that.storeGroupId,
@@ -335,6 +351,12 @@ export default {
         deviceCode: that.deviceCode, //设备编号
         putInCode: that.putInCode, //投放编号
       };
+      // 0=企业微信,1=H5相机
+      if (this.userInfo.photoMethod == '0') {
+        form.mediaId = this.meidaId; //	string	图片素材id
+      } else {
+        form.fileUrl = this.fileUrl; //	string	图片素材id
+      }
       this.controller = null;
       // 需要图匠校验的添加参数和loading
       if (this.photoIdentifyType) {
@@ -416,7 +438,8 @@ export default {
     confirmUpload(res) {
       if (this.photoIdentifyType) {
         var form = {
-          mediaId: this.meidaId, //	string	图片素材id
+          mediaId: '',
+          fileUrl: '',
           visitSource: '1', //	Long	拜访模式
           storeGroupId: this.storeGroupId, //	string	门店任务组,多个用逗号隔开
           visitsId: localStorage.getItem('visitId'), //	string	拜访id
@@ -432,6 +455,12 @@ export default {
           businessId: res.data.businessId, // 当前拍摄图片id
           feedbackMessage: res.feedbackMessage,
         };
+        // 0=企业微信,1=H5相机
+        if (this.userInfo.photoMethod == '0') {
+          form.mediaId = this.meidaId; //	string	图片素材id
+        } else {
+          form.fileUrl = this.fileUrl; //	string	图片素材id
+        }
         if (res.isUpdate) {
           form.isUpdate = 'true';
         }