From cd521a63503bbd50ca93dfedbc9472377f427d76 Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Sat, 17 Sep 2022 11:24:20 +0800 Subject: [PATCH] =?UTF-8?q?:rocket:=20=E9=9B=86=E6=88=90SSE,=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E4=B9=B1=E7=A0=81=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AMap/src/AMapDesigner/index.vue | 28 +++++++++++++++++-- src/settings/componentSetting.ts | 8 +++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/components/AMap/src/AMapDesigner/index.vue b/src/components/AMap/src/AMapDesigner/index.vue index 8821c15..4025c78 100644 --- a/src/components/AMap/src/AMapDesigner/index.vue +++ b/src/components/AMap/src/AMapDesigner/index.vue @@ -123,8 +123,6 @@ import { useI18n } from '/@/hooks/web/useI18n'; import { useDebounceFn } from '@vueuse/core'; - var source = new EventSource('http://localhost:8080/sse/subscribe?id=yihuihui'); - /** 类型规范统一声明定义区域 */ interface MapState { first: boolean; @@ -170,7 +168,6 @@ let courierUserMarkerCluster; let scanCourierUserCircleRange; let driving; - const { t } = useI18n(); const emit = defineEmits(['success']); const userStore = useUserStore(); @@ -466,6 +463,31 @@ })); orgMarkerCluster?.setData(orgPoints); + // sse长轮询连接获取收样员gps位置 + if (!!window.EventSource) { + // 建立连接 + const source = new EventSource(mapDesigner.sseUrl); + + source.addEventListener('open', function (e) { + console.info(e,'建立连接。。。'); + }, false); + + source.addEventListener('message', function (e) { + source.close(); + console.info(e); + }); + + source.addEventListener('error', function (e) { + console.info(e); + }, false); + + } else { + notification.error({ + message: '你的浏览器不支持SSE', + description: '请更换浏览器,在尝试使用此功能!', + duration: 2 + }); + } // 加载完毕 complete(); }).catch(error => { diff --git a/src/settings/componentSetting.ts b/src/settings/componentSetting.ts index 3247302..9017e4d 100644 --- a/src/settings/componentSetting.ts +++ b/src/settings/componentSetting.ts @@ -5,6 +5,10 @@ * @create: 2022/4/7 */ import type { SorterResult } from '../components/Table'; +import { getAccessToken } from '/@/utils/auth'; +import { buildUUID } from '/@/utils/uuid'; +import { useGlobSetting } from '/@/hooks/setting'; +const { apiUrl } = useGlobSetting(); export default { // 基本表设置 @@ -50,6 +54,8 @@ export default { // 默认中心点 mapCenter: '112.919043, 28.288623', // 默认缩放 - defaultZoom: 17 + defaultZoom: 17, + // sse后端地址 + sseUrl: `${apiUrl}/common_proxy/common/mapLogisticSse/subscribe?clientId=${buildUUID()}&accessToken=${getAccessToken()}` } };