Przeglądaj źródła

Merge branch 'zhongqi-chat'

shizhongqi 10 miesięcy temu
rodzic
commit
d71e3989c3

+ 37 - 0
hdApp/src/admin/goods/add.vue

@@ -151,6 +151,7 @@ import AppUploader from "@/components/app-uploader";
 const form = require("@/utils/formValidation.js");
 import { getClass } from "@/api/category";
 import { addGoodsData } from "@/api/goods"
+import { delImage } from "@/api/pic-text";
 import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
 //import productMins from "@/mixins/product"; //复制页面代码时,没去掉
 import inputRestore from "@/mixins/inputRestore";
@@ -230,6 +231,42 @@ export default {
           this.form.shortCover = this.form.shopImg[0];
         }
       }
+
+      const shortDelPath = this.normalizeImgPath(res.del).replace(/^\//, '') // 因为 oss 接收的短路径不带 /
+      console.log('shortDelPath', shortDelPath);
+      if (shortDelPath != '') {
+        delImage({ filePath: shortDelPath }).then(() => {
+          console.log('图片删除成功');
+        }).catch(err => {
+          console.error('图片删除失败:', err);
+        });
+      } else {
+        console.error('图片删除失败:', '短路径为空');
+      }
+    },
+    // 规范化图片路径:去除域名与查询参数,保留以/开头的相对路径
+    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+1) : '' // 去掉/
+        }
+        return noQuery
+      } catch (e) {
+        return ''
+      }
     },
     imgUploadSuccess(res) {
       var _res = JSON.parse(res.data)

+ 48 - 0
hdApp/src/admin/goods/detail.vue

@@ -149,6 +149,7 @@ import TuiListCell from "@/components/plugin/list-cell";
 const form = require("@/utils/formValidation.js");
 import { getClass } from "@/api/category";
 import { getGoodsDetail, updateGoodsData } from "@/api/goods";
+import { delImages } from "@/api/pic-text";
 //图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
 import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
 //import productMins from "@/mixins/product"; //复制页面代码时,没去掉,引入的话会导致页面崩溃
@@ -164,6 +165,8 @@ export default {
     return {
       headers:{token:''},
       currentImgData: [],
+      // 收集待删除的小图URL,提交时批量删除
+      delImgQueue: [],
       loading: false, // 添加加载状态
 
       form: {
@@ -214,9 +217,44 @@ export default {
   },
   methods: {
     init(){},
+    // 规范化图片路径:去除域名与查询参数,保留以/开头的相对路径
+    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 ''
+      }
+    },
     imgDeleteFn(res){
       const index = res.index
+      // 先记录对应的短路径(无域名、无参数)
+      const shortDelPath = this.form.shopImg && this.form.shopImg[index]
+        ? this.form.shopImg[index]
+        : this.normalizeImgPath(res && res.del ? res.del : '').replace(/^\//, '') // 因为 oss 接收的短路径不带 /
+      // 从数组中移除
       this.form.shopImg.splice(index,1)
+      // 收集删除的小图短路径,去重
+      if (shortDelPath) {
+        if (!this.delImgQueue.includes(shortDelPath)) {
+          this.delImgQueue.push(shortDelPath)
+        }
+      }
       
       // 处理封面图片的临界情况
       if (this.form.shopImg.length === 0) {
@@ -477,6 +515,16 @@ export default {
         
         // 更新成功后,把更新的数据传递给前一页的列表页
         if (res.code === 1) {
+          // 如有删除的图片,提交给批量删除接口
+          if (this.delImgQueue && this.delImgQueue.length > 0) {
+            const filePaths = Array.from(new Set(this.delImgQueue))
+            delImages({ filePaths }).then(() => {
+              // 清空队列
+              this.delImgQueue = []
+            }).catch(() => {
+              // 忽略删除失败的提示,避免影响主流程
+            })
+          }
           try {
             let pages = getCurrentPages();
             let prevPage = pages[pages.length - 2];

+ 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>

+ 21 - 1
hdApp/src/admin/picText/picTextAdd.vue

@@ -13,7 +13,9 @@
             ref="richEditor"
             v-model="form.imageTextVos" 
             @change="onContentChange"
+            @collect-delete="onCollectDelete"
             :action="getLoginInfo.imgUploadApi"
+            :deferDelete="isEdit"
           />
         </view>
 
@@ -44,7 +46,9 @@ export default {
         title: '',
         imageTextVos: [] // 新增图文内容数组
       },
-      isEdit: false
+      isEdit: false,
+      // 编辑模式下,暂存删除的图片路径(短路径)
+      delImgQueue: []
     };
   },
   onLoad(option) {
@@ -114,6 +118,14 @@ export default {
     onContentChange(content) {
       this.form.imageTextVos = content;
     },
+    // 收集编辑模式下的删除图片
+    onCollectDelete(payload){
+      if (!this.isEdit) return;
+      if (!payload || !Array.isArray(payload.filePaths)) return;
+      payload.filePaths.forEach(p => {
+        if (p && !this.delImgQueue.includes(p)) this.delImgQueue.push(p)
+      })
+    },
     
     // 预览内容
     previewContent() {
@@ -181,6 +193,14 @@ export default {
         if(res.code == 1){
           uni.$emit('refreshListPage');
           that.$msg(this.isEdit ? '修改成功' : '添加成功');
+          // 编辑模式下,如存在待删图片,统一调用批量删除
+          if (this.isEdit && this.delImgQueue.length > 0) {
+            const { delImages } = require('@/api/pic-text');
+            const filePaths = Array.from(new Set(this.delImgQueue))
+            delImages({ filePaths }).then(() => {
+              this.delImgQueue = []
+            }).catch(() => {})
+          }
           uni.navigateBack({
             delta: 1
           });

+ 49 - 19
hdApp/src/components/RichMediaEditor/index.vue

@@ -206,6 +206,11 @@ export default {
     iconColor: { //图标颜色
       type: String,
       default: '#717173'
+    },
+    // 编辑模式下延迟删除,交由父组件统一处理
+    deferDelete: {
+      type: Boolean,
+      default: false
     }
   },
   data() {
@@ -331,19 +336,37 @@ export default {
 
             // 后继删除图片处理:首先判断是否是图片,如果是大图,则删除图片,如果是小图片,则批量删除多张图片
             if (tempList.type === 1) {
-              // 大图
-              delImage({ filePath: tempList.content }).then(() => {
-                console.log('大图删除成功');
-              });
+              if (this.deferDelete) { // 编辑模式下延迟删除,交由父组件统一处理
+                const p = tempList.content
+                if (p) this.$emit('collect-delete', { filePaths: [p] })
+              } else { // 新增模式下立即删除
+                // 大图立即删除
+                delImage({ filePath: tempList.content }).then(() => {
+                  console.log('大图删除成功');
+                }).catch(err => {
+                  console.error('大图删除失败:', err);
+                });
+              }
             } else if (tempList.type === 2) {
-              // 批量删除小图
-              let imgs = [];
-              tempList.content.forEach(img => {
-                imgs.push(img);
-              });
-              delImages({ filePaths: imgs }).then(() => {
-                console.log('小图删除成功');
-              });
+              if (this.deferDelete) { // 编辑模式下延迟删除,交由父组件统一处理
+                let imgs = [];
+                tempList.content.forEach(img => {
+                  const p = img
+                  if (p) imgs.push(p)
+                });
+                if (imgs.length > 0) this.$emit('collect-delete', { filePaths: imgs })
+              } else {
+                // 批量删除小图
+                let imgs = [];
+                tempList.content.forEach(img => {
+                  imgs.push(img);
+                });
+                delImages({ filePaths: imgs }).then(() => {
+                  console.log('小图删除成功');
+                }).catch(err => {
+                  console.error('小图删除失败:', err);
+                });
+              }
             }
           }
         }
@@ -438,15 +461,22 @@ export default {
         success: (res) => {
           if (res.confirm) {
             const imageUrl = this.contentList[itemIndex].content[imgIndex];
-            // 删除服务器上的图片
-            delImage({ filePath: imageUrl }).then(() => {
+            if (this.deferDelete) {
+              const p = imageUrl
               // 从数组中移除图片
               this.contentList[itemIndex].content.splice(imgIndex, 1);
-            }).catch(err => {
-              console.error('删除图片失败:', err);
-              // 即使删除失败也从数组中移除
-              this.contentList[itemIndex].content.splice(imgIndex, 1);
-            });
+              if (p) this.$emit('collect-delete', { filePaths: [p] })
+            } else {
+              // 删除服务器上的图片
+              delImage({ filePath: imageUrl }).then(() => {
+                // 从数组中移除图片
+                this.contentList[itemIndex].content.splice(imgIndex, 1);
+              }).catch(err => {
+                console.error('删除图片失败:', err);
+                // 即使删除失败也从数组中移除
+                this.contentList[itemIndex].content.splice(imgIndex, 1);
+              });
+            }
           }
         }
       });

Plik diff jest za duży
+ 570 - 554
hdApp/src/components/htz-image-upload/htz-image-upload.vue


+ 15 - 15
mallApp/src/components/RichMediaViewer/index.vue

@@ -406,11 +406,11 @@ export default {
     onImageError(index) {
       console.error('大图加载失败:', index)
       this.contentList[index].loaded = true // 标记图片加载失败,不再重复加载
-      uni.showToast({
-        title: '图片加载失败',
-        icon: 'error',
-        duration: 500
-      })
+      // uni.showToast({
+      //   title: '图片加载失败',
+      //   icon: 'error',
+      //   duration: 500
+      // })
     },
 
     // 大图加载成功处理
@@ -422,11 +422,11 @@ export default {
     onSmallImageError(index, imgIndex) {
       console.error('小图加载失败:', index, imgIndex)
       this.contentList[index].imageStatus[imgIndex] = true // 标记小图加载失败,不再重复加载
-      uni.showToast({
-        title: '图片加载失败',
-        icon: 'error',
-        duration: 500
-      })
+      // uni.showToast({
+      //   title: '图片加载失败',
+      //   icon: 'error',
+      //   duration: 500
+      // })
     },
 
     // 小图加载成功处理
@@ -440,11 +440,11 @@ export default {
     onPreviewImageError(index) {
       console.error('预览图片加载失败:', index)
       this.$set(this.previewImageStatus, index, true) // 标记预览图片加载失败,不再重复加载
-      uni.showToast({
-        title: '图片加载失败',
-        icon: 'error',
-        duration: 500
-      })
+      // uni.showToast({
+      //   title: '图片加载失败',
+      //   icon: 'error',
+      //   duration: 500
+      // })
     },
 
     // 预览图片加载成功处理

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików