This commit is contained in:
menxipeng
2025-09-13 14:46:45 +08:00
parent 89a2aded5e
commit f341d5b423
3 changed files with 20 additions and 35 deletions

View File

@@ -130,10 +130,12 @@ export default {
// 然后将数组转为对象数组
this.fileList = list.map(item => {
if (typeof item === "string") {
if (item.indexOf(this.baseUrl) === -1 && !isExternal(item)) {
item = { name: this.baseUrl + item, url: this.baseUrl + item }
// 如果不是完整URL且不包含baseUrl则添加baseUrl前缀用于显示
if (!isExternal(item) && item.indexOf(this.baseUrl) === -1) {
const displayUrl = this.baseUrl + (item.startsWith('/') ? item : '/' + item);
item = { name: displayUrl, url: displayUrl }
} else {
item = { name: item, url: item }
item = { name: item, url: item }
}
}
return item
@@ -196,13 +198,14 @@ export default {
// 上传成功回调
handleUploadSuccess(res, file) {
if (res.code === 200) {
// 根据新的接口返回格式data字段包含图片路径
// 直接使用接口返回的路径,不做任何修改
let imagePath = res.data || res.fileName;
// 如果路径不是以http开头则拼接域名前缀
// 为了显示需要临时添加baseUrl前缀
let displayUrl = imagePath;
if (imagePath && !imagePath.startsWith('http://') && !imagePath.startsWith('https://')) {
imagePath = this.baseUrl + imagePath;
displayUrl = this.baseUrl + imagePath;
}
this.uploadList.push({ name: imagePath, url: imagePath })
this.uploadList.push({ name: displayUrl, url: displayUrl })
this.uploadedSuccessfully()
} else {
this.number--