完成仓库模块
This commit is contained in:
@@ -107,7 +107,6 @@ function checkoutItem(id: string) {
|
||||
checkoutPointlist.value.push(id);
|
||||
const find = pointslist.value.find((item) => item.id === id);
|
||||
if (find && find.location) {
|
||||
console.log(find.location, find.pointName);
|
||||
if (find && find.location) {
|
||||
addPointMarker(id, find.location, find.pointName);
|
||||
}
|
||||
@@ -172,7 +171,6 @@ function init() {
|
||||
pathPoints: res.data.pathPoints, // 巡检路线经纬度
|
||||
totalPoints: res.data.totalPoints // 巡检点
|
||||
};
|
||||
console.log('巡检路线详情:', form.value);
|
||||
nextTick(() => {
|
||||
if (routeid.value) {
|
||||
checkoutPointlist.value = res.data.totalPoints ? res.data.totalPoints.split(',') : [];
|
||||
@@ -187,7 +185,6 @@ function init() {
|
||||
}
|
||||
// 回显路线
|
||||
if (res.data.pathPoints) {
|
||||
console.log('回显巡检点:', res.data.pathPoints);
|
||||
renderSavedPath(res.data.pathPoints);
|
||||
}
|
||||
}
|
||||
@@ -242,7 +239,6 @@ onMounted(async () => {
|
||||
if (drawnPolylines.value.length > 0) {
|
||||
map.value.remove(drawnPolylines.value[0]);
|
||||
}
|
||||
|
||||
drawnPolylines.value = [e.obj];
|
||||
// 画完继续允许画下一条(但永远只保留一条)
|
||||
initDrawTool();
|
||||
@@ -315,47 +311,67 @@ function clearAll() {
|
||||
// !!! 核心:获取绘制的路线经纬度数组
|
||||
function getPolylinePath() {
|
||||
if (drawnPolylines.value.length === 0) return [];
|
||||
const lastLine = drawnPolylines.value.at(-1);
|
||||
console.log('最后一条线的路径:', lastLine.getPath());
|
||||
const lastLine = drawnPolylines.value.pop();
|
||||
const path = lastLine.getPath().map((p) => [p.lng, p.lat]);
|
||||
return path;
|
||||
}
|
||||
/**
|
||||
* 修复高德地图 Polyline 闭合路线最后一段不显示
|
||||
* 解决:最后两点坐标相同 → 长度0 → 不渲染
|
||||
*/
|
||||
function fixClosePath(path: number[][]): number[][] {
|
||||
if (!path || path.length < 2) return path;
|
||||
|
||||
const newPath = [...path];
|
||||
|
||||
// 如果是闭合路线(最后一点 ≈ 第一点)
|
||||
const first = newPath[0];
|
||||
const last = newPath[newPath.length - 1];
|
||||
|
||||
// 判断是否几乎重合
|
||||
const isSame = Math.abs(last[0] - first[0]) < 1e-8 && Math.abs(last[1] - first[1]) < 1e-8;
|
||||
|
||||
if (isSame) {
|
||||
// 【关键】最后一点极微小偏移,强制生成线段
|
||||
newPath[newPath.length - 1] = [last[0] + 0.0000001, last[1] + 0.0000001];
|
||||
}
|
||||
|
||||
return newPath;
|
||||
}
|
||||
|
||||
// !== 提交 =============================================================================
|
||||
const submitForm = () => {
|
||||
formRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
// 获取路线经纬度
|
||||
const path = getPolylinePath() as [number, number][];
|
||||
if (path.length === 0) {
|
||||
ElMessage.warning('请绘制巡检路线');
|
||||
return;
|
||||
}
|
||||
// 转成字符串传给后端
|
||||
const [start_lng, start_lat] = path.shift() as [number, number];
|
||||
const [end_lng, end_lat] = path.pop() as [number, number];
|
||||
|
||||
form.value.startLng = `${start_lng}`;
|
||||
form.value.startLat = `${start_lat}`;
|
||||
form.value.endLng = `${end_lng}`;
|
||||
form.value.endLat = `${end_lat}`;
|
||||
|
||||
form.value.pathPoints = JSON.stringify(path);
|
||||
form.value.totalPoints = checkoutPointlist.value.join(',');
|
||||
|
||||
console.log('提交数据:', form.value);
|
||||
if (routeid.value) {
|
||||
updateRoute(form.value).then(() => {
|
||||
ElMessage.success('编辑成功');
|
||||
cancelForm();
|
||||
});
|
||||
} else {
|
||||
addRoute(form.value).then(() => {
|
||||
ElMessage.success('添加成功');
|
||||
cancelForm();
|
||||
});
|
||||
}
|
||||
// if (valid) {
|
||||
// 获取路线经纬度
|
||||
const path = getPolylinePath() as [number, number][];
|
||||
if (path.length === 0) {
|
||||
ElMessage.warning('请绘制巡检路线');
|
||||
return;
|
||||
}
|
||||
// 转成字符串传给后端
|
||||
const [start_lng, start_lat] = path.at(0) as [number, number];
|
||||
const [end_lng, end_lat] = path.at(-1) as [number, number];
|
||||
|
||||
form.value.startLng = `${start_lng}`;
|
||||
form.value.startLat = `${start_lat}`;
|
||||
form.value.endLng = `${end_lng}`;
|
||||
form.value.endLat = `${end_lat}`;
|
||||
|
||||
form.value.pathPoints = JSON.stringify(path);
|
||||
form.value.totalPoints = checkoutPointlist.value.join(',');
|
||||
if (routeid.value) {
|
||||
updateRoute(form.value).then(() => {
|
||||
ElMessage.success('编辑成功');
|
||||
cancelForm();
|
||||
});
|
||||
} else {
|
||||
addRoute(form.value).then(() => {
|
||||
ElMessage.success('添加成功');
|
||||
cancelForm();
|
||||
});
|
||||
}
|
||||
// }
|
||||
});
|
||||
};
|
||||
// 返回
|
||||
|
||||
Reference in New Issue
Block a user