修改巡检模块提交之后后台数据图片不显示的问题
This commit is contained in:
parent
d0f448789a
commit
06f9b79012
@ -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: '提交失败',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user