安琪酵母(西藏)益生菌信息采集中心智能实验室
longyvfengyun
2023-08-21 66bae94879a1ef44abe28833627564086d74ee13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
/**
 * 获取Websocket的连接
 * @param action
 * @returns {string}
 */
function getWsUrl(action, port) {
  let env = import.meta.env.VITE_APP_ENV;
  let _port = port ? port : 8101;
  let hostname = window.location.hostname;
  let wsProtocol = "ws://";
  if(window.location.protocol == "https:") {
    wsProtocol = "wss://";
  }
  if (env == 'dev') {
    hostname = "localhost";
  }else {
    _port = window.location.port;
  }
  // 处理端口为80
  _port = _port == 80?"":":"+_port;
  return wsProtocol + hostname + _port + '/envir/' + action;
}
 
export default getWsUrl;