|
|
@ -618,21 +618,21 @@ export default { |
|
|
}, |
|
|
}, |
|
|
/** 弹窗点击“确定”:正式将数据保存到后端数据库 */ |
|
|
/** 弹窗点击“确定”:正式将数据保存到后端数据库 */ |
|
|
async confirmSaveNewRoute() { |
|
|
async confirmSaveNewRoute() { |
|
|
// 严格校验起名逻辑 |
|
|
// 1. 严格校验 |
|
|
if (!this.newRouteName || this.newRouteName.trim() === '') { |
|
|
if (!this.newRouteName || this.newRouteName.trim() === '') { |
|
|
this.$message.error('新增航线未命名,请输入名称后保存!'); |
|
|
this.$message.error('新增航线未命名,请输入名称后保存!'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
// 获取当前选中的方案 ID |
|
|
|
|
|
const currentScenarioId = this.selectedPlanId; |
|
|
const currentScenarioId = this.selectedPlanId; |
|
|
if (!currentScenarioId) { |
|
|
if (!currentScenarioId) { |
|
|
this.$message.warning('请先在左侧选择一个方案,再保存航线!'); |
|
|
this.$message.warning('请先在左侧选择一个方案,再保存航线!'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
// 构造符合后端 Routes 实体类的数据结构 |
|
|
|
|
|
|
|
|
// 2. 构造数据 |
|
|
const routeData = { |
|
|
const routeData = { |
|
|
callSign: this.newRouteName, |
|
|
callSign: this.newRouteName, |
|
|
scenarioId: currentScenarioId || 1, // 使用当前选中的方案ID,默认1 |
|
|
scenarioId: currentScenarioId, |
|
|
platformId: 1, |
|
|
platformId: 1, |
|
|
attributes: "{}", |
|
|
attributes: "{}", |
|
|
waypoints: this.tempMapPoints.map((p, index) => ({ |
|
|
waypoints: this.tempMapPoints.map((p, index) => ({ |
|
|
@ -645,45 +645,55 @@ export default { |
|
|
turnAngle: 0.0 |
|
|
turnAngle: 0.0 |
|
|
})) |
|
|
})) |
|
|
}; |
|
|
}; |
|
|
|
|
|
try { |
|
|
|
|
|
const response = await addRoutes(routeData); |
|
|
|
|
|
if (response.code === 200) { |
|
|
|
|
|
this.$message.success('航线及其航点已成功保存至当前方案'); |
|
|
|
|
|
|
|
|
try { |
|
|
const savedRoute = response.data; |
|
|
// 调用后端 API 保存到数据库 |
|
|
const newRouteId = savedRoute ? savedRoute.id : null; |
|
|
const response = await addRoutes(routeData); |
|
|
|
|
|
if (response.code === 200) { |
|
|
// 1. 立即停止绘制并清除临时线(不要用 clearRoute) |
|
|
this.$message.success('航线及其航点已成功保存至当前方案'); |
|
|
if (this.$refs.cesiumMap) { |
|
|
// 获取后端生成的正式 ID |
|
|
this.drawDom = false; |
|
|
const savedRoute = response.data; |
|
|
if (this.$refs.cesiumMap.clearTempRoute) this.$refs.cesiumMap.clearTempRoute(); |
|
|
const newRouteId = savedRoute ? savedRoute.id : null; |
|
|
|
|
|
if (this.$refs.cesiumMap) { |
|
|
|
|
|
this.$refs.cesiumMap.clearRoute(); |
|
|
|
|
|
// 如果拿到了正式 ID,则按照“正式航线”的规则渲染一次 |
|
|
|
|
|
if (newRouteId) { |
|
|
|
|
|
if (!this.activeRouteIds.includes(savedRoute.id)) { |
|
|
|
|
|
this.activeRouteIds.push(savedRoute.id); |
|
|
|
|
|
} |
|
|
|
|
|
// 更新当前详情,确保右侧下方航点列表立刻显示 |
|
|
|
|
|
this.selectedRouteDetails = { |
|
|
|
|
|
id: newRouteId, |
|
|
|
|
|
name: this.newRouteName, |
|
|
|
|
|
waypoints: routeData.waypoints |
|
|
|
|
|
}; |
|
|
|
|
|
//使用正式 ID 渲染点和线 |
|
|
|
|
|
this.$refs.cesiumMap.renderRouteWaypoints(routeData.waypoints, newRouteId); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 先执行刷新列表,同步后端数据库状态 |
|
|
|
|
|
await this.getList(); |
|
|
|
|
|
|
|
|
|
|
|
// 3. 在列表刷新后的“下一帧”执行选中和渲染逻辑 |
|
|
|
|
|
this.$nextTick(async () => { |
|
|
|
|
|
if (newRouteId) { |
|
|
|
|
|
// 确保新 ID 在激活列表中(触发右侧勾选 UI) |
|
|
|
|
|
if (!this.activeRouteIds.includes(newRouteId)) { |
|
|
|
|
|
this.activeRouteIds.push(newRouteId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 重新锁定选中详情,防止被 getList 重置为空 |
|
|
|
|
|
this.selectedRouteId = newRouteId; |
|
|
|
|
|
this.selectedRouteDetails = { |
|
|
|
|
|
id: newRouteId, |
|
|
|
|
|
name: this.newRouteName, |
|
|
|
|
|
waypoints: routeData.waypoints |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 显式执行连线渲染 |
|
|
|
|
|
if (this.$refs.cesiumMap) { |
|
|
|
|
|
this.$refs.cesiumMap.renderRouteWaypoints(routeData.waypoints, newRouteId); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 重置弹窗 UI |
|
|
|
|
|
this.showNameDialog = false; |
|
|
|
|
|
this.newRouteName = ''; |
|
|
|
|
|
this.tempMapPoints = []; |
|
|
} |
|
|
} |
|
|
// 重置 UI 状态 |
|
|
} catch (error) { |
|
|
this.showNameDialog = false; |
|
|
console.error("保存失败:", error); |
|
|
this.drawDom = false; |
|
|
|
|
|
this.newRouteName = ''; |
|
|
|
|
|
this.tempMapPoints = []; |
|
|
|
|
|
// 重新拉取右侧航线列表以保持同步 |
|
|
|
|
|
await this.getList(); |
|
|
|
|
|
} |
|
|
} |
|
|
} catch (error) { |
|
|
}, |
|
|
console.error("保存航线失败:", error); |
|
|
|
|
|
this.$message.error('保存失败,请检查后端服务'); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
// 航点编辑弹窗相关方法 |
|
|
// 航点编辑弹窗相关方法 |
|
|
openWaypointDialog(waypoint) { |
|
|
openWaypointDialog(waypoint) { |
|
|
this.selectedWaypoint = waypoint; |
|
|
this.selectedWaypoint = waypoint; |
|
|
|