From 30ce5ae75b9c5e2158af16991e7fafda353142aa Mon Sep 17 00:00:00 2001 From: yyy <2605810609@qq.com> Date: Fri, 28 Feb 2025 11:25:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=A0=E9=80=92=E5=8F=82=E6=95=B0=E7=BB=99?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E5=9C=B0=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/map/map.ts | 6 +-- src/views/mapPage/realTimeMap/editMap.vue | 54 +++++++++++++---------- src/views/mapPage/realTimeMap/index.vue | 16 +++---- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/api/map/map.ts b/src/api/map/map.ts index df1b7e19..43303bad 100644 --- a/src/api/map/map.ts +++ b/src/api/map/map.ts @@ -29,8 +29,8 @@ export const downloadPositionMap = async (params) => { return await request.get({ url: `/system/position-map/download`, params }) } //获得仓库点位地图 -export const getPositionMap = async (params) => { - return await request.get({ url: `/system/position-map/get`, params }) +export const getPositionMap = async (id) => { + return await request.get({ url: `/system/position-map/get?id=` + id }) } // 文件上传 export const uploadPositionMap = async (data) => { @@ -135,4 +135,4 @@ export const mapLineGet = async (params) => { //通过地图id获取连线列表 export const mapLineListGet = async (params) => { return await request.get({ url: `/system/position-map-line/list`, params }) -} \ No newline at end of file +} diff --git a/src/views/mapPage/realTimeMap/editMap.vue b/src/views/mapPage/realTimeMap/editMap.vue index c854927b..f2c73b24 100644 --- a/src/views/mapPage/realTimeMap/editMap.vue +++ b/src/views/mapPage/realTimeMap/editMap.vue @@ -1993,20 +1993,25 @@ const imgBgObj = reactive({ height: '', floor: '', area: '', - resolution: 0.05, - origin: [-54.4, -34.2] + resolution: 0, + origin: null }) //接收参数 const { query } = useRoute() // 查询参数 //获取地图点位 const getMapList = async () => { - if (query.mapId) { - imgBgObj.positionMapId = query.mapId - imgBgObj.floor = query.floor - imgBgObj.area = query.area - //调转换成png的接口 - getMapData(imgBgObj) - } + if (!query.mapId) return + let res = await MapApi.getPositionMap(query.mapId) + let yamlJson = JSON.parse(res.yamlJson) + imgBgObj.positionMapId = res.id + imgBgObj.floor = res.floor + imgBgObj.area = res.area + imgBgObj.width = yamlJson.width + imgBgObj.height = yamlJson.height + imgBgObj.origin = yamlJson.origin + imgBgObj.resolution = yamlJson.resolution + // //调转换成png的接口 + getMapData(imgBgObj) } //调转换成png的接口 const getMapData = async (mapInfo) => { @@ -2016,20 +2021,9 @@ const getMapData = async (mapInfo) => { }) imgBgObj.imgUrl = data - //获取一下图片的宽高 - const img = new Image() - img.src = imgBgObj.imgUrl - //加载图片成功 - img.onload = () => { - imgBgObj.width = img.naturalWidth - imgBgObj.height = img.naturalHeight - getAllNodeList() - getAllMapRoute() - } - //加载图片失败 - img.onerror = () => { - console.error('图片加载失败') - } + //获取节点 路径等信息 + getAllNodeList() + getAllMapRoute() } //获取所有的点位 处理七种类型的 const getAllNodeList = async () => { @@ -2306,6 +2300,20 @@ const removeEventListener = () => { window.removeEventListener('keydown', handleKeyDown) } +const router = useRouter() +onBeforeRouteLeave((to, from) => { + if (to.fullPath == '/mapPage/realTimeMap') { + router.replace({ + name: 'MapPageRealTimeMap', + query: { + floor: imgBgObj.floor, + area: imgBgObj.area, + mapId: imgBgObj.positionMapId + } + }) + } +}) + onMounted(() => { getMapList() window.addEventListener('keydown', handleKeyDown) diff --git a/src/views/mapPage/realTimeMap/index.vue b/src/views/mapPage/realTimeMap/index.vue index fa82509b..4c03022e 100644 --- a/src/views/mapPage/realTimeMap/index.vue +++ b/src/views/mapPage/realTimeMap/index.vue @@ -112,7 +112,6 @@ const getList = async () => { } list.value = mapList - console.log(list.value, data) if (mapValue.value.length) { handleChangeMap(mapValue.value) } else { @@ -135,7 +134,6 @@ const handleChangeMap = async (e) => { floor: '', area: '' } - console.log(mapInfo.value) indexPageRef.value.getMapData(mapInfo.value) } //新建任务 @@ -163,9 +161,7 @@ const editMap = () => { router.push({ name: 'editMapPageRealTimeMap', query: { - mapId: mapInfo.value.id, - floor: mapInfo.value.floor, - area: mapInfo.value.area + mapId: mapInfo.value.id } }) } @@ -176,14 +172,12 @@ const mapInfo = ref({ floor: '', area: '' }) -// const transmitMapInfo = (map) => { -// mapInfo.value = map -// } onMounted(() => { - if (route.query.floorArea) { - console.log(route.query.floorArea, route) - mapValue.value = JSON.parse(route.query.floorArea) + if (route.query.mapId) { + mapInfo.value.mapId = route.query.mapId + mapInfo.value.floor = route.query.floor + mapInfo.value.area = route.query.area } getList() })