Files
tuanwei-admin/src/utils/ws-url.ts
T
gxwebsoft 567e4aabdb feat(user): 支持修改当前用户资料接口并更新个人中心调用
- 新增 updateSelfUser 方法,用于修改当前登录用户的个人资料
- 个人中心调用接口由原 updateUser 切换为 updateSelfUser,避免学生账号权限不足导致的保存失败
- 更新了头像保存、个人信息保存等相关调用代码,添加异常捕获和提示
- 修正环境变量 .env.development 中 API URL 配置为生产地址
- 优化审核记录排序逻辑,新增获取最新审核记录和编辑入口显示判断函数
- 调整审核状态标签使用统一排序规则,防止显示和编辑状态不一致
- 新增社团活动、社团编辑、志愿时长录入、学分记录编辑、社会实践学分申报、青马学员编辑等多个新增组件及表单功能
- 各新增功能支持表单验证、操作反馈和数据加载优化
2026-11-05 19:03:40 +08:00

31 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { API_BASE_URL } from '@/config/setting';
/**
* 统一拼接「当前登录用户」的 WebSocket 地址。
*
* <p>2026-10-21 起统一走 {@code /api} 前缀(后端端点为 {@code /api/chat/{userId}})。
* 原先这里会把 {@code /api} 主动剥掉再拼 {@code /chat/${userId}},现场网关
* (twai-api.gxmu.edu.cn)只对 {@code /api} 放行 WebSocket 升级,导致握手被降级成
* 普通 GET 而返回 404。现在与其它接口同前缀,减少一类环境差异。
*
* <p>若后端回退到旧路径,只需把 {@link USER_WS_PATH} 改成 {@code '/chat'}。
*/
const USER_WS_PATH = '/chat';
export const buildUserWebSocketUrl = (userId: number | string): string => {
const suffix = `${USER_WS_PATH}/${userId}`;
// 绝对地址(生产/联调):https://host/api -> wss://host/api/chat/{userId}
if (/^https?:\/\//.test(API_BASE_URL)) {
const url = new URL(API_BASE_URL);
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
url.pathname = url.pathname.replace(/\/+$/, '');
return `${url.toString().replace(/\/$/, '')}${suffix}`;
}
// 相对地址(VITE_API_URL=/api):与页面同源
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const base = API_BASE_URL.replace(/\/+$/, '');
return `${protocol}//${window.location.host}${base}${suffix}`;
};