refactor(frontend): 统一域名获取与比较逻辑

- 新增 mainDomain() 函数,简化 mainUrl 域名获取
  - 新增 removeMainUrlPrefix() 函数,用于移除 URL 的服务器域名前缀
  - getDomain() 返回值统一转为小写,确保域名比较不受大小写影响
  - 将多处 getDomain(mainUrl()) 调用替换为 mainDomain(),提升代码可读性
This commit is contained in:
kuaifan 2026-01-10 05:48:25 +00:00
parent 16d5ffd4f9
commit ce42c2a660
9 changed files with 38 additions and 17 deletions

View File

@ -411,7 +411,7 @@ export default {
return 1;
}
//
if ($A.getDomain(url) == $A.getDomain($A.mainUrl())) {
if ($A.getDomain(url) == $A.mainDomain()) {
try {
const {pathname, searchParams} = new URL(url);
// meeting/1234567890/xxxxx
@ -438,7 +438,7 @@ export default {
},
isDownloadUrl(url) {
if ($A.getDomain(url) == $A.getDomain($A.mainUrl())) {
if ($A.getDomain(url) == $A.mainDomain()) {
try {
const {pathname, searchParams} = new URL(url);
//

View File

@ -129,7 +129,7 @@ Vue.prototype.goForward = function(route, isReplace, autoBroadcast = true) {
if (typeof route === 'string') {
if ($A.strExists(route, '/')) {
if (/^https?:\/\//.test(route)) {
if ($A.getDomain(route) === $A.getDomain($A.mainUrl())) {
if ($A.getDomain(route) === $A.mainDomain()) {
route = route.replace(/^https?:\/\/[^\/]+/, '');
} else {
// 处理外部链接
@ -357,7 +357,7 @@ const $preload = async () => {
document.querySelector(".app-view-loading")?.setAttribute("data-visible", "false")
window.__initializeApp = async (loadHash) => {
if (/^https?:\/\//.test(loadHash)) {
if ($A.getDomain(loadHash) !== $A.getDomain($A.mainUrl())) {
if ($A.getDomain(loadHash) !== $A.mainDomain()) {
window.location.href = url;
return;
}

View File

@ -159,7 +159,7 @@ export default {
if (this.compareVersion(this.apiVersion, '0.19.0') === -1) {
$A.modalWarning({
title: '温馨提示',
message: `服务器(${$A.getDomain($A.mainUrl())})接口版本过低,部分功能可能无法正常使用。`,
message: `服务器(${$A.mainDomain()})接口版本过低,部分功能可能无法正常使用。`,
});
}
if (this.$Electron) {

View File

@ -1185,7 +1185,7 @@ const timezone = require("dayjs/plugin/timezone");
getDomain(weburl) {
const urlReg = /http(s)?:\/\/([^\/]+)/i;
const domain = `${weburl}`.match(urlReg);
return ((domain != null && domain.length > 0) ? domain[2] : "");
return ((domain != null && domain.length > 0) ? domain[2] : "").toLowerCase();
},
/**

View File

@ -62,6 +62,29 @@ import {convertLocalResourcePath} from "../components/Replace/utils";
return $A.apiUrl(`../${str}`)
},
/**
* 获取 mainUrl 的域名
* @returns {string}
*/
mainDomain() {
return $A.getDomain($A.mainUrl());
},
/**
* 移除 mainUrl 前缀忽略 http/https 协议差异只匹配域名
* @param url
* @returns {string} 匹配时返回带前导斜杠的路径 /path/to不匹配时返回原始 url
*/
removeMainUrlPrefix(url) {
url = url + "";
const urlDomain = $A.getDomain(url);
const mainDomain = $A.mainDomain();
if (urlDomain && mainDomain && urlDomain === mainDomain) {
return url.replace(/^https?:\/\/[^\/]+/, '');
}
return url;
},
/**
* 服务地址
* @param str
@ -514,7 +537,7 @@ import {convertLocalResourcePath} from "../components/Replace/utils";
* @returns {boolean}
*/
isDooServer() {
const u = $A.getDomain($A.mainUrl())
const u = $A.mainDomain()
return /dootask\.com$/.test(u)
|| /hitosea\.com$/.test(u)
|| /^127\.0\.0\.1/.test(u)
@ -598,7 +621,7 @@ import {convertLocalResourcePath} from "../components/Replace/utils";
if (!/\.(png|jpg|jpeg)$/.test(url)) {
return false
}
return $A.getDomain(url) == $A.getDomain($A.mainUrl());
return $A.getDomain(url) == $A.mainDomain();
},
/**

View File

@ -1202,10 +1202,10 @@ export default {
const arr = (text + "").match(/^https?:\/\/(.*?)\/login\?qrcode=(.*?)$/)
if (arr) {
//
if ($A.getDomain(text) != $A.getDomain($A.mainUrl())) {
if ($A.getDomain(text) != $A.mainDomain()) {
let content = this.$L('请确认扫码的服务器与当前服务器一致')
content += `<br/>${this.$L('二维码服务器')}: ${$A.getDomain(text)}`
content += `<br/>${this.$L('当前服务器')}: ${$A.getDomain($A.mainUrl())}`
content += `<br/>${this.$L('当前服务器')}: ${$A.mainDomain()}`
$A.modalWarning({
language: false,
title: this.$L('扫码登录'),

View File

@ -401,9 +401,7 @@ export default {
width: Math.min(window.screen.availWidth, 1440),
height: Math.min(window.screen.availHeight, 900),
}
const meetingLink = $A.leftDelete(linkRes.data, $A.mainUrl())
.replace(/^\//, '');
const meetingPath = $A.urlAddParams("/" + meetingLink, {
const meetingPath = $A.urlAddParams($A.removeMainUrlPrefix(linkRes.data), {
type: 'direct',
nickname: data.nickname,
avatar: data.userimg,

View File

@ -220,7 +220,7 @@ export default {
async onVersion() {
const array = [
`${this.$L('服务器')}: ${$A.getDomain($A.mainUrl())}`
`${this.$L('服务器')}: ${$A.mainDomain()}`
]
if (this.serverVersion) {
array.push(`${this.$L('服务器版本')}: v${this.serverVersion}`)

View File

@ -1287,7 +1287,7 @@ export default {
userUrl({state}, url) {
return new Promise(resolve => {
// 如果是访问:服务器域名 且 当前是本地文件,则将服务器域名替换成本地路径
if ($A.getDomain(url) == $A.getDomain($A.mainUrl()) && isLocalHost(window.location)) {
if ($A.getDomain(url) == $A.mainDomain() && isLocalHost(window.location)) {
try {
const remoteURL = new URL(url)
if (/^\/(single|meeting)\//.test(remoteURL.pathname)) {
@ -1308,7 +1308,7 @@ export default {
userid: state.userId,
}
// 如果是访问:服务器域名 或 本地文件,则添加 token 参数
if ($A.getDomain(url) == $A.getDomain($A.mainUrl()) || isLocalHost(url)) {
if ($A.getDomain(url) == $A.mainDomain() || isLocalHost(url)) {
params.token = state.userToken
}
resolve($A.urlAddParams(url, params))
@ -1402,7 +1402,7 @@ export default {
// 外站 URL 自动移除 preload 脚本(通过 contextIsolation: false
const pathDomain = $A.getDomain(params.path)
const isExternal = pathDomain && pathDomain !== $A.getDomain($A.mainUrl())
const isExternal = pathDomain && pathDomain !== $A.mainDomain()
if (isExternal) {
params.webPreferences = Object.assign({contextIsolation: false}, params.webPreferences)
} else {