|
|
@@ -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)
|