From b61ca7f5679139cb8a0152d9377257800062fefd Mon Sep 17 00:00:00 2001 From: wx <645899409@qq.com> Date: Wed, 9 Jul 2025 19:38:59 +0800 Subject: [PATCH] =?UTF-8?q?update=201.=E6=B7=BB=E5=8A=A0=E6=80=A5=E6=95=91?= =?UTF-8?q?=E8=B7=AF=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/mapUtils/map.ts | 41 ++++++++++++++ src/assets/mapUtils/mapConstant.ts | 11 +++- src/views/indexSun.vue | 4 +- src/views/indexSun/centerMap.vue | 91 ++++++++++++++++++------------ src/views/indexSun/indexSun.ts | 9 ++- vite.config.ts | 3 +- 6 files changed, 115 insertions(+), 44 deletions(-) diff --git a/src/assets/mapUtils/map.ts b/src/assets/mapUtils/map.ts index 4464c4e..8a57989 100644 --- a/src/assets/mapUtils/map.ts +++ b/src/assets/mapUtils/map.ts @@ -9,6 +9,7 @@ import { defaultOption, getZoom, mapKey, mapPlugin } from '/@/assets/mapUtils/ma let AMap = null; export const Map = { + aMap: null, map: null, overlayGroup: null, // 地图中marker circleGroup: null, //直升机背景圆 @@ -19,6 +20,9 @@ export const Map = { infoWindow: null, //地图弹窗 driveLine: null, // 导航轨迹线 emergencyMarker: null, // 应急人员marker + startMarker: null, + endMarker: null, + clearSOrE: null, /** * @desc 地图舒适化 * @param el dom元素 id选择器 @@ -34,6 +38,7 @@ export const Map = { plugins: mapPlugin, // 需要使用的的插件列表,如比例尺'AMap.Scale'等 }).then((res) => { AMap = res; + this.aMap = res; const { zoom, center, mapStyle } = { ...defaultOption, ...option }; //基本地图加载 this.map = new AMap.Map(el, { @@ -476,4 +481,40 @@ export const Map = { this.clearNaviLine(); this.clearEmergencyMarker(); }, + createSMarker(position: any) { + if (this.startMarker) { + this.startMarker?.setMap(null); + this.startMarker = null; + } + + this.startMarker = new AMap.Marker({ + position: position, + offset: new AMap.Pixel(0, 0), + }); + this.map.add(this.startMarker); + this.setZoomCenter(position); + }, + createEMarker(position: any) { + if (this.endMarker) { + this.endMarker?.setMap(null); + this.endMarker = null; + } + + this.endMarker = new AMap.Marker({ + position: position, + offset: new AMap.Pixel(0, 0), + }); + this.map.add(this.endMarker); + this.setZoomCenter(position); + }, + clearSOrE() { + if (this.startMarker) { + this.startMarker?.setMap(null); + this.startMarker = null; + } + if (this.endMarker) { + this.endMarker?.setMap(null); + this.endMarker = null; + } + }, }; diff --git a/src/assets/mapUtils/mapConstant.ts b/src/assets/mapUtils/mapConstant.ts index c49f5a8..ae6d75f 100644 --- a/src/assets/mapUtils/mapConstant.ts +++ b/src/assets/mapUtils/mapConstant.ts @@ -23,7 +23,16 @@ export const innerLineLight = { // 地图key export const mapKey = '4bbcb216b889f2d612cbed05ae6979c8'; // 地图插件 -export const mapPlugin = ['AMap.ToolBar', 'AMap.Driving', 'AMap.GeoJSON', 'AMap.MarkerCluster', 'AMap.PlaceSearch', 'AMap.Driving', 'AMap.Geocoder']; +export const mapPlugin = [ + 'AMap.ToolBar', + 'AMap.Driving', + 'AMap.GeoJSON', + 'AMap.MarkerCluster', + 'AMap.PlaceSearch', + 'AMap.Driving', + 'AMap.Geocoder', + 'AMap.AutoComplete', +]; //根据数据量设置地图层级 export function getZoom(list = []) { diff --git a/src/views/indexSun.vue b/src/views/indexSun.vue index c9060aa..700f85f 100644 --- a/src/views/indexSun.vue +++ b/src/views/indexSun.vue @@ -105,7 +105,7 @@ import { handleSocketUrl, startTime } from '/@/utils/utils.ts'; import { useUserStore } from '/@/store/modules/user.ts'; - const { getCenterInfo } = useUserStore(); + const { getCenterInfo, setCount } = useUserStore(); import { oneLApi, roomDetailApi, @@ -273,6 +273,7 @@ watch(socketData, (nVal) => { if (nVal) { nextTick(() => { + setCount(); setSocketData(nVal); employeeDialogRef.value.openDialog(); }); @@ -285,6 +286,7 @@ const emergencyDialogRef = ref(); //紧急求助 watch(socketData1, (nVal) => { if (nVal) { + setCount(); setSocketData1(nVal); emergencyDialogRef.value.openDialog(); } diff --git a/src/views/indexSun/centerMap.vue b/src/views/indexSun/centerMap.vue index acfe699..1c2e7a8 100644 --- a/src/views/indexSun/centerMap.vue +++ b/src/views/indexSun/centerMap.vue @@ -2,17 +2,17 @@
-
+
{{ item.name }}
- + - + 清空 @@ -20,7 +20,7 @@
-
+
@@ -65,9 +65,9 @@
-
{{ item.name }}
-
相距{{ item.distance }}
-
驾车大约{{ item.driveTime }}
+
{{ item?.name }}
+
相距{{ item?.distance }}
+
驾车大约{{ item?.driveTime }}
@@ -123,7 +123,8 @@ const level = ref(0); const routeList = ref([]); const emits = defineEmits(['clearHospitalList', 'showRestB', 'handleDetail']); - + let placeSearch = null; + let driving = null; watch( () => props.showHospitalList, (v) => { @@ -143,6 +144,17 @@ getMapData(tabList[0].type); Map.map && Map.map.on('zoomend', setLevel); Map.map && Map.map.on('zoomend', setLevel); + placeSearch = new Map.aMap.PlaceSearch({ + extensions: 'all', + pageIndex: 1, + pageSize: 10, + showMarker: false, + }); + // 确保 AutoComplete 加载完成后再使用 + const startAuto = new Map.aMap.AutoComplete({ input: 'startInput' }); + const endAuto = new Map.aMap.AutoComplete({ input: 'endInput' }); + startAuto.on('select', startSelect); + endAuto.on('select', endSelect); }); $bus.on(earlyWarning, (params) => { drawMarker(params); @@ -157,6 +169,27 @@ }); }); + function startSelect(e: any) { + placeSearch.search(e.poi.name, function (status, result) { + if (status === 'complete' && result.poiList.pois.length > 0) { + const poi = result.poiList.pois[0]; // 取第一个结果 + const { lat, lng } = poi.location; + formState.value.start = poi.name; + Map.createSMarker([lng, lat]); + } + }); + } + function endSelect(e: any) { + placeSearch.search(e.poi.name, function (status, result) { + if (status === 'complete' && result.poiList.pois.length > 0) { + const poi = result.poiList.pois[0]; // 取第一个结果 + const { lat, lng } = poi.location; + formState.value.end = poi.name; + Map.createEMarker([lng, lat]); + } + }); + } + function showDrivingLine(item) { nextTick(() => { panelTitle.value = '全程' + item.driveTime + item.distance; @@ -183,29 +216,13 @@ function changeTab(item: any, i: number) { closeDrivingElement(); currentIndex.value = i; - if (item.type) { - tab(item); - } + tab(item); } function tab(item: any) { Map.clearActiveHospital(); Map.map.off('moveend', logMapinfo); - if (TabType.diFangYiYuan == item.type) { - let { lng, lat } = Map.getMapCenter(); - Map.getAddressByPoint([lng, lat]).then((text, data) => { - // console.log('data', data, data.citycode); - }); - Map.removeOverlayGroup(); - Map.map.on('moveend', logMapinfo); - return; - } - // if (TabType.zhiShengJi == item.type) { - // Map.createAircraft(aircraft); - // return; - // } else { - // getMapData(item.type, { type: item.type }); - // } + getMapData(item.type, { type: item.type }); } function watchInfoChangeTab(item: any) { @@ -223,13 +240,13 @@ return message.warn('请输入终点'); } searchFlag.value = true; - let map = new AMap.Map('container', { - resizeEnable: true, - center: [116.397428, 39.90923], //地图中心点 - zoom: 13, //地图显示的缩放级别 - }); - let driving = new AMap.Driving({ - map: map, + // let map = new Map.aMap.Map('container', { + // resizeEnable: true, + // center: [116.397428, 39.90923], //地图中心点 + // zoom: 13, //地图显示的缩放级别 + // }); + driving = new Map.aMap.Driving({ + map: Map.map, panel: 'panel', }); driving.search([{ keyword: formState.value.start }, { keyword: formState.value.end }], function (status, result) { @@ -241,7 +258,7 @@ searchFlag.value = false; } }); - AMap.Event.addListener(driving, 'complete', (res) => { + Map.aMap.Event.addListener(driving, 'complete', (res) => { const data = JSON.parse(JSON.stringify(res)); searchFlag.value = false; if (data.info == 'OK') { @@ -301,6 +318,7 @@ } function closeDrivingElement() { + if (driving) driving.clear(); Map.clearNavigationElements(); formState.value.start = ''; formState.value.end = ''; @@ -345,6 +363,7 @@ } function resetMap() { + Map.clearSOrE(); closeDrivingElement(); changeTab(list.value[currentIndex.value], currentIndex.value); emits('showRestB'); @@ -404,7 +423,7 @@ border-radius: 6px; position: absolute; top: 36px; - z-index: 999; + z-index: 100; transition: all 0.3s; :deep(.form-item-self) { @@ -679,7 +698,7 @@ position: absolute; left: 0; top: 50px; - z-index: 99; + z-index: 101; font-size: 20px; cursor: pointer; padding: 0px 6px; diff --git a/src/views/indexSun/indexSun.ts b/src/views/indexSun/indexSun.ts index de3efc1..8e1010b 100644 --- a/src/views/indexSun/indexSun.ts +++ b/src/views/indexSun/indexSun.ts @@ -7,10 +7,9 @@ export const legend1 = new URL('/@/assets/img/legend1.png', import.meta.url).hre export const legend2 = new URL('/@/assets/img/legend5.png', import.meta.url).href; export const legend3 = new URL('/@/assets/img/legend3.png', import.meta.url).href; -async function getDict(code) { - return await getDictByCode2({ dictCode: code }); -} -export const checkData = await getDict('xj_check_type'); +export const checkData = await (async () => { + return await getDictByCode2({ dictCode: 'xj_check_type' }); +})(); export function getClassCharts(dx, dy, m) { return { @@ -159,7 +158,7 @@ export function infoContent1(res) {
`; } diff --git a/vite.config.ts b/vite.config.ts index 168169d..5b7b223 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -56,12 +56,13 @@ export default defineConfig({ }, optimizeDeps: { esbuildOptions: { - target: 'es2020', + target: 'esnext', }, // @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly include: ['lodash-es', 'ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US'], }, build: { + target: 'esnext', sourcemap: false, // rollupOptions: { // output: {