Skip to content

Commit

Permalink
fix: 优化设备判断-优化url处理
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jan 11, 2023
1 parent f6d693b commit aae7ee0
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions utils/otherlib/ChromeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ export const FROM_CONSTANTS = {
FROM_CHROME,
}

/**
* 通过 host 拼接url
* @param host
* @param srcUrl
* @param split
* @returns {string}
*/
const appendHost = (host, srcUrl, split) => {
let url = srcUrl
let baseUrl = window.location.protocol + "//" + host
if (split && split !== "") {
baseUrl = window.location.protocol + "//" + host + split
}

// 智能拼接
url = pathJoin(baseUrl, url)
return url
}

/**
* 在chrome插件打开网页
*
Expand Down Expand Up @@ -95,30 +114,20 @@ export const getPageUrl = (pageUrl, split) => {
url = setUrlParameter(url, "from", from)
}

// 处理手动分隔符
// 处理host
let host = window.location.host
if (isInSiyuanNewWinBrowser()) {
const ipv4 = window.terwer.ip
host = ipv4 + ":" + window.location.port
}
let baseUrl = window.location.protocol + "//" + host
if (split && split !== "") {
baseUrl = window.location.protocol + "//" + host + split
}

// 智能拼接
url = pathJoin(baseUrl, url)
// 拼接url
url = appendHost(host, url, split)
} else if (deviceType === DeviceType.DeviceType_Chrome_Extension) {
url = chrome.runtime.getURL(url)
} else {
let host = window.location.host
let baseUrl = window.location.protocol + "//" + host
if (split && split !== "") {
baseUrl = window.location.protocol + "//" + host + split
}
url = setUrlParameter(url, "from", FROM_CONSTANTS.FROM_CHROME)
// 智能拼接
url = pathJoin(baseUrl, url)
// 拼接url
url = appendHost(host, url, split)
}

logger.warn("将要打开页面=>", url)
Expand Down

0 comments on commit aae7ee0

Please sign in to comment.