fix: ScrollContainer的一个问题
parent
88c1f5c2c4
commit
57314ee1d0
|
@ -6,6 +6,10 @@ import { useScrollTo } from '@/hooks/event/useScrollTo'
|
||||||
|
|
||||||
defineOptions({ name: 'ScrollContainer' })
|
defineOptions({ name: 'ScrollContainer' })
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
scrollHeight: { type: Number },
|
||||||
|
})
|
||||||
|
|
||||||
const scrollbarRef = ref<Nullable<ScrollbarType>>(null)
|
const scrollbarRef = ref<Nullable<ScrollbarType>>(null)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +76,12 @@ defineExpose({ scrollbarRef, scrollTo, scrollBottom, getScrollWrap })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Scrollbar ref="scrollbarRef" class="scroll-container" v-bind="$attrs">
|
<Scrollbar
|
||||||
|
ref="scrollbarRef"
|
||||||
|
class="scroll-container"
|
||||||
|
:scroll-height="scrollHeight"
|
||||||
|
v-bind="$attrs"
|
||||||
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</Scrollbar>
|
</Scrollbar>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -26,7 +26,7 @@ const spinRef = ref<ElRef>(null)
|
||||||
const realHeightRef = ref(0)
|
const realHeightRef = ref(0)
|
||||||
const minRealHeightRef = ref(0)
|
const minRealHeightRef = ref(0)
|
||||||
|
|
||||||
let realHeight = 0
|
const realHeight = ref(0);
|
||||||
|
|
||||||
const stopElResizeFn: Fn = () => {}
|
const stopElResizeFn: Fn = () => {}
|
||||||
|
|
||||||
|
@ -122,13 +122,13 @@ async function setModalHeight() {
|
||||||
return
|
return
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// if (!realHeight) {
|
// if (!realHeight) {
|
||||||
realHeight = spinEl.scrollHeight
|
realHeight.value = spinEl.scrollHeight
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (props.fullScreen)
|
if (props.fullScreen)
|
||||||
realHeightRef.value = window.innerHeight - props.modalFooterHeight - props.modalHeaderHeight - 28
|
realHeightRef.value = window.innerHeight - props.modalFooterHeight - props.modalHeaderHeight - 28
|
||||||
else
|
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))
|
emit('heightChange', unref(realHeightRef))
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ defineExpose({ scrollTop })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ScrollContainer ref="wrapperRef">
|
<ScrollContainer ref="wrapperRef" :scrollHeight="realHeight">
|
||||||
<div ref="spinRef" v-loading="loading" :style="spinStyle" :loading-tip="loadingTip">
|
<div ref="spinRef" v-loading="loading" :style="spinStyle" :loading-tip="loadingTip">
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts" setup>
|
<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 { toObject } from './util'
|
||||||
import Bar from './bar'
|
import Bar from './bar'
|
||||||
import { addResizeListener, removeResizeListener } from '@/utils/event'
|
import { addResizeListener, removeResizeListener } from '@/utils/event'
|
||||||
|
@ -33,6 +33,11 @@ const props = defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: 'div',
|
default: 'div',
|
||||||
},
|
},
|
||||||
|
scrollHeight: {
|
||||||
|
// 用于监控内部scrollHeight的变化
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const sizeWidth = ref('0')
|
const sizeWidth = ref('0')
|
||||||
|
@ -69,6 +74,15 @@ function update() {
|
||||||
sizeWidth.value = widthPercentage < 100 ? `${widthPercentage}%` : ''
|
sizeWidth.value = widthPercentage < 100 ? `${widthPercentage}%` : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.scrollHeight,
|
||||||
|
() => {
|
||||||
|
if (props.native)
|
||||||
|
return
|
||||||
|
update()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.native)
|
if (props.native)
|
||||||
return
|
return
|
||||||
|
@ -94,10 +108,8 @@ onBeforeUnmount(() => {
|
||||||
<template>
|
<template>
|
||||||
<div class="scrollbar">
|
<div class="scrollbar">
|
||||||
<div
|
<div
|
||||||
ref="wrap"
|
ref="wrap" class="scrollbar__wrap" :class="[wrapClass, native ? '' : 'scrollbar__wrap--hidden-default']"
|
||||||
class="scrollbar__wrap" :class="[wrapClass, native ? '' : 'scrollbar__wrap--hidden-default']"
|
:style="style as any" @scroll="handleScroll"
|
||||||
:style="style as any"
|
|
||||||
@scroll="handleScroll"
|
|
||||||
>
|
>
|
||||||
<component :is="tag" ref="resize" class="scrollbar__view" :class="[viewClass]" :style="viewStyle">
|
<component :is="tag" ref="resize" class="scrollbar__view" :class="[viewClass]" :style="viewStyle">
|
||||||
<slot />
|
<slot />
|
||||||
|
@ -160,7 +172,7 @@ onBeforeUnmount(() => {
|
||||||
top: 2px;
|
top: 2px;
|
||||||
width: 6px;
|
width: 6px;
|
||||||
|
|
||||||
& > div {
|
&>div {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,16 +181,16 @@ onBeforeUnmount(() => {
|
||||||
left: 2px;
|
left: 2px;
|
||||||
height: 6px;
|
height: 6px;
|
||||||
|
|
||||||
& > div {
|
&>div {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.scrollbar:active > .scrollbar__bar,
|
.scrollbar:active>.scrollbar__bar,
|
||||||
.scrollbar:focus > .scrollbar__bar,
|
.scrollbar:focus>.scrollbar__bar,
|
||||||
.scrollbar:hover > .scrollbar__bar {
|
.scrollbar:hover>.scrollbar__bar {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transition: opacity 340ms ease-out;
|
transition: opacity 340ms ease-out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue