diff --git a/packages/opendesign/src/_utils/is.ts b/packages/opendesign/src/_utils/is.ts index 6153085f1f2803ae03012c4d1749f700a7d082dd..5c27ca586e0b007748b5599d8249f9bdba7fc039 100644 --- a/packages/opendesign/src/_utils/is.ts +++ b/packages/opendesign/src/_utils/is.ts @@ -84,3 +84,26 @@ export const isHoverDevice = isClient ? window.matchMedia('(hover: hover)').matc export function isWindow(val: unknown): val is Window { return val === window; } + +/** + * 判断一个给定的路径是否是当前页面的内部链接 + * @param {string} link - 需要判断的路径(可以是相对路径、绝对路径或完整URL) + * @returns {boolean} - 如果是外部链接返回true,否则返回false + */ +export function isCurrentPageLink(link: string): boolean { + // 处理锚点或空路径,通常视为内部链接 + if (link.startsWith('#')) { + return true; + } + + try { + // 使用URL对象解析目标路径(以当前页面为基准) + const targetUrl = new URL(link, window.location.href); + + // 比较协议、主机名、端口和路径 + return targetUrl.origin + targetUrl.pathname === window.location.origin + window.location.pathname; + } catch { + // 如果URL解析失败(如不规范的路径),判定为外部链接 + return false; + } +} diff --git a/packages/opendesign/src/anchor/OAnchor.vue b/packages/opendesign/src/anchor/OAnchor.vue index deb53ecf38805a936531de6d68759f588ea204a6..6f385ffb427e239a80e16b127d1c7c517f3dcab8 100644 --- a/packages/opendesign/src/anchor/OAnchor.vue +++ b/packages/opendesign/src/anchor/OAnchor.vue @@ -1,13 +1,16 @@ @@ -51,5 +80,6 @@ import { OAnchor, OAnchorItem } from '../index'; position: fixed; top: 200px; right: 60px; + display: flex; } diff --git a/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue b/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue index 8f395ea73786151d4383fc2d39c250e03a39f387..ac7addf227aeb51414257ff9590cdf0f2e2bf49a 100644 --- a/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue +++ b/packages/opendesign/src/anchor/__docs__/__case__/AnchorUsage.vue @@ -3,6 +3,10 @@ ### 使用 +`size` 属性 + +- 说明:指定锚点的尺寸风格(默认值:medium) + `container` 属性 - 说明:指定锚点监听的滚动容器(默认值:window) @@ -32,6 +36,10 @@ ### Usage +`size` property + +- Description:The size of anchor (default: medium) + `container` property - Description: Specifies the scroll container to be monitored by the anchor (default: window) @@ -59,7 +67,11 @@ Nested anchors: `OAnchorItem` can be nested to create multi-level anchor structu