no message

This commit is contained in:
kuaifan 2025-04-11 09:31:43 +08:00
parent 5489462f90
commit bfdb72dd0a
9 changed files with 88 additions and 15 deletions

17
electron/utils.js vendored
View File

@ -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

View File

@ -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) {
// 如果只传了一个参数将其视为pathurl默认为当前页面
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

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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))
})
},