| | |
| | | return; |
| | | } |
| | | |
| | | // 验证图片上传 |
| | | // 修改图片验证逻辑 |
| | | if (!this.form.photos || this.form.photos.length === 0) { |
| | | this.$message.warning('请上传工单图片'); |
| | | return; |
| | |
| | | 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; |
| | | } |
| | |
| | | |
| | | // 文件改变时的钩子 |
| | | 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; |
| | | }, |
| | | |
| | | // 文件移除时的钩子 |
| | |
| | | } |
| | | // 如果有图片,添加到表单中 |
| | | 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,用于区分是否为已存在的图片 |
| | | }]; |
| | | } |
| | | |