|
|
@ -11,7 +11,7 @@ |
|
|
|
|
|
|
|
|
<script lang="ts"> |
|
|
<script lang="ts"> |
|
|
import { defineComponent, ref, unref, nextTick } from 'vue'; |
|
|
import { defineComponent, ref, unref, nextTick } from 'vue'; |
|
|
import { Scrollbar } from '/@/components/Scrollbar'; |
|
|
import { Scrollbar, ScrollbarType } from '/@/components/Scrollbar'; |
|
|
|
|
|
|
|
|
import { useScrollTo } from '/@/hooks/event/useScrollTo'; |
|
|
import { useScrollTo } from '/@/hooks/event/useScrollTo'; |
|
|
|
|
|
|
|
|
@ -19,15 +19,17 @@ |
|
|
name: 'ScrollContainer', |
|
|
name: 'ScrollContainer', |
|
|
components: { Scrollbar }, |
|
|
components: { Scrollbar }, |
|
|
setup() { |
|
|
setup() { |
|
|
const scrollbarRef = ref<RefInstanceType<any>>(null); |
|
|
const scrollbarRef = ref<Nullable<ScrollbarType>>(null); |
|
|
|
|
|
|
|
|
function scrollTo(to: number, duration = 500) { |
|
|
function scrollTo(to: number, duration = 500) { |
|
|
const scrollbar = unref(scrollbarRef); |
|
|
const scrollbar = unref(scrollbarRef); |
|
|
if (!scrollbar) return; |
|
|
if (!scrollbar) return; |
|
|
|
|
|
|
|
|
nextTick(() => { |
|
|
nextTick(() => { |
|
|
|
|
|
const wrap = unref(scrollbar.wrap); |
|
|
|
|
|
if (!wrap) return; |
|
|
const { start } = useScrollTo({ |
|
|
const { start } = useScrollTo({ |
|
|
el: unref(scrollbar.$.wrap), |
|
|
el: wrap, |
|
|
to, |
|
|
to, |
|
|
duration, |
|
|
duration, |
|
|
}); |
|
|
}); |
|
|
@ -38,7 +40,7 @@ |
|
|
function getScrollWrap() { |
|
|
function getScrollWrap() { |
|
|
const scrollbar = unref(scrollbarRef); |
|
|
const scrollbar = unref(scrollbarRef); |
|
|
if (!scrollbar) return null; |
|
|
if (!scrollbar) return null; |
|
|
return scrollbar.$.wrap; |
|
|
return scrollbar.wrap; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function scrollBottom() { |
|
|
function scrollBottom() { |
|
|
@ -46,9 +48,11 @@ |
|
|
if (!scrollbar) return; |
|
|
if (!scrollbar) return; |
|
|
|
|
|
|
|
|
nextTick(() => { |
|
|
nextTick(() => { |
|
|
const scrollHeight = scrollbar.$.wrap.scrollHeight as number; |
|
|
const wrap = unref(scrollbar.wrap); |
|
|
|
|
|
if (!wrap) return; |
|
|
|
|
|
const scrollHeight = wrap.scrollHeight as number; |
|
|
const { start } = useScrollTo({ |
|
|
const { start } = useScrollTo({ |
|
|
el: unref(scrollbar.$.wrap), |
|
|
el: wrap, |
|
|
to: scrollHeight, |
|
|
to: scrollHeight, |
|
|
}); |
|
|
}); |
|
|
start(); |
|
|
start(); |
|
|
|