From 7c52f083db30f7e68c3e10a88cbc47d41cf9de20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=97=E5=A4=A7?= Date: Mon, 25 Mar 2024 14:24:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(VirtualScroll):=20=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E5=A2=9E=E5=8A=A0=E6=BB=9A=E5=8A=A8=E5=88=B0?= =?UTF-8?q?=E9=A1=B6=E9=83=A8,=20=E5=BA=95=E9=83=A8,=20=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E9=A1=B9=E6=96=B9=E6=B3=95=20(#3687)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VirtualScroll/src/VirtualScroll.vue | 34 ++++++++++++++++++- src/design/ant/input.less | 3 +- src/views/demo/comp/scroll/VirtualScroll.vue | 28 +++++++++++++-- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/components/VirtualScroll/src/VirtualScroll.vue b/src/components/VirtualScroll/src/VirtualScroll.vue index 255100327..12080cb70 100644 --- a/src/components/VirtualScroll/src/VirtualScroll.vue +++ b/src/components/VirtualScroll/src/VirtualScroll.vue @@ -52,7 +52,7 @@ export default defineComponent({ name: 'VirtualScroll', props, - setup(props, { slots }) { + setup(props, { slots, expose }) { const wrapElRef = ref(null); const state = reactive({ first: 0, @@ -128,6 +128,31 @@ state.last = getLast(state.first); } + function scrollToTop() { + const wrapEl = unref(wrapElRef); + if (!wrapEl) { + return; + } + wrapEl.scrollTop = 0; + } + + function scrollToBottom() { + const wrapEl = unref(wrapElRef); + if (!wrapEl) { + return; + } + wrapEl.scrollTop = wrapEl.scrollHeight; + } + + function scrollToItem(index: number) { + const wrapEl = unref(wrapElRef); + if (!wrapEl) { + return; + } + const i = index - 1 > 0 ? index - 1 : 0; + wrapEl.scrollTop = i * unref(getItemHeightRef); + } + function renderChildren() { const { items = [] } = props; return items.slice(unref(getFirstToRenderRef), unref(getLastToRenderRef)).map(genChild); @@ -143,6 +168,13 @@ ); } + expose({ + wrapElRef, + scrollToTop, + scrollToItem, + scrollToBottom, + }); + onMounted(() => { state.last = getLast(0); nextTick(() => { diff --git a/src/design/ant/input.less b/src/design/ant/input.less index 8245fb724..18a133ae7 100644 --- a/src/design/ant/input.less +++ b/src/design/ant/input.less @@ -4,8 +4,7 @@ .ant-input { &-number, &-number-group-wrapper { - width: 100% !important; - min-width: 110px; + width: 100%; max-width: 100%; } } diff --git a/src/views/demo/comp/scroll/VirtualScroll.vue b/src/views/demo/comp/scroll/VirtualScroll.vue index 69697e492..c3b146fd4 100644 --- a/src/views/demo/comp/scroll/VirtualScroll.vue +++ b/src/views/demo/comp/scroll/VirtualScroll.vue @@ -1,8 +1,26 @@