Commit 6d00a908 authored by liwei's avatar liwei

修改了上传逻辑,以及修复了图片显示异步问题,上传判断字段后续需要改

parent 333b87d6
......@@ -525,17 +525,21 @@ export default {
loadData() {
this.loading = true
listCmsActivity(this.queryParams).then(response => {
this.tableData = response.data
const tableData = response.data
// 处理分页数据里的url
this.tableData.forEach(item => {
getOssUrl(item.pictureId).then(imgRes => {
item.url = imgRes.data
// 使用 Promise.all 处理所有的 getOssUrl 异步操作
const promises = tableData.map(item => {
return getOssUrl(item.pictureId).then(imgRes => {
item.url = imgRes.data // 更新 url 字段
})
})
this.total = response.total
this.loading = false
}
)
// 等待所有异步操作完成
Promise.all(promises).then(() => {
this.tableData = tableData // 数据更新
this.total = response.total
this.loading = false
})
})
},
/** 查看报名人数 */
handleClick(row) {
......
......@@ -501,16 +501,31 @@ export default {
try {
// 发起上传请求
uploadPublic(formData).then(response => {
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
if (response.data.ossInfoId !== null && response.data.ossInfoId !== '' && response.data.ossInfoId !== undefined){
// oss上传
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
businessId: businessId
}]
this.form.pictureId = businessId
this.imageUrl = res1.data
})
})
} else {
// 本地上传
getOssUrl(response.data.businessId).then(res1 => {
const businessId = response.data.businessId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
......@@ -519,7 +534,7 @@ export default {
this.form.pictureId = businessId
this.imageUrl = res1.data
})
})
}
})
} catch (error) {
console.error('上传失败:', error)
......
......@@ -299,20 +299,22 @@ export default {
/** 查询banner管理列表 */
getList() {
this.loading = true
listCmsBanner(this.queryParams).then(
response => {
this.cmsBannerList = response.data
// 处理分页数据里的url
this.cmsBannerList.forEach(item => {
getOssUrl(item.pictureId).then(imgRes => {
item.url = imgRes.data
})
listCmsBanner(this.queryParams).then(response => {
const tableData = response.data
// 处理分页数据里的url
// 使用 Promise.all 处理所有的 getOssUrl 异步操作
const promises = tableData.map(item => {
return getOssUrl(item.pictureId).then(imgRes => {
item.url = imgRes.data // 更新 url 字段
})
console.log('11111111111', this.cmsBannerList)
})
// 等待所有异步操作完成
Promise.all(promises).then(() => {
this.cmsBannerList = tableData // 数据更新
this.total = response.total
this.loading = false
}
)
})
})
},
/** 取消按钮 */
cancel() {
......@@ -447,16 +449,31 @@ export default {
try {
// 发起上传请求
uploadPublic(formData).then(response => {
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
if (response.data.ossInfoId !== null && response.data.ossInfoId !== '' && response.data.ossInfoId !== undefined){
// oss上传
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
businessId: businessId
}]
this.form.pictureId = businessId
this.imageUrl = res1.data
})
})
} else {
// 本地上传
getOssUrl(response.data.businessId).then(res1 => {
const businessId = response.data.businessId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
......@@ -465,7 +482,7 @@ export default {
this.form.pictureId = businessId
this.imageUrl = res1.data
})
})
}
})
} catch (error) {
console.error('上传失败:', error)
......
......@@ -343,15 +343,18 @@ export default {
this.loading = true
listCmsNotice(this.queryParams).then(
response => {
this.tableData = response.data
// 处理分页数据里的url
this.tableData.forEach(item => {
getOssUrl(item.pictureId).then(imgRes => {
item.url = imgRes.data
const tableData = response.data
const promises = tableData.map(item => {
return getOssUrl(item.pictureId).then(imgRes => {
item.url = imgRes.data // 更新 url 字段
})
})
this.total = response.total
this.loading = false
// 等待所有异步操作完成
Promise.all(promises).then(() => {
this.tableData = tableData // 数据更新
this.total = response.total
this.loading = false
})
}
)
},
......
......@@ -311,16 +311,31 @@ export default {
try {
// 发起上传请求
uploadPublic(formData).then(response => {
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
if (response.data.ossInfoId !== null && response.data.ossInfoId !== '' && response.data.ossInfoId !== undefined){
// oss上传
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
businessId: businessId
}]
this.form.pictureId = businessId
this.imageUrl = res1.data
})
})
} else {
// 本地上传
getOssUrl(response.data.businessId).then(res1 => {
const businessId = response.data.businessId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
......@@ -329,7 +344,7 @@ export default {
this.form.pictureId = businessId
this.imageUrl = res1.data
})
})
}
})
} catch (error) {
console.error('上传失败:', error)
......
......@@ -1055,16 +1055,31 @@ export default {
try {
// 发起上传请求
uploadPublic(formData).then(response => {
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
if (response.data.ossInfoId !== null && response.data.ossInfoId !== '' && response.data.ossInfoId !== undefined){
// oss上传
axios({
method: 'PUT',
url: response.data.url,
data: file,
headers: {
'Content-Type': file.type
}
}).then(res => {
getOssUrl(response.data.ossInfoId).then(res1 => {
const businessId = response.data.ossInfoId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
businessId: businessId
}]
this.form.avatar = businessId
this.imageUrl = res1.data
})
})
} else {
// 本地上传
getOssUrl(response.data.businessId).then(res1 => {
const businessId = response.data.businessId
// 更新 fileList,保存文件的 URL 和其他信息
this.fileList = [{
url: res1.data,
......@@ -1073,7 +1088,7 @@ export default {
this.form.avatar = businessId
this.imageUrl = res1.data
})
})
}
})
} catch (error) {
console.error('上传失败:', error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment