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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import router from '@/router';
export const getPortFromUrl=(url) =>{
    try {
        const portPattern = /:\d+/;
        const urlObj = new URL(url);
        const portMatch = portPattern.exec(urlObj.host)[0].slice(1); // 去掉冒号
        return parseInt(portMatch, 10); // 转换为整数
    } catch (error) {
        console.error(error.message);
        return null;
    }
};
export const doHostName=(hostname)=>{
    /* if(hostname.includes('localhost')){
         return hostname;
     }*/
    return hostname.substring(hostname.indexOf(".")+1);
};
export const getApsPage = () => {
    // 首页部署在各个环境的端口
    /* const loginPathMap = {
       prod:`//${window.location.hostname}:9080`,
       test:`//192.168.20.119:9080`,
       // 想跳到本地启动的登录页的话需要把dev改成你本地项目路径
       dev: `//192.168.8.112:8080`
     };*/
    //return loginPathMap[environmentType()]
    let port=getPortFromUrl(window.location.href);//获得端口号
    let hostname=window.location.hostname;// 一级域名
    if(hostname.includes('fai365.com')||hostname.includes('smartai.com')||hostname.includes('navicat.com')) {// 代表存在域名
        hostname='aps.'+doHostName(hostname);
    }
    if(hostname.includes('localhost')){
        port=process.env.VUE_APP_APS_PORT;//端口号与 .env.development 中 VUE_APP_APS_PORT 跟本地aps项目的端口号保持一致
    }
    if(router.mode==='history'){
        if(port){
            return `${hostname}:${port}`;
        }else{
            return `${hostname}`;
        }
    }else{
        if(port){
            return `${hostname}:${port}`+'/#';
        }else{
            return `${hostname}`+'/#';
        }
    }
};