소스 검색

开单图片删除操作增加请求删除接口

shizhongqi 10 달 전
부모
커밋
770ff1d6ad
2개의 변경된 파일36개의 추가작업 그리고 6개의 파일을 삭제
  1. 34 2
      hdApp/src/admin/order/workOrder.vue
  2. 2 4
      hdApp/src/components/htz-image-upload/htz-image-upload.vue

+ 34 - 2
hdApp/src/admin/order/workOrder.vue

@@ -82,7 +82,7 @@ import productMins from "@/mixins/cgPlantProduct";
 import AppDeliveryModule from "@/components/app-delivery";
 import { createOrder } from "@/api/order";
 import { mapGetters } from "vuex";
-import { getUserDistance } from "@/api/express";
+import { delImage } from "@/api/pic-text";
 import { getAllKind } from "@/api/kind";
 //图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
 import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
@@ -150,6 +150,14 @@ export default {
     imgDeleteFn(res){
       const index = res.index
       this.form.cover.splice(index,1)
+      const shortDelPath = this.normalizeImgPath(res.del).replace(/^\//, '') // 因为 oss 接收的短路径不带 /
+      if (shortDelPath != '') {
+        delImage({ filePath: shortDelPath }).then(() => {
+          console.log('图片删除成功');
+        }).catch(err => {
+          console.error('图片删除失败:', err);
+        });
+      }
     },
     init() {
       this.getKindDataFn()
@@ -227,7 +235,31 @@ export default {
             that.pageTo({url: '/admin/order/workOrderResult',type:2,query:{id:res.data.id}})
           })
       })
-    }
+    },
+    // 规范化图片路径:去除域名与查询参数,保留以/开头的相对路径
+    normalizeImgPath(url){
+      if (!url || typeof url !== 'string') return ''
+      try {
+        // 去掉查询参数
+        const qIndex = url.indexOf('?')
+        const noQuery = qIndex >= 0 ? url.substring(0, qIndex) : url
+        // 提取以/开头的路径
+        const match = noQuery.match(/:\/\/[\w.-]+(\:\d+)?(\/[^?#]+)$/)
+        if (match && match[2]) {
+          return match[2]
+        }
+        // 若本身就是相对路径则直接返回
+        if (noQuery.startsWith('/')) return noQuery
+        // 若是无协议域名形式 //domain/path
+        if (noQuery.startsWith('//')) {
+          const idx = noQuery.indexOf('/', 2)
+          return idx > 0 ? noQuery.substring(idx) : ''
+        }
+        return noQuery
+      } catch (e) {
+        return ''
+      }
+    },
   },
 };
 </script>

+ 2 - 4
hdApp/src/components/htz-image-upload/htz-image-upload.vue

@@ -287,11 +287,9 @@ export default {
       });
     },
     imgAdd() {
-      console.log('imgAdd');
+      //console.log('imgAdd');
       let nowNum = Math.abs(this.uploadLists.length - this.max);
       let thisNum = this.chooseNum > nowNum ? nowNum : this.chooseNum; //可选数量
-      console.log('nowNum', nowNum);
-      console.log('thisNum', thisNum);
       // #ifdef APP-PLUS
       if (this.sourceType.length > 1) {
         uni.showActionSheet({
@@ -436,7 +434,7 @@ export default {
       Promise.all(compressImgs) //执行所有需请求的接口
         .then((results) => {
           uni.hideLoading();
-          console.log('imgUpload', results);
+          // console.log('imgUpload', results);
           this.imgUpload(results);
         })
         .catch((res, object) => {