feat: 优化getBaseURL函数
This commit is contained in:
@@ -3,8 +3,12 @@ import { pluginsAll } from '/@/views/plugins/index';
|
|||||||
/**
|
/**
|
||||||
* @description 校验是否为租户模式。租户模式把域名替换成 域名 加端口
|
* @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;
|
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] || '';
|
let param = baseURL.split('/')[3] || '';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (pluginsAll && pluginsAll.indexOf('dvadmin3-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) {
|
if (pluginsAll && pluginsAll.indexOf('dvadmin3-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) {
|
||||||
@@ -31,9 +35,8 @@ export const getBaseURL = function (url:string) {
|
|||||||
if (regex.test(url)) {
|
if (regex.test(url)) {
|
||||||
return url
|
return url
|
||||||
} else {
|
} else {
|
||||||
if(url.startsWith('/')){
|
// js判断是否是斜杠结尾
|
||||||
return baseURL + url;
|
return baseURL.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!baseURL.endsWith('/')) {
|
if (!baseURL.endsWith('/')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user