功能变化: 修改baseUrl函数

This commit is contained in:
猿小天
2023-12-26 10:49:09 +08:00
parent 0c1cf1218b
commit d0feaa23e5
3 changed files with 17 additions and 7 deletions

View File

@@ -3,9 +3,9 @@ import { pluginsAll } from '/@/views/plugins/index';
/**
* @description 校验是否为租户模式。租户模式把域名替换成 域名 加端口
*/
export const getBaseURL = function () {
var baseURL = import.meta.env.VITE_API_URL as any;
var param = baseURL.split('/')[3] || '';
export const getBaseURL = function (url:string) {
let baseURL = import.meta.env.VITE_API_URL as any;
let param = baseURL.split('/')[3] || '';
// @ts-ignore
if (pluginsAll && pluginsAll.indexOf('dvadmin3-tenants-web') !== -1 && (!param || baseURL.startsWith('/'))) {
// 1.把127.0.0.1 替换成和前端一样域名
@@ -26,6 +26,16 @@ export const getBaseURL = function () {
baseURL = location.protocol + '//' + location.hostname + (location.port ? ':' : '') + location.port + baseURL;
}
}
if(url){
const regex = /^(http|https):\/\//;
if(regex.test(url)){
return url
}else{
if(url.startsWith('/')){
return baseURL + url;
}
}
}
if (!baseURL.endsWith('/')) {
baseURL += '/';
}