diff --git a/web/src/utils/baseUrl.ts b/web/src/utils/baseUrl.ts index d2e1af6..6b55c27 100644 --- a/web/src/utils/baseUrl.ts +++ b/web/src/utils/baseUrl.ts @@ -3,8 +3,12 @@ import { pluginsAll } from '/@/views/plugins/index'; /** * @description 校验是否为租户模式。租户模式把域名替换成 域名 加端口 */ -export const getBaseURL = function (url:string) { +export const getBaseURL = function (url: null | string = null, isHost: null | boolean = null) { let baseURL = import.meta.env.VITE_API_URL as any; + // 如果需要host返回,时,返回地址前缀加http地址 + if (isHost && !baseURL.startsWith('http')) { + baseURL = window.location.protocol + '//' + window.location.host + baseURL + } let param = baseURL.split('/')[3] || ''; // @ts-ignore if (pluginsAll && pluginsAll.indexOf('dvadmin3-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) { @@ -26,14 +30,13 @@ export const getBaseURL = function (url:string) { baseURL = location.protocol + '//' + location.hostname + (location.port ? ':' : '') + location.port + baseURL; } } - if(url){ + if (url) { const regex = /^(http|https):\/\//; - if(regex.test(url)){ + if (regex.test(url)) { return url - }else{ - if(url.startsWith('/')){ - return baseURL + url; - } + } else { + // js判断是否是斜杠结尾 + return baseURL.replace(/\/$/, '') + '/' + url.replace(/^\//, ''); } } if (!baseURL.endsWith('/')) {