|
|
@@ -206,6 +206,11 @@ export default {
|
|
|
iconColor: { //图标颜色
|
|
|
type: String,
|
|
|
default: '#717173'
|
|
|
+ },
|
|
|
+ // 编辑模式下延迟删除,交由父组件统一处理
|
|
|
+ deferDelete: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
@@ -331,24 +336,37 @@ export default {
|
|
|
|
|
|
// 后继删除图片处理:首先判断是否是图片,如果是大图,则删除图片,如果是小图片,则批量删除多张图片
|
|
|
if (tempList.type === 1) {
|
|
|
- // 大图
|
|
|
- delImage({ filePath: tempList.content }).then(() => {
|
|
|
- console.log('大图删除成功');
|
|
|
- this.$emit('auto-submit');
|
|
|
- }).catch(err => {
|
|
|
- console.error('大图删除失败:', err);
|
|
|
- // 删除失败也尝试自动提交,以保证数据一致
|
|
|
- this.$emit('auto-submit');
|
|
|
- });
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -443,17 +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);
|
|
|
- this.$emit('auto-submit');
|
|
|
- }).catch(err => {
|
|
|
- console.error('删除图片失败:', err);
|
|
|
- // 即使删除失败也从数组中移除
|
|
|
- this.contentList[itemIndex].content.splice(imgIndex, 1);
|
|
|
- this.$emit('auto-submit');
|
|
|
- });
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|