mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-28 04:40:37 +00:00
refactor(frontend): 统一域名获取与比较逻辑
- 新增 mainDomain() 函数,简化 mainUrl 域名获取 - 新增 removeMainUrlPrefix() 函数,用于移除 URL 的服务器域名前缀 - getDomain() 返回值统一转为小写,确保域名比较不受大小写影响 - 将多处 getDomain(mainUrl()) 调用替换为 mainDomain(),提升代码可读性
This commit is contained in:
parent
16d5ffd4f9
commit
ce42c2a660
@ -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);
|
||||
// 匹配常见的下载相关路径
|
||||
|
||||
4
resources/assets/js/app.js
vendored
4
resources/assets/js/app.js
vendored
@ -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;
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
2
resources/assets/js/functions/common.js
vendored
2
resources/assets/js/functions/common.js
vendored
@ -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();
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
27
resources/assets/js/functions/web.js
vendored
27
resources/assets/js/functions/web.js
vendored
@ -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();
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -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('扫码登录'),
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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}`)
|
||||
|
||||
6
resources/assets/js/store/actions.js
vendored
6
resources/assets/js/store/actions.js
vendored
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user