Commit 6d00a908 authored by liwei's avatar liwei

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

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