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

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, uniqueByField,
menuButtonInfo, menuButtonInfo,
NavgateTo, NavgateTo,
upload
} from "../../../utils"; } from "../../../utils";
import { apiArr } from "../../../api/routingInspection"; import { apiArr } from "../../../api/routingInspection";
@ -96,6 +97,8 @@ export default {
this.selectedPointInfo = option // this.selectedPointInfo = option //
this.searchKeyword = option.point_info.point_name this.searchKeyword = option.point_info.point_name
this.showOptions = false this.showOptions = false
//
this.images = []
} else { } else {
console.warn('选择的点位信息不完整', option) console.warn('选择的点位信息不完整', option)
} }
@ -149,13 +152,39 @@ export default {
} }
try { 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 = { const params = {
task_id: parseInt(this.taskId), // ID task_id: parseInt(this.taskId), // ID
task_point_id: parseInt(this.selectedPoint), // 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); const res = await request(apiArr.routingInspectionSubmit, "POST", params);
@ -168,6 +197,7 @@ export default {
icon: 'success' icon: 'success'
}) })
} catch (error) { } catch (error) {
uni.hideLoading();
console.error('提交失败', error) console.error('提交失败', error)
uni.showToast({ uni.showToast({
title: '提交失败', title: '提交失败',