From 33d08361c09d7fea244b453ba989119f2adc265b Mon Sep 17 00:00:00 2001 From: Lyan-u Date: Fri, 6 Sep 2024 08:15:51 +0000 Subject: [PATCH] =?UTF-8?q?fix(indexes):=20=E4=BF=AE=E5=A4=8D=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E4=B8=BA=E6=95=B0=E5=AD=97=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E6=97=B6=E4=BE=A7=E8=BE=B9=E6=A0=8F=E4=B8=8D=E8=83=BD=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=BF=80=E6=B4=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/indexes/indexes.tsx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/indexes/indexes.tsx b/src/indexes/indexes.tsx index 497a22921..01de84713 100644 --- a/src/indexes/indexes.tsx +++ b/src/indexes/indexes.tsx @@ -7,8 +7,8 @@ import { onBeforeUnmount, provide, computed, - ComponentInternalInstance, watch, + ComponentPublicInstance, } from 'vue'; import throttle from 'lodash/throttle'; import { preventDefault } from '../shared/dom'; @@ -16,21 +16,18 @@ import config from '../config'; import IndexesProps from './props'; import { usePrefixClass } from '../hooks/useClass'; import { useTNodeJSX } from '../hooks/tnode'; - -interface Child extends ComponentInternalInstance { - [key: string]: any; -} +import { TdIndexesAnchorProps } from './type'; interface State { showSidebarTip: boolean; activeSidebar: string | number; - children: Child[]; + children: ComponentPublicInstance[]; } interface GroupTop { height: number; top: number; - anchor: string; + anchor: string | number; totalHeight: number; } @@ -146,14 +143,12 @@ export default defineComponent({ const getAnchorsRect = () => { return Promise.all( state.children.map((child) => { - const { $el } = child; - const { dataset } = $el; - const { index } = dataset; + const { $el, index } = child; const rect = $el.getBoundingClientRect(); groupTop.push({ height: rect.height, top: rect.top - parentRect.value.top, - anchor: /^\d+$/.test(index) ? Number(index) : index, + anchor: index, totalHeight: 0, }); return child; @@ -168,7 +163,7 @@ export default defineComponent({ const target = document.elementFromPoint(clientX, clientY); if (target && target.className === `${indexesClass.value}__sidebar-item` && target instanceof HTMLElement) { const { index } = target.dataset; - const curIndex = /^\d+$/.test(index ?? '') ? Number(index) : index; + const curIndex = indexList.value.find((idx) => String(idx) === index); if (curIndex !== undefined && state.activeSidebar !== curIndex) { setActiveSidebarAndTip(curIndex); scrollToByIndex(curIndex); @@ -176,7 +171,7 @@ export default defineComponent({ } }; - const relation = (child: ComponentInternalInstance) => { + const relation = (child: ComponentPublicInstance) => { child && state.children.push(child); };