diff --git a/electron/utils.js b/electron/utils.js index d07adaa52..07fabada9 100644 --- a/electron/utils.js +++ b/electron/utils.js @@ -275,11 +275,24 @@ const utils = { * @returns {string|string} */ getDomain(weburl) { - let urlReg = /http(s)?:\/\/([^\/]+)/i; - let domain = (weburl + "").match(urlReg); + const urlReg = /http(s)?:\/\/([^\/]+)/i; + const domain = `${weburl}`.match(urlReg); return ((domain != null && domain.length > 0) ? domain[2] : ""); }, + /** + * 提取 URL 协议 + * @param weburl + * @returns {string} + */ + getProtocol(weburl) { + try { + return new URL(weburl).protocol + } catch(e){ + return "" + } + }, + /** * 显示窗口 * @param win diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 2308146b8..d84c23134 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -651,6 +651,51 @@ const timezone = require("dayjs/plugin/timezone"); return this.rightDelete(url.replace("?&", "?"), '?'); }, + /** + * 替换url中的hash + * @param {string} url - 要修改的URL;如果只提供一个参数,则作为新的hash路径,URL默认为当前页面 + * @param {string} [path] - 新的hash路径,可包含或不包含#前缀 + * @returns {string} 替换hash后的URL + */ + urlReplaceHash(url, path = undefined) { + // 如果只传了一个参数,将其视为path,url默认为当前页面 + if (path === undefined) { + path = url; + url = window.location.href; + } + + // 确保url有值 + url = url || window.location.href; + + try { + // 使用URL API正确解析URL各部分 + const urlObj = new URL(url); + + // 确保path是字符串并格式正确 + path = String(path || ''); + if (path && path.startsWith('#')) { + path = path.substring(1); + } + + // 设置新的hash + urlObj.hash = path; + + return urlObj.toString(); + } catch (e) { + // 如果URL解析失败,回退到简单的字符串替换方法 + if (!path) { + return url.replace(/#.*$/, ''); + } + + const hashPath = path.startsWith('#') ? path : '#' + path; + if (url.includes('#')) { + return url.replace(/#.*$/, hashPath); + } else { + return url + hashPath; + } + } + }, + /** * 刷新当前地址 * @returns {string} @@ -1017,11 +1062,24 @@ const timezone = require("dayjs/plugin/timezone"); * @returns {string|string} */ getDomain(weburl) { - let urlReg = /http(s)?:\/\/([^\/]+)/i; - let domain = (weburl + "").match(urlReg); + const urlReg = /http(s)?:\/\/([^\/]+)/i; + const domain = `${weburl}`.match(urlReg); return ((domain != null && domain.length > 0) ? domain[2] : ""); }, + /** + * 提取 URL 协议 + * @param weburl + * @returns {string} + */ + getProtocol(weburl) { + try { + return new URL(weburl).protocol + } catch(e){ + return "" + } + }, + /** * 滚动到View * @param element diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 018104c3b..1f904a111 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -2364,7 +2364,7 @@ export default { block: 'end', behavior: 'smooth' }) - }, 500, 100, 3) + }, 500, 500, 3) } }, @@ -3799,7 +3799,7 @@ export default { params: { titleFixed: true, allowAccess: true, - url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` + url: $A.urlReplaceHash(path) }, }) } else { diff --git a/resources/assets/js/pages/manage/components/FileHistory.vue b/resources/assets/js/pages/manage/components/FileHistory.vue index 65db1d7f6..6b031b293 100644 --- a/resources/assets/js/pages/manage/components/FileHistory.vue +++ b/resources/assets/js/pages/manage/components/FileHistory.vue @@ -202,7 +202,7 @@ export default { params: { titleFixed: true, allowAccess: true, - url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` + url: $A.urlReplaceHash(path) }, }) } else { diff --git a/resources/assets/js/pages/manage/components/ProjectLog.vue b/resources/assets/js/pages/manage/components/ProjectLog.vue index f889a3f55..834678a35 100644 --- a/resources/assets/js/pages/manage/components/ProjectLog.vue +++ b/resources/assets/js/pages/manage/components/ProjectLog.vue @@ -236,7 +236,7 @@ export default { url: 'web.js', params: { allowAccess: true, - url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` + url: $A.urlReplaceHash(path) }, }) } else { diff --git a/resources/assets/js/pages/manage/components/TaskContentHistory.vue b/resources/assets/js/pages/manage/components/TaskContentHistory.vue index 1bb1dfb27..0a61a3d7b 100644 --- a/resources/assets/js/pages/manage/components/TaskContentHistory.vue +++ b/resources/assets/js/pages/manage/components/TaskContentHistory.vue @@ -189,7 +189,7 @@ export default { params: { titleFixed: true, allowAccess: true, - url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` + url: $A.urlReplaceHash(path) }, }) } else { diff --git a/resources/assets/js/pages/manage/components/TaskDetail.vue b/resources/assets/js/pages/manage/components/TaskDetail.vue index a106b8680..aa391e8b9 100755 --- a/resources/assets/js/pages/manage/components/TaskDetail.vue +++ b/resources/assets/js/pages/manage/components/TaskDetail.vue @@ -1899,7 +1899,7 @@ export default { params: { titleFixed: true, allowAccess: true, - url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` + url: $A.urlReplaceHash(path) }, }); } else { diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index 0d60ac998..aeeed8513 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -1123,7 +1123,7 @@ export default { params: { titleFixed: true, allowAccess: true, - url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` + url: $A.urlReplaceHash(path) }, }); } else { diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 160b90b76..efe85ac3d 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -1171,13 +1171,15 @@ export default { */ userUrl({state}, url) { return new Promise(resolve => { - const newUrl = $A.urlAddParams(url, { + const params = { language: languageName, theme: state.themeConf, userid: state.userId, - token: state.userToken, - }) - resolve(newUrl) + } + if ($A.getDomain(url) == $A.getDomain($A.mainUrl()) || $A.getProtocol(url) == "file:") { + params.token = state.userToken + } + resolve($A.urlAddParams(url, params)) }) },