diff --git a/.env.development b/.env.development index 5bb03fd..e160334 100644 --- a/.env.development +++ b/.env.development @@ -25,4 +25,4 @@ VITE_APP_RSA_PUBLIC_KEY = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbf VITE_APP_CLIENT_ID = 'e5cd7e4891bf95d1d19206ce24a7b32e' #websocket地址 -VITE_APP_WEBSOCKET_URL = 'ws://127.0.0.1:8098/resource/websocket' \ No newline at end of file +VITE_APP_WEBSOCKET_URL = '/resource/websocket' \ No newline at end of file diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index eafaaff..013eb1c 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -98,14 +98,13 @@ import { ComponentInternalInstance } from "vue"; import { TenantVO } from "@/api/types"; import notice from './notice/index.vue'; import useNoticeStore from '@/store/modules/notice'; -import { getToken } from '@/utils/auth'; const appStore = useAppStore(); const userStore = useUserStore(); const settingsStore = useSettingsStore(); const noticeStore = storeToRefs(useNoticeStore()); const newNotice = ref(0); -let websocket = new WebSocket(import.meta.env.VITE_APP_WEBSOCKET_URL + '?Authorization=Bearer ' + getToken() + '&clientid=' + import.meta.env.VITE_APP_CLIENT_ID); + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const userId = ref(userStore.userId); @@ -181,7 +180,8 @@ const handleCommand = (command: string) => { commandMap[command](); } } -//用深度监听 + +//用深度监听 消息 watch(() => noticeStore.state.value.notices, (newVal, oldVal) => { newNotice.value = newVal.length; }, { deep: true }); diff --git a/src/views/index.vue b/src/views/index.vue index e740ac6..4896ef1 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -99,7 +99,7 @@ import { initWebSocket } from '@/utils/websocket'; onMounted(() => { -initWebSocket(import.meta.env.VITE_APP_WEBSOCKET_URL); + initWebSocket("ws://"+window.location.host+import.meta.env.VITE_APP_BASE_API+import.meta.env.VITE_APP_WEBSOCKET_URL); }); const goTarget = (url:string) => { diff --git a/src/views/tool/webSocket/index.vue b/src/views/tool/webSocket/index.vue index 4452bb0..60d9a98 100644 --- a/src/views/tool/webSocket/index.vue +++ b/src/views/tool/webSocket/index.vue @@ -38,7 +38,7 @@ interface Conf { } const conf = reactive({ - url: import.meta.env.VITE_APP_WEBSOCKET_URL, // 连接地址 + url: "ws://localhost"+import.meta.env.VITE_APP_BASE_API+import.meta.env.VITE_APP_WEBSOCKET_URL, // 连接地址 send: '123', // 发送信息 message: [], // 消息列表 }); diff --git a/vite.config.ts b/vite.config.ts index cadaf62..788aace 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -28,6 +28,7 @@ export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => { [env.VITE_APP_BASE_API]: { target: 'http://localhost:8080', changeOrigin: true, + ws: true, rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '') } }