From c32bfd861e35134ee401d4354f2fdd52b62d1aa3 Mon Sep 17 00:00:00 2001
From: rain <1679827795@qq.com>
Date: Mon, 28 Apr 2025 17:06:47 +0800
Subject: [PATCH] 修复草稿保存图片后,发布工单时提示未上传图片
---
src/views/tickets/ticket.vue | 32 ++++++++++++++++++++++++--------
1 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/src/views/tickets/ticket.vue b/src/views/tickets/ticket.vue
index 02b0592..6724c16 100644
--- a/src/views/tickets/ticket.vue
+++ b/src/views/tickets/ticket.vue
@@ -1035,7 +1035,7 @@
return;
}
- // 验证图片上传
+ // 修改图片验证逻辑
if (!this.form.photos || this.form.photos.length === 0) {
this.$message.warning('请上传工单图片');
return;
@@ -1059,9 +1059,17 @@
submitData.id = this.form.id;
}
- // 获取文件对象
- const file = this.form.photos[0].raw;
- if (!file) {
+ // 修改获取文件的逻辑
+ let file = null;
+ const photoInfo = this.form.photos[0];
+
+ if (photoInfo.raw) {
+ // 如果有新上传的文件,使用新文件
+ file = photoInfo.raw;
+ } else if (photoInfo.existingUrl) {
+ // 如果是已存在的图片,将URL添加到提交数据中
+ submitData.photoUrl = photoInfo.existingUrl;
+ } else {
this.$message.warning('图片文件无效,请重新上传');
return;
}
@@ -1511,8 +1519,12 @@
// 文件改变时的钩子
handleFileChange(file, fileList) {
- this.form.photos = fileList;
- this.currentDetail.photos = fileList;
+ // 保持最新的文件列表
+ this.form.photos = fileList.map(item => ({
+ ...item,
+ existingUrl: item.url && !item.raw ? item.url : null // 标记已存在的图片URL
+ }));
+ this.currentDetail.photos = this.form.photos;
},
// 文件移除时的钩子
@@ -1856,9 +1868,13 @@
}
// 如果有图片,添加到表单中
if (row.photo_url) {
+ // 创建一个带有必要信息的文件对象
this.form.photos = [{
- name: 'existing-photo',
- url: row.photo_url
+ name: 'existing-photo.jpg', // 添加默认扩展名
+ url: row.photo_url, // 用于预览的URL
+ status: 'success', // 标记为已上传成功
+ raw: null, // 初始化为null
+ existingUrl: row.photo_url // 保存原始URL,用于区分是否为已存在的图片
}];
}
--
Gitblit v1.9.3