修改巡检模块提交之后后台数据图片不显示的问题

This commit is contained in:
赵毅 2025-09-26 16:14:34 +08:00
parent d0f448789a
commit 06f9b79012

View File

@ -57,6 +57,7 @@ import {
uniqueByField,
menuButtonInfo,
NavgateTo,
upload
} from "../../../utils";
import { apiArr } from "../../../api/routingInspection";
@ -96,6 +97,8 @@ export default {
this.selectedPointInfo = option // 保存完整的点位信息
this.searchKeyword = option.point_info.point_name
this.showOptions = false
// 切换点位时清空图片数据
this.images = []
} else {
console.warn('选择的点位信息不完整', option)
}
@ -149,13 +152,39 @@ export default {
}
try {
// 准备提交数据,使用正确的参数格式
// 上传所有图片到服务器
uni.showLoading({
title: '正在上传图片...',
mask: true
})
// 使用Promise.all并行上传所有图片
const uploadPromises = this.images.map(imagePath => {
return new Promise((resolve, reject) => {
upload(imagePath, (res) => {
if (res.code === 1 && res.data && res.data.path) {
resolve(res.data.path); // 上传成功,返回服务器返回的图片URL
} else {
reject(new Error('图片上传失败'));
}
});
});
});
// 等待所有图片上传完成
const uploadedImageUrls = await Promise.all(uploadPromises);
uni.hideLoading();
// 准备提交数据,使用服务器返回的图片URL
const params = {
task_id: parseInt(this.taskId), // 巡检任务ID
task_point_id: parseInt(this.selectedPoint), // 巡检点ID
image: this.images // 巡检图片,格式为字符串数组
image: uploadedImageUrls // 巡检图片,使用服务器返回的URL数组
}
console.log('上传成功的图片URL:', uploadedImageUrls)
// 调用正确的接口
const res = await request(apiArr.routingInspectionSubmit, "POST", params);
@ -168,6 +197,7 @@ export default {
icon: 'success'
})
} catch (error) {
uni.hideLoading();
console.error('提交失败', error)
uni.showToast({
title: '提交失败',