mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
perf: 优化页面切换时缩略图的表现
This commit is contained in:
parent
99c53c385d
commit
a71c9ffbd3
@ -225,4 +225,19 @@ export const getLineElementPath = (element: PPTLineElement) => {
|
|||||||
return `M${start} C${p1} ${p2} ${end}`
|
return `M${start} C${p1} ${p2} ${end}`
|
||||||
}
|
}
|
||||||
return `M${start} L${end}`
|
return `M${start} L${end}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断一个元素是否在可视范围内
|
||||||
|
* @param element 元素
|
||||||
|
* @param parent 父元素
|
||||||
|
*/
|
||||||
|
export const isElementInViewport = (element: HTMLElement, parent: HTMLElement): boolean => {
|
||||||
|
const elementRect = element.getBoundingClientRect()
|
||||||
|
const parentRect = parent.getBoundingClientRect()
|
||||||
|
|
||||||
|
return (
|
||||||
|
elementRect.top >= parentRect.top &&
|
||||||
|
elementRect.bottom <= parentRect.bottom
|
||||||
|
)
|
||||||
}
|
}
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
<Draggable
|
<Draggable
|
||||||
class="thumbnail-list"
|
class="thumbnail-list"
|
||||||
|
ref="thumbnailsRef"
|
||||||
:modelValue="slides"
|
:modelValue="slides"
|
||||||
:animation="200"
|
:animation="200"
|
||||||
:scroll="true"
|
:scroll="true"
|
||||||
@ -46,10 +47,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from 'vue'
|
import { computed, nextTick, ref, watch } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useMainStore, useSlidesStore, useKeyboardStore } from '@/store'
|
import { useMainStore, useSlidesStore, useKeyboardStore } from '@/store'
|
||||||
import { fillDigit } from '@/utils/common'
|
import { fillDigit } from '@/utils/common'
|
||||||
|
import { isElementInViewport } from '@/utils/element'
|
||||||
import type { ContextmenuItem } from '@/components/Contextmenu/types'
|
import type { ContextmenuItem } from '@/components/Contextmenu/types'
|
||||||
import useSlideHandler from '@/hooks/useSlideHandler'
|
import useSlideHandler from '@/hooks/useSlideHandler'
|
||||||
import useScreening from '@/hooks/useScreening'
|
import useScreening from '@/hooks/useScreening'
|
||||||
@ -85,6 +87,26 @@ const {
|
|||||||
sortSlides,
|
sortSlides,
|
||||||
} = useSlideHandler()
|
} = useSlideHandler()
|
||||||
|
|
||||||
|
// 页面被切换时
|
||||||
|
const thumbnailsRef = ref<InstanceType<typeof Draggable>>()
|
||||||
|
watch(() => slideIndex.value, () => {
|
||||||
|
|
||||||
|
// 清除多选状态的幻灯片
|
||||||
|
if (selectedSlidesIndex.value.length) {
|
||||||
|
mainStore.updateSelectedSlidesIndex([])
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查当前页缩略图是否在可视范围,不在的话需要滚动到对应的位置
|
||||||
|
nextTick(() => {
|
||||||
|
const activeThumbnailRef: HTMLElement = thumbnailsRef.value?.$el?.querySelector('.thumbnail-item.active')
|
||||||
|
if (thumbnailsRef.value && activeThumbnailRef && !isElementInViewport(activeThumbnailRef, thumbnailsRef.value.$el)) {
|
||||||
|
setTimeout(() => {
|
||||||
|
activeThumbnailRef.scrollIntoView({ behavior: 'smooth' })
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// 切换页面
|
// 切换页面
|
||||||
const changeSlideIndex = (index: number) => {
|
const changeSlideIndex = (index: number) => {
|
||||||
mainStore.setActiveElementIdList([])
|
mainStore.setActiveElementIdList([])
|
||||||
@ -100,6 +122,7 @@ const handleClickSlideThumbnail = (e: MouseEvent, index: number) => {
|
|||||||
if (isMultiSelected && selectedSlidesIndex.value.includes(index) && e.button !== 0) return
|
if (isMultiSelected && selectedSlidesIndex.value.includes(index) && e.button !== 0) return
|
||||||
|
|
||||||
// 按住Ctrl键,点选幻灯片,再次点击已选中的页面则取消选中
|
// 按住Ctrl键,点选幻灯片,再次点击已选中的页面则取消选中
|
||||||
|
// 如果被取消选中的页面刚好是当前激活页面,则需要从其他被选中的页面中选择第一个作为当前激活页面
|
||||||
if (ctrlKeyState.value) {
|
if (ctrlKeyState.value) {
|
||||||
if (slideIndex.value === index) {
|
if (slideIndex.value === index) {
|
||||||
if (!isMultiSelected) return
|
if (!isMultiSelected) return
|
||||||
@ -116,7 +139,6 @@ const handleClickSlideThumbnail = (e: MouseEvent, index: number) => {
|
|||||||
else {
|
else {
|
||||||
const newSelectedSlidesIndex = [...selectedSlidesIndex.value, index]
|
const newSelectedSlidesIndex = [...selectedSlidesIndex.value, index]
|
||||||
mainStore.updateSelectedSlidesIndex(newSelectedSlidesIndex)
|
mainStore.updateSelectedSlidesIndex(newSelectedSlidesIndex)
|
||||||
changeSlideIndex(index)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +157,6 @@ const handleClickSlideThumbnail = (e: MouseEvent, index: number) => {
|
|||||||
const newSelectedSlidesIndex = []
|
const newSelectedSlidesIndex = []
|
||||||
for (let i = minIndex; i <= maxIndex; i++) newSelectedSlidesIndex.push(i)
|
for (let i = minIndex; i <= maxIndex; i++) newSelectedSlidesIndex.push(i)
|
||||||
mainStore.updateSelectedSlidesIndex(newSelectedSlidesIndex)
|
mainStore.updateSelectedSlidesIndex(newSelectedSlidesIndex)
|
||||||
changeSlideIndex(index)
|
|
||||||
}
|
}
|
||||||
// 正常切换页面
|
// 正常切换页面
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user