/* * @Author: your name * @Date: 2021-04-19 15:46:08 * @LastEditTime: 2025-12-02 17:00:17 * @LastEditors: xieyunhui awesomedema@gmail.com * @Description: In User Settings Edit * @FilePath: /web_TracerMethodology/utils/requestUrl.js */ // const base = '192.168.51.80:8801/imed/pfm/'; export const networkType = 1; //网络类型:内网=0,外网=1 // 运行时可更新的网关域名,由授权查询接口返回的 region 动态设置 export function setRuntimeRegionDomain(region) { try { if (region && typeof region === 'string') { uni.setStorageSync('runtimeRegion', region); } } catch (e) {} } export function getRuntimeRegionDomain() { try { const r = uni.getStorageSync('runtimeRegion'); return r || ''; } catch (e) { return ''; } } // 计算当前基础URL(无兜底,必须授权设置后才可用) export function getBaseURL() { // #ifdef H5 try { if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'production') { // H5 生产:直连真实网关 return 'http://47.97.190.5:8806/imed/pfm/'; // return 'http://120.27.235.181:8806/imed/pfm/'; // return 'http://120.27.235.181:8802/imed/pfm/'; } } catch (e) {} // H5 开发:走本地代理前缀(由 devServer 重写到 /imed/pfm) return '/TracerMethodology/api/'; // #endif // 非 H5(例如 APP)走授权下发的网关域名 const region = getRuntimeRegionDomain(); if (!region) { try { uni.showToast({ title: '接口域名缺失,请重新授权', icon: 'none' }); } catch (e) {} throw new Error('Missing runtime region domain'); } const hasProtocol = /^https?:\/\//i.test(region); // 默认拼接 /imed/pfm/ 路径,可按需调整 const origin = hasProtocol ? region : `http://${region}`; const normalizedOrigin = origin.replace(/\/$/, ''); return `${normalizedOrigin}/imed/pfm/`; } // 兼容旧导出:提供一个按需计算的 URL 常量访问器 export function getURL() { return getBaseURL(); } // WebSocket地址生成:基于当前HTTP基础地址替换协议 export const wsURL = (hiId, user, permission) => { const httpBase = getBaseURL(); const wsBase = httpBase.replace(/^http:/i, 'ws:').replace(/^https:/i, 'wss:'); return `${wsBase}websocket/${hiId}/${user}/${permission}`; }