Просмотр исходного кода

feature_20260330_拜访连拍速度优化

zhujindu 1 неделя назад
Родитель
Сommit
ac70c7aa74

+ 5 - 1
src/components/deleteUploadImgTaskPhoto.vue

@@ -45,6 +45,7 @@ import { removePhotoBatch } from '@/api/index';
 import uploadVNormalTaskPhoto from '@/components/uploadVNormalTaskPhoto';
 import { mapState } from 'vuex';
 import { getTicketFun } from '@/utils/TXApiFun';
+import { is } from 'core-js/core/object';
 export default {
   name: 'deleteUploadImgTaskPhoto',
   components: { uploadVNormalTaskPhoto },
@@ -148,6 +149,7 @@ export default {
       imgArr: [],
       mediaIds: [],
       locationRemark: '',
+      isUploadImg: true,
     };
   },
   methods: {
@@ -158,7 +160,7 @@ export default {
         let mediaitem = mediaInfos.pop();
         wx.downloadImage({
           serverId: mediaitem.mediaId,
-          isShowProgressTips: 0, // 默认为1,显示进度提示
+          isShowProgressTips: 1, // 默认为1,显示进度提示
           success: (res) => {
             wx.getLocalImgData({
               localId: res.localId,
@@ -222,6 +224,7 @@ export default {
           }),
         );
         this.$nextTick(() => {
+          this.isUploadImg = false;
           this.syncUpload(localIds);
         });
       } else {
@@ -238,6 +241,7 @@ export default {
     },
     syncUpload(localIds, callback) {
       if (!localIds.length) {
+        this.isUploadImg = true;
         callback && callback();
         return;
       } else {

+ 57 - 26
src/views/deviceWithin/taskPhotoTaking.vue

@@ -235,38 +235,69 @@ export default {
         this.taskPhotoRecognitionResult = item.taskPhotoRecognitionResult;
       });
     },
-    onSubmit() {
-      let formData = {
-        storeId: this.$route.query.storeId,
-        storeCode: this.$route.query.storeCode,
-        storeGroupId: this.$route.query.storeGroupId,
-        visitsId: this.visitsId,
-        taskList: this.taskIds.split(',').map((val) => Number(val)),
-        insert: true,
-        collectionAnswers: [],
-        checkUnManage: 'N',
-        deviceCode: '',
-        putInCode: '',
-        equipmentCode: '',
-        collectionItemId: this.$refs.taskPhoto[0].collectionItemId, //	是	string	采集项id
-        objectType: this.$route.query.photoType, //	是	string	照片类型,取任务上的照片类型,如果没有则取手动选择的照片类型
-        locationRemark: this.$refs.taskPhoto[0].locationRemark, //	是	String	当前地址信息
-        mediaInfos: [],
-        isH5: this.userInfo.photoMethod == '1' ? true : false, // 是否H5拍照 1:是;0:否
-      };
-      // 0=企业微信,1=H5相机
-      if (this.userInfo.photoMethod == '1') {
-        formData.mediaInfos = [];
-      } else {
-        formData.mediaInfos = this.$refs.taskPhoto[0].imgArr;
+    waitUploadReady(timeout = 60000, interval = 300) {
+      return new Promise((resolve, reject) => {
+        const start = Date.now();
+        const check = () => {
+          const taskPhoto = this.$refs.taskPhoto && this.$refs.taskPhoto[0];
+          if (taskPhoto && taskPhoto.isUploadImg) {
+            resolve();
+            return;
+          }
+          if (Date.now() - start >= timeout) {
+            reject(new Error('图片上传超时,请稍后再试'));
+            return;
+          }
+          setTimeout(check, interval);
+        };
+        check();
+      });
+    },
+    async onSubmit() {
+      this.toastLoading(0, '提交中,请稍候...', true);
+      try {
+        const taskPhoto = this.$refs.taskPhoto && this.$refs.taskPhoto[0];
+        if (taskPhoto && !taskPhoto.isUploadImg) {
+          await this.waitUploadReady(120000, 400);
+        }
+
+        let formData = {
+          storeId: this.$route.query.storeId,
+          storeCode: this.$route.query.storeCode,
+          storeGroupId: this.$route.query.storeGroupId,
+          visitsId: this.visitsId,
+          taskList: this.taskIds.split(',').map((val) => Number(val)),
+          insert: true,
+          collectionAnswers: [],
+          checkUnManage: 'N',
+          deviceCode: '',
+          putInCode: '',
+          equipmentCode: '',
+          collectionItemId: taskPhoto ? taskPhoto.collectionItemId : '',
+          objectType: this.$route.query.photoType,
+          locationRemark: taskPhoto ? taskPhoto.locationRemark : '',
+          mediaInfos: [],
+          isH5: this.userInfo.photoMethod == '1',
+        };
+        if (this.userInfo.photoMethod == '1') {
+          formData.mediaInfos = [];
+        } else if (taskPhoto) {
+          formData.mediaInfos = taskPhoto.imgArr;
+        }
+        await this.addCollection(formData);
+      } catch (err) {
+        this.$toast(err.message || '提交失败,请稍后再试');
+      } finally {
+        this.toastLoading().clear();
       }
-      this.addCollection(formData);
     },
     addCollection(formData) {
-      addCollectionAnswerBatch(formData).then((res) => {
+      return addCollectionAnswerBatch(formData).then((res) => {
         if (res.code == 200) {
           localStorage.setItem('getRequestFlage', 'true');
           this.$router.go(-1);
+        } else {
+          this.$toast('提交失败,请重试');
         }
       });
     },