fix: ScrollContainer的一个问题

pull/38/head
xingyu 2023-10-10 12:12:33 +08:00
parent 88c1f5c2c4
commit 57314ee1d0
3 changed files with 36 additions and 15 deletions

View File

@ -6,6 +6,10 @@ import { useScrollTo } from '@/hooks/event/useScrollTo'
defineOptions({ name: 'ScrollContainer' })
defineProps({
scrollHeight: { type: Number },
})
const scrollbarRef = ref<Nullable<ScrollbarType>>(null)
/**
@ -72,7 +76,12 @@ defineExpose({ scrollbarRef, scrollTo, scrollBottom, getScrollWrap })
</script>
<template>
<Scrollbar ref="scrollbarRef" class="scroll-container" v-bind="$attrs">
<Scrollbar
ref="scrollbarRef"
class="scroll-container"
:scroll-height="scrollHeight"
v-bind="$attrs"
>
<slot />
</Scrollbar>
</template>

View File

@ -26,7 +26,7 @@ const spinRef = ref<ElRef>(null)
const realHeightRef = ref(0)
const minRealHeightRef = ref(0)
let realHeight = 0
const realHeight = ref(0);
const stopElResizeFn: Fn = () => {}
@ -122,13 +122,13 @@ async function setModalHeight() {
return
await nextTick()
// if (!realHeight) {
realHeight = spinEl.scrollHeight
realHeight.value = spinEl.scrollHeight
// }
if (props.fullScreen)
realHeightRef.value = window.innerHeight - props.modalFooterHeight - props.modalHeaderHeight - 28
else
realHeightRef.value = props.height ? props.height : realHeight > maxHeight ? maxHeight : realHeight
realHeightRef.value = props.height ? props.height : realHeight.value > maxHeight ? maxHeight : realHeight.value
emit('heightChange', unref(realHeightRef))
}
@ -141,7 +141,7 @@ defineExpose({ scrollTop })
</script>
<template>
<ScrollContainer ref="wrapperRef">
<ScrollContainer ref="wrapperRef" :scrollHeight="realHeight">
<div ref="spinRef" v-loading="loading" :style="spinStyle" :loading-tip="loadingTip">
<slot />
</div>

View File

@ -1,5 +1,5 @@
<script lang="ts" setup>
import { computed, nextTick, onBeforeUnmount, onMounted, provide, ref, unref } from 'vue'
import { computed, nextTick, onBeforeUnmount, onMounted, provide, ref, unref, watch } from 'vue'
import { toObject } from './util'
import Bar from './bar'
import { addResizeListener, removeResizeListener } from '@/utils/event'
@ -33,6 +33,11 @@ const props = defineProps({
type: String,
default: 'div',
},
scrollHeight: {
// scrollHeight
type: Number,
default: 0,
},
})
const sizeWidth = ref('0')
@ -69,6 +74,15 @@ function update() {
sizeWidth.value = widthPercentage < 100 ? `${widthPercentage}%` : ''
}
watch(
() => props.scrollHeight,
() => {
if (props.native)
return
update()
},
)
onMounted(() => {
if (props.native)
return
@ -94,10 +108,8 @@ onBeforeUnmount(() => {
<template>
<div class="scrollbar">
<div
ref="wrap"
class="scrollbar__wrap" :class="[wrapClass, native ? '' : 'scrollbar__wrap--hidden-default']"
:style="style as any"
@scroll="handleScroll"
ref="wrap" class="scrollbar__wrap" :class="[wrapClass, native ? '' : 'scrollbar__wrap--hidden-default']"
:style="style as any" @scroll="handleScroll"
>
<component :is="tag" ref="resize" class="scrollbar__view" :class="[viewClass]" :style="viewStyle">
<slot />
@ -160,7 +172,7 @@ onBeforeUnmount(() => {
top: 2px;
width: 6px;
& > div {
&>div {
width: 100%;
}
}
@ -169,16 +181,16 @@ onBeforeUnmount(() => {
left: 2px;
height: 6px;
& > div {
&>div {
height: 100%;
}
}
}
}
.scrollbar:active > .scrollbar__bar,
.scrollbar:focus > .scrollbar__bar,
.scrollbar:hover > .scrollbar__bar {
.scrollbar:active>.scrollbar__bar,
.scrollbar:focus>.scrollbar__bar,
.scrollbar:hover>.scrollbar__bar {
opacity: 1;
transition: opacity 340ms ease-out;
}