zhujindu преди 2 седмици
родител
ревизия
627f29c749
променени са 2 файла, в които са добавени 43 реда и са изтрити 18 реда
  1. 32 10
      src/components/deleteUploadImgTaskPhoto.vue
  2. 11 8
      src/views/deviceWithin/taskPhotoTaking.vue

+ 32 - 10
src/components/deleteUploadImgTaskPhoto.vue

@@ -19,10 +19,10 @@
             ref="uploadVNormal" />
         </div>
       </van-col>
-      <van-col span="6" v-for="(id, index) in imgArr" :key="index">
+      <van-col span="6" v-for="(item, index) in imgArr" :key="index">
         <div class="imgview">
           <van-icon v-if="insert == '1'" name="close" size="16" v-on:click="deleteImg(index)" />
-          <img :src="id" width="100px" height="100px" @click="previewsImg(index)" />
+          <img :src="item.serverId" width="100px" height="100px" @click="previewsImg(index)" />
           <!-- <img
             v-else
             :src="urls.fileUrl"
@@ -96,7 +96,7 @@ export default {
   watch: {
     imgs: {
       handler(val) {
-        this.imgArr = val || [];
+        if (val) this.imgArr = val;
       },
       deep: true,
       immediate: true,
@@ -106,6 +106,7 @@ export default {
     return {
       url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
       imgArr: [],
+      mediaIds: [],
     };
   },
   methods: {
@@ -113,20 +114,41 @@ export default {
       this.imgArr.splice(index, 1);
     },
     previewsImg(index) {
+      let urls = this.imgArr.map((item) => item.serverId);
       ImagePreview({
-        images: this.imgArr,
+        images: urls,
         startPosition: index,
       });
     },
     newimgarr(localIds) {
-      if (this.isIOS()) {
-        this.imgArr = this.imgArr.concat([...localIds]);
-        // 解决ios微信localId无法直接使用的问题,获取base64后再上传
-        // this.setIosImg(localIds);
+      this.syncUpload(localIds);
+      // if (this.isIOS()) {
+      //   this.imgArr = this.imgArr.concat([...localIds]);
+      //   // 解决ios微信localId无法直接使用的问题,获取base64后再上传
+      //   // this.setIosImg(localIds);
+      // } else {
+      //   this.imgArr = this.imgArr.concat([...localIds]);
+      // }
+      // this.$emit('upDataDetail');
+    },
+    syncUpload(localIds, callback) {
+      if (!localIds.length) {
+        callback && callback();
+        return;
       } else {
-        this.imgArr = this.imgArr.concat([...localIds]);
+        var localId = localIds.pop();
+        wx.uploadImage({
+          localId: localId,
+          isShowProgressTips: 1, // 默认为1,显示进度提示
+          success: (res) => {
+            this.imgArr.push({
+              mediaId: res.serverId,
+              serverId: localId,
+            });
+            this.syncUpload(localIds, callback);
+          },
+        });
       }
-      // this.$emit('upDataDetail');
     },
     isIOS() {
       return /iPhone|iPad|iPod/i.test(navigator.userAgent);

+ 11 - 8
src/views/deviceWithin/taskPhotoTaking.vue

@@ -144,6 +144,7 @@ export default {
       taskPhotoRecognitionResult: null,
       spanArr: [],
       pos: 0,
+      mediaIds: [],
     };
   },
   activated() {
@@ -240,15 +241,17 @@ export default {
         deviceCode: '',
         putInCode: '',
         equipmentCode: '',
+        mediaIds: this.$refs.taskPhoto[0].imgArr,
       };
-      console.log(this.$refs.taskPhoto);
-      console.log(this.$refs.taskPhoto.imgArr);
-      // addCollectionAnswerBatch(formData).then((res) => {
-      //   if (res.code == 200) {
-      //     localStorage.setItem('getRequestFlage', 'true');
-      //     this.$router.go(-1);
-      //   }
-      // });
+      this.addCollection(formData);
+    },
+    addCollection(formData) {
+      addCollectionAnswerBatch(formData).then((res) => {
+        if (res.code == 200) {
+          localStorage.setItem('getRequestFlage', 'true');
+          this.$router.go(-1);
+        }
+      });
     },
     onClickLeft() {
       this.$router.go(-1);