类似 http://localhost:9528/#/device/monitorTalkBack
或 https://192.168.11.11:9528/#/device/monitorTalkBack
取 http://localhost:9528/或https://192.168.11.11:9528/
function getLocalHostPath(){
//获取项目url
let cur = window.document.location.href;
//获取项目名
let pathname = window.document.location.pathname;
let localhostPath;
//如果项目名不是根路径,根据项目名直接找到索引,截取
if(pathname!="/") {
let pos = cur.indexOf( pathname );
localhostPath = cur.substring( 0, pos )+'/';
}else{
//如果项目名是根路径,根据正则进行截取
let reg = /((http:\/\/|https:\/\/)(\w|\.)*:\d*\/)(.*)/
localhostPath = cur.replace(reg,function ($,$1,$2,$3,$4) {
return $1;
})
}
return localhostPath
}