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