fix: 修复1:: 形式的ipv6校验失败的bug

This commit is contained in:
xiaojunnuo
2026-01-31 02:07:06 +08:00
parent 52cbff0e15
commit 8b96f218d5
6 changed files with 37 additions and 12 deletions
@@ -60,6 +60,7 @@ import { request } from "/@/api/service";
import { Dicts } from "../lib/dicts";
import { useRouter } from "vue-router";
import { useDomainImport, useDomainImportManage } from "/@/views/certd/cert/domain/use";
import { openRouteInNewWindow } from "/@/vben/utils";
defineOptions({
name: "DomainSelector",
@@ -190,7 +191,7 @@ const router = useRouter();
function openDomainManager(e: any) {
e.preventDefault();
// router.push("/certd/cert/domain");
window.open(`${window.location.origin}/#/certd/cert/domain`);
openRouteInNewWindow("/certd/cert/domain");
}
const openDomainImportManageDialog = useDomainImportManage();
@@ -4,8 +4,16 @@ function isIpv6(d: string) {
if (!d) {
return false;
}
const isIPv6Regex = /^([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})$/gm;
return isIPv6Regex.test(d);
// const isIPv6Regex = /^([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})$/gm;
// return isIPv6Regex.test(d);
try {
// 尝试构造URL,用IPv6作为hostname
new URL(`http://[${d}]`);
return true;
} catch {
return false;
}
}
function isIpv4(d: string) {
if (!d) {
@@ -167,7 +167,6 @@ function useMixedMenu() {
* @param path 路由路径
*/
function calcSideMenus(path: string = route.path) {
debugger;
let { rootMenu } = findRootMenuByPath(menus.value, path);
if (!rootMenu) {
rootMenu = menus.value.find((item: any) => item.path === path);
@@ -27,8 +27,12 @@ function openWindow(url: string, options: OpenWindowOptions = {}): void {
*/
function openRouteInNewWindow(path: string) {
const { hash, origin } = location;
let pathname = location.pathname;
if (pathname.endsWith("/")) {
pathname = pathname.slice(0, -1);
}
const fullPath = path.startsWith("/") ? path : `/${path}`;
const url = `${origin}${hash ? "/#" : ""}${fullPath}`;
const url = `${origin}${pathname}${hash ? "/#" : ""}${fullPath}`;
openWindow(url, { target: "_blank" });
}