From 5de8de007b53564557216e5f77f297d5b0ccffec Mon Sep 17 00:00:00 2001 From: Seven <1530011482@qq.com> Date: Wed, 30 Sep 2026 14:22:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=BC=80=E5=8F=91=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=92=8C=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83=E7=9A=84?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 3 +++ .env.production | 2 ++ DESIGN.md | 2 +- src/utils/config.js | 2 ++ src/utils/request.js | 4 ++-- src/utils/websocket.js | 5 ++--- 6 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .env.development create mode 100644 .env.production create mode 100644 src/utils/config.js diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..d5a9566 --- /dev/null +++ b/.env.development @@ -0,0 +1,3 @@ +# 必须要以VUE_APP_打头,不然识别不了 +VUE_APP_HTTP_BASE_URL=/api +VUE_APP_WS_URL=ws://localhost:3000 \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..ba3b3d4 --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +VUE_APP_HTTP_BASE_URL=http://localhost:3000/api +VUE_APP_WS_URL=ws://localhost:3000 \ No newline at end of file diff --git a/DESIGN.md b/DESIGN.md index fc1e575..2afb05d 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -189,7 +189,7 @@ HTTP 401 会清理认证状态并导航至登录页。用户主动退出会先 以下内容是根据当前代码观察到的限制,供后续迭代使用,并非已实现功能: -1. **运行配置集中化**:HTTP base URL 与 WebSocket 地址目前分散/硬编码,应按开发、测试、生产环境配置,减少部署时遗漏。 +1. **运行配置集中化**:HTTP base URL 与 WebSocket 地址目前分散/硬编码,应按开发、测试、生产环境配置,减少部署时遗漏。(已解决) 2. **认证状态持久性**:token 会持久化,但 username 不持久化;刷新后需由用户信息接口恢复展示状态。还应评估 localStorage 对 token 的安全取舍及 token 过期刷新方案。 3. **WebSocket 健壮性**:当前没有断线重连、心跳、待发送队列或连接状态 UI;发送前应明确连接不可用的反馈,并评估 ACK 超时及重复消息处理。 4. **会话切换与分页状态**:`loadEnd` 等分页标志需要在联系人切换时明确重置;异步消息请求也应避免旧联系人响应覆盖新联系人视图。 diff --git a/src/utils/config.js b/src/utils/config.js new file mode 100644 index 0000000..dfc937b --- /dev/null +++ b/src/utils/config.js @@ -0,0 +1,2 @@ +export const HTTP_BASE_URL = process.env.VUE_APP_HTTP_BASE_URL; +export const WS_URL = process.env.VUE_APP_WS_URL; \ No newline at end of file diff --git a/src/utils/request.js b/src/utils/request.js index af83552..8a49ce9 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,6 +1,7 @@ import axios from 'axios'; import store from '../store'; import router from '../router'; +import { HTTP_BASE_URL } from "./config" let redirectingToLogin = false; @@ -25,8 +26,7 @@ function redirectToLogin() { // 配置请求 const request = axios.create({ - // baseURL: process.env.REACT_APP_API_BASE_URL, - baseURL: "/api", + baseURL: HTTP_BASE_URL, timeout: 10000, }); diff --git a/src/utils/websocket.js b/src/utils/websocket.js index 25b1dcc..ae10762 100644 --- a/src/utils/websocket.js +++ b/src/utils/websocket.js @@ -1,7 +1,6 @@ -let ws = null; +import { WS_URL } from "./config"; -// WebSocket连接地址 -const WS_URL = "ws://localhost:3000"; +let ws = null; // 建立WebSocket连接 export function connectWebSocket(token, onMessage, onOpen, onClose, onError) {