feat: 优化collapse组件

This commit is contained in:
539943419 committed 2025-01-19 12:33:41 +08:00
1 parent f6c17ed816
commit d8a283dd89
1 file changed
+33 -7
+33 -7
View File
@@ -15,9 +15,7 @@ const props = defineProps({
}) })
const cwRef = ref<HTMLDivElement>() const cwRef = ref<HTMLDivElement>()
const cRef = ref<HTMLDivElement>() const cRef = ref<HTMLDivElement>()
const cwStyle = ref<{ [key: string]: string | number }>({ const cwStyle = ref<{ [key: string]: string | number }>({})
maxHeight: '99999vh',
})
const cStyle = ref<{ [key: string]: string | number }>({}) const cStyle = ref<{ [key: string]: string | number }>({})
let originHeight = -1 let originHeight = -1
@@ -33,6 +31,13 @@ const clearTimer = () => {
const handleHide = () => { const handleHide = () => {
clearTimer() clearTimer()
calcOriginHeight();
cwStyle.value = {
maxHeight: `${originHeight}px`,
opacity: 1,
transition: "all 0.2s ease-in-out, opacity 0.1s ease-out",
}
timer.push(setTimeout(() => {
cwStyle.value = { cwStyle.value = {
maxHeight: 0, maxHeight: 0,
opacity: 0, opacity: 0,
@@ -44,8 +49,10 @@ const handleHide = () => {
maxHeight: 0, maxHeight: 0,
display: 'none', display: 'none',
opacity: 0, opacity: 0,
pointerEvents: 'none',
} }
}, 300)) }, 300))
}))
} }
const handleShow = () => { const handleShow = () => {
@@ -53,6 +60,15 @@ const handleShow = () => {
cwStyle.value = { cwStyle.value = {
maxHeight: 0, maxHeight: 0,
opacity: 0, opacity: 0,
pointerEvents: 'none',
}
timer.push(setTimeout(() => {
calcOriginHeight();
cwStyle.value = {
maxHeight: 0,
opacity: 0,
transition: "all 0.2s ease-in-out, opacity 0.3s ease-in",
pointerEvents: 'none',
} }
timer.push(setTimeout(() => { timer.push(setTimeout(() => {
cwStyle.value = { cwStyle.value = {
@@ -60,6 +76,15 @@ const handleShow = () => {
opacity: 1, opacity: 1,
transition: "all 0.2s ease-in-out, opacity 0.3s ease-in" transition: "all 0.2s ease-in-out, opacity 0.3s ease-in"
} }
timer.push(setTimeout(() => {
cwStyle.value = {
opacity: 1,
}
nextTick(() => {
calcOriginHeight()
})
}, 300))
}))
})) }))
} }
@@ -73,11 +98,12 @@ watch(() => props.show, (newVal) => {
} }
}) })
onMounted(() => { const calcOriginHeight = () => {
originHeight = cwRef.value!.clientHeight originHeight = cRef.value!.clientHeight
cwStyle.value = {
maxHeight: `${originHeight}px`,
} }
onMounted(() => {
calcOriginHeight()
}) })
</script> </script>