增加线上加点功能 在已有路线上新增节点 前端自动分成两条路线

This commit is contained in:
yyy 2025-04-14 17:52:08 +08:00
parent 7fbdf6fb8d
commit fcdf626511
2 changed files with 164 additions and 10 deletions

View File

@ -173,3 +173,17 @@ export const getByMapItemId = async (mapId, mapItemId) => {
url: `/system/ware/house-location/getByMapItemId?mapItemId=${mapItemId}&mapId=${mapId}` url: `/system/ware/house-location/getByMapItemId?mapItemId=${mapItemId}&mapId=${mapId}`
}) })
} }
//线上加点保存点位
export const lineAddItem = async (data) => {
return await request.post({
url: `/system/position-map-item/lineAddItem`,
data
})
}
//获取id
export const getNodeId = async () => {
return await request.get({
url: `/system/position-map-item/getUUid`
})
}

View File

@ -578,7 +578,7 @@
:y2="Number(curve.endPointY)" :y2="Number(curve.endPointY)"
:stroke="curve.isSelected ? '#f48924' : '#2d72d9'" :stroke="curve.isSelected ? '#f48924' : '#2d72d9'"
:stroke-width="state.routeWidthForm.routeWidth" :stroke-width="state.routeWidthForm.routeWidth"
@click="handleChooseRoute(curve, index, 'line')" @click="(e) => handleChooseRoute(curve, index, 'line', e)"
/> />
<text <text
style="user-select: none" style="user-select: none"
@ -588,7 +588,7 @@
text-anchor="middle" text-anchor="middle"
fill="black" fill="black"
v-if="curve.isSelected" v-if="curve.isSelected"
@click="handleChooseRoute(curve, index, 'line')" @click="(e) => handleChooseRoute(curve, index, 'line', e)"
> >
{{ calculateRouteLength(curve, 'line') }} {{ calculateRouteLength(curve, 'line') }}
</text> </text>
@ -601,7 +601,7 @@
:stroke="curve.isSelected ? '#f48924' : '#2d72d9'" :stroke="curve.isSelected ? '#f48924' : '#2d72d9'"
:stroke-width="state.routeWidthForm.routeWidth" :stroke-width="state.routeWidthForm.routeWidth"
fill="none" fill="none"
@click="handleChooseRoute(curve, index, 'curve')" @click="handleChooseRoute(curve, index)"
/> />
<text <text
style="user-select: none" style="user-select: none"
@ -611,7 +611,7 @@
text-anchor="middle" text-anchor="middle"
fill="black" fill="black"
v-if="curve.isSelected" v-if="curve.isSelected"
@click="handleChooseRoute(curve, index, 'curve')" @click="handleChooseRoute(curve, index)"
> >
{{ calculateRouteLength(curve, 'curve') }} {{ calculateRouteLength(curve, 'curve') }}
</text> </text>
@ -730,10 +730,10 @@
<!-- </map-scale-tool> --> <!-- </map-scale-tool> -->
</div> </div>
<!-- <div class="actual-location" v-if="state.actualLocation.x && state.actualLocation.y"> <div class="actual-location" v-if="state.actualLocation.x && state.actualLocation.y">
<div>X{{ state.actualLocation.x }}</div> <div>X{{ state.actualLocation.x }}</div>
<div>Y{{ state.actualLocation.y }}</div> <div>Y{{ state.actualLocation.y }}</div>
</div> --> </div>
<!-- 节点编辑 --> <!-- 节点编辑 -->
<editNodeProperties <editNodeProperties
@ -1133,8 +1133,8 @@ const mapClick = (e) => {
const actualLocationX = disposeEventPoints(e).actualLocationX const actualLocationX = disposeEventPoints(e).actualLocationX
const actualLocationY = disposeEventPoints(e).actualLocationY const actualLocationY = disposeEventPoints(e).actualLocationY
// state.actualLocation.x = actualLocationX state.actualLocation.x = actualLocationX
// state.actualLocation.y = actualLocationY state.actualLocation.y = actualLocationY
// //
if (toolbarSwitchType.value === 'drawNodes') { if (toolbarSwitchType.value === 'drawNodes') {
@ -2618,10 +2618,131 @@ const getCurvePath = (curve) => {
return path return path
} }
// 线 // 线
const handleChooseRoute = (item, index, type) => { const handleChooseRoute = async (item, index, type, e) => {
if (toolbarSwitchType.value === 'addPointOnline') { if (toolbarSwitchType.value === 'addPointOnline') {
//线 线
if (type === 'line') { if (type === 'line') {
} else { const id = await MapApi.getNodeId()
const pageX = disposeEventPoints(e).x
const pageY = disposeEventPoints(e).y
const x = mapPointToLineSegment(item, pageX, pageY).newX
const y = mapPointToLineSegment(item, pageX, pageY).newY
const actualLocationX = disposeEventPoint(x, y).actualLocationX
const actualLocationY = disposeEventPoint(x, y).actualLocationY
let newPoint = {
id: id,
positionMapId: imgBgObj.positionMapId, //id
layerSelectionShow: true,
locationX: x,
locationY: y,
actualLocationX: actualLocationX,
actualLocationY: actualLocationY,
locationDeep: 40,
locationWide: 40,
locationDeepPx: 8,
locationWidePx: 8,
angle: 0,
draggable: true,
resizable: true,
rotatable: false,
lockAspectRatio: false, //
mapImageUrl: '',
locationYaw: 0, //
type: 1, //1
dataList: [], //
dataObj: {} //
}
let positionMapLineOne = {
isSelected: false, //
startingPointId: item.startingPointId,
endPointId: id,
startPointX: item.startPointX, //
startPointY: item.startPointY, //
endPointX: x, //
endPointY: y, //
actualStartPointX: item.actualStartPointX, //x
actualStartPointY: item.actualStartPointY, //y
actualEndPointX: actualLocationX, //x
actualEndPointY: actualLocationY, //y
actualBeginControlX: '', //x
actualBeginControlY: '', //y
actualEndControlX: '', //x
actualEndControlY: '', //y
beginControlX: 0, //x
beginControlY: 0, //y
endControlX: 0, //x
endControlY: 0, //y
expansionZoneFront: 0, //
expansionZoneAfter: 0, //
expansionZoneLeft: 0, //
expansionZoneRight: 0, //
method: 0, // 0.线 1.线2.线3.线 4.线
direction: 2, // 1. 2.,
forwardSpeedLimit: 1.5, //
reverseSpeedLimit: 0.4, //
toward: 0, // ( 0: 1: 2: 3:)
beginWidth: 8, //
beginHigh: 8, //
endWidth: 8, //
endHigh: 8 //
}
let positionMapLineTwo = {
isSelected: false, //
startingPointId: id,
endPointId: item.endPointId,
startPointX: x, //
startPointY: y, //
endPointX: item.endPointX, //
endPointY: item.endPointY, //
actualStartPointX: actualLocationX, //x
actualStartPointY: actualLocationY, //y
actualEndPointX: item.actualEndPointX, //x
actualEndPointY: item.actualEndPointY, //y
actualBeginControlX: '', //x
actualBeginControlY: '', //y
actualEndControlX: '', //x
actualEndControlY: '', //y
beginControlX: 0, //x
beginControlY: 0, //y
endControlX: 0, //x
endControlY: 0, //y
expansionZoneFront: 0, //
expansionZoneAfter: 0, //
expansionZoneLeft: 0, //
expansionZoneRight: 0, //
method: 0, // 0.线 1.线2.线3.线 4.线
direction: 2, // 1. 2.,
forwardSpeedLimit: 1.5, //
reverseSpeedLimit: 0.4, //
toward: 0, // ( 0: 1: 2: 3:)
beginWidth: 8, //
beginHigh: 8, //
endWidth: 8, //
endHigh: 8 //
}
try {
let res = await MapApi.lineAddItem([
{
...newPoint,
oldLineId: id,
positionMapLines: [positionMapLineOne, positionMapLineTwo]
}
])
state.allMapPointInfo.push(newPoint)
state.mapRouteList.push(positionMapLineOne)
state.mapRouteList.push(positionMapLineTwo)
state.mapRouteList.splice(index, 1)
state.allHistoryList[0] = {
allMapPointInfo: JSON.parse(JSON.stringify(state.allMapPointInfo)),
mapRouteList: JSON.parse(JSON.stringify(state.mapRouteList))
}
state.currentIndex = 0
message.success('添加成功')
} catch (e) {
message.error(e)
}
} }
} else { } else {
state.mapRouteList.forEach((curve, i) => { state.mapRouteList.forEach((curve, i) => {
@ -2638,6 +2759,25 @@ const handleChooseRoute = (item, index, type) => {
} }
} }
} }
const mapPointToLineSegment = (linePoint, x, y) => {
const dx = Number(linePoint.endPointX) - Number(linePoint.startPointX)
const dy = Number(linePoint.endPointY) - Number(linePoint.startPointY)
const length = Math.sqrt(dx * dx + dy * dy)
const vx = x - Number(linePoint.startPointX)
const vy = y - Number(linePoint.startPointY)
const dotProduct = vx * dx + vy * dy
const projectionLength = dotProduct / length
const t = Math.max(0, Math.min(1, projectionLength / length))
const newX = Number(linePoint.startPointX) + t * dx
const newY = Number(linePoint.startPointY) + t * dy
return { newX, newY }
}
//线 //线
const editMapRouteDialogSubmit = (form) => { const editMapRouteDialogSubmit = (form) => {
state.mapRouteList[state.currentDragTarget.index] = form state.mapRouteList[state.currentDragTarget.index] = form