✨ feat(core): 实现详情面板动画逻辑并完善相关测试

* 新增 detailMotion 工具类以支持更精细的动画控制
* 优化 FileManageView 面板渲染逻辑,改用 v-show 提升交互性能
* 调整 Transition 组件为手动控制模式以适配自定义动画
* 在 package.json 中配置自动化测试脚本
* 补充 detailMotion 相关的单元测试与测试说明文档
This commit is contained in:
orion committed 2026-09-15 11:25:43 +08:00
1 parent 9bac0c0040
commit af009cf3c5
6 files changed
+307 -138

No files matched your search

+96 -138
View File
@@ -71,8 +71,8 @@
</div>
</div>
<Transition name="fcb-expand-120" @before-enter="beforeExpandPanelEnter" @enter="enterExpandPanel" @after-enter="afterExpandPanelEnter" @before-leave="beforeExpandPanelLeave" @leave="leaveExpandPanel">
<div id="file-filter-panel" v-if="filterBodyVisible" class="fcb-expand-content mt-4 grid gap-4">
<Transition :css="false" @before-enter="beforeExpandPanelEnter" @enter="enterExpandPanel" @after-enter="afterExpandPanelEnter" @before-leave="beforeExpandPanelLeave" @leave="leaveExpandPanel">
<div id="file-filter-panel" v-show="filterBodyVisible" class="fcb-expand-content mt-4 grid gap-4">
<div class="flex flex-col gap-3 lg:flex-row lg:items-center">
<label class="min-w-0 flex-1">
<span class="sr-only">{{ t('fileManage.searchPlaceholder') }}</span>
@@ -1227,7 +1227,7 @@
<TransitionGroup
:css="false"
tag="div"
ref="lifecycleListRef" class="fcb-lifecycle-list"
class="fcb-lifecycle-list"
@before-enter="beforeLifecycleRowEnter"
@enter="enterLifecycleRow"
@leave="leaveLifecycleRow"
@@ -1246,7 +1246,7 @@
/>
</div>
<div
class="fcb-lifecycle-card theme-2026-card-hover mb-2.5 rounded-[16px] border px-3 py-2 shadow-sm transition-all duration-200 hover:shadow-md last:mb-0 sm:rounded-[20px]"
class="fcb-lifecycle-card theme-2026-card-hover rounded-[16px] border px-3 py-2 shadow-sm transition-all duration-200 hover:shadow-md sm:rounded-[20px]"
:class="[
isDarkMode ? 'border-gray-700 bg-gray-800/60' : 'border-gray-100 bg-gray-50'
]"
@@ -1276,14 +1276,15 @@
}}
</button>
<Transition
name="fcb-retrieval-panel"
:css="false"
@before-enter="beforeRetrievalPanelEnter"
@enter="enterRetrievalPanel"
@after-enter="afterRetrievalPanelEnter"
@before-leave="beforeRetrievalPanelLeave"
@leave="leaveRetrievalPanel"
>
<div v-if="isRetrievalHistoryExpanded" class="mt-2.5 space-y-1.5">
<div v-show="isRetrievalHistoryExpanded" class="fcb-retrieval-panel">
<div class="space-y-1.5 pt-2.5">
<div
v-for="(event, eventIndex) in retrievalTimelineEvents"
:key="`${event.key}-${eventIndex}-${event.displayMeta}`"
@@ -1296,6 +1297,7 @@
</div>
<p class="mt-1 leading-5" :class="mutedTextClass">{{ event.displayDescription }}</p>
</div>
</div>
</div>
</Transition>
</div>
@@ -1751,6 +1753,7 @@ import BaseModal from '@/components/common/BaseModal.vue'
import BaseButton from '@/components/common/BaseButton.vue'
import { useAdminFiles, useInjectedDarkMode, useTransferAnalytics } from '@/composables'
import { formatFileSize, formatTimestamp } from '@/utils/common'
import { createDetailMotion } from '@/utils/detailMotion'
const { t } = useI18n()
const isDarkMode = useInjectedDarkMode()
@@ -1859,9 +1862,8 @@ const syncMobileViewport = (event: MediaQueryListEvent) => {
isMobileViewport.value = event.matches
}
const isLifecycleExpanded = ref(false)
const lifecycleListRef = ref<HTMLElement | null>(null)
const lifecycleViewportRef = ref<HTMLElement | null>(null)
let lifecycleHeightAnimation: Animation | null = null
let lifecycleHeightRevision = 0
const isRetrievalHistoryExpanded = ref(false)
const retrievalTimelineEvents = computed(() =>
(selectedFileDetail.value?.detailTimeline || []).filter((item) => item.key === 'retrieved_event')
@@ -1875,55 +1877,37 @@ const visibleDetailTimeline = computed(() =>
isLifecycleExpanded.value ? detailTimelineRows.value : detailTimelineRows.value.slice(0, 3)
)
const animateLifecycleHeight = async () => {
await nextTick()
const viewport = lifecycleViewportRef.value
if (!viewport || reducedMotionQuery.matches) return
lifecycleHeightAnimation?.cancel()
lifecycleHeightAnimation = null
viewport.style.height = ''
await nextTick()
const currentHeight = viewport.getBoundingClientRect().height
viewport.style.height = `${currentHeight}px`
await nextTick()
const targetHeight = viewport.scrollHeight
lifecycleHeightAnimation = viewport.animate(
[{ height: `${currentHeight}px` }, { height: `${targetHeight}px` }],
{ duration: 420, easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'forwards' }
)
const cleanup = () => {
viewport.style.height = ''
lifecycleHeightAnimation = null
}
lifecycleHeightAnimation.addEventListener('finish', cleanup, { once: true })
lifecycleHeightAnimation.addEventListener('cancel', cleanup, { once: true })
}
const LIFECYCLE_ENTER_MS = 160
const LIFECYCLE_LEAVE_MS = 120
const lifecycleEasing = 'cubic-bezier(0.22, 1, 0.36, 1)'
const lifecycleExitEasing = 'cubic-bezier(0.4, 0, 1, 1)'
watch(isLifecycleExpanded, animateLifecycleHeight)
const reducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)')
const detailMotion = createDetailMotion(() => reducedMotionQuery.matches)
const playDetailAnimation = detailMotion.play
const PANEL_DURATION_MS = 420
const lifecycleEasing = 'cubic-bezier(0.32, 0.72, 0, 1)'
const LIFECYCLE_ENTER_MS = 180
const LIFECYCLE_LEAVE_MS = 120
const playDetailAnimation = (
element: HTMLElement,
keyframes: Keyframe[],
options: KeyframeAnimationOptions,
done: () => void
) => {
if (reducedMotionQuery.matches) {
done()
return
}
element.getAnimations().forEach((animation) => animation.cancel())
const animation = element.animate(keyframes, { fill: 'both', ...options })
const finish = () => done()
animation.addEventListener('finish', finish, { once: true })
animation.addEventListener('cancel', finish, { once: true })
}
// This watcher runs before Vue patches the rows: capture the visible starting
// height now, then measure the natural list height after leaving rows exit flow.
watch(isLifecycleExpanded, async () => {
const revision = ++lifecycleHeightRevision
const viewport = lifecycleViewportRef.value
if (!viewport) return
const from = viewport.getBoundingClientRect().height
detailMotion.cancel(viewport)
viewport.style.height = `${from}px`
viewport.style.overflow = 'hidden'
await nextTick()
if (revision !== lifecycleHeightRevision || !viewport.isConnected) return
const to = viewport.firstElementChild?.getBoundingClientRect().height ?? 0
playDetailAnimation(
viewport,
[{ height: `${from}px` }, { height: `${to}px` }],
{ duration: PANEL_DURATION_MS, easing: lifecycleEasing },
() => {
viewport.style.height = ''
viewport.style.overflow = ''
}
)
})
const beforeLifecycleRowEnter = (element: Element) => {
const row = element as HTMLElement
@@ -1946,6 +1930,11 @@ const enterLifecycleRow = (element: Element, done: () => void) => {
}
const leaveLifecycleRow = (element: Element, done: () => void) => {
const row = element as HTMLElement
const width = row.getBoundingClientRect().width
const top = row.offsetTop
row.style.position = 'absolute'
row.style.top = `${top}px`
row.style.width = `${width}px`
row.style.willChange = 'opacity'
playDetailAnimation(
row,
@@ -1953,86 +1942,66 @@ const leaveLifecycleRow = (element: Element, done: () => void) => {
{ opacity: 1 },
{ opacity: 0 }
],
{ duration: LIFECYCLE_LEAVE_MS, easing: lifecycleExitEasing },
{ duration: LIFECYCLE_LEAVE_MS, easing: lifecycleEasing },
() => {
row.style.willChange = ''
done()
}
)
}
const beforeExpandPanelEnter = (element: Element) => {
const panel = element as HTMLElement
panel.style.height = '0px'
panel.style.overflow = 'hidden'
}
const enterExpandPanel = (element: Element, done: () => void) => {
const panel = element as HTMLElement
const targetHeight = panel.scrollHeight
playDetailAnimation(panel, [{ height: '0px', opacity: 0 }, { height: `${targetHeight}px`, opacity: 1 }], { duration: 420, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' }, done)
}
const afterExpandPanelEnter = (element: Element) => {
const panel = element as HTMLElement
panel.style.height = ''
panel.style.overflow = ''
}
const beforeExpandPanelLeave = (element: Element) => {
const panel = element as HTMLElement
panel.style.height = `${panel.scrollHeight}px`
panel.style.overflow = 'hidden'
}
const leaveExpandPanel = (element: Element, done: () => void) => {
const panel = element as HTMLElement
const currentHeight = panel.scrollHeight
playDetailAnimation(panel, [{ height: `${currentHeight}px`, opacity: 1 }, { height: '0px', opacity: 0 }], { duration: 320, easing: 'cubic-bezier(0.4, 0, 0.8, 0.2)' }, done)
}
const beforeRetrievalPanelEnter = (element: Element) => {
const panel = element as HTMLElement
panel.style.height = '0px'
panel.style.overflow = 'clip'
panel.style.willChange = 'height, opacity, transform'
}
const enterRetrievalPanel = (element: Element, done: () => void) => {
const panel = element as HTMLElement
const height = panel.scrollHeight
playDetailAnimation(
panel,
[
{ height: '0px', opacity: 0, transform: 'translate3d(0, -4px, 0)' },
{ height: `${height}px`, opacity: 1, transform: 'translate3d(0, 0, 0)' }
],
{ duration: LIFECYCLE_ENTER_MS, easing: lifecycleEasing },
done
)
}
const afterRetrievalPanelEnter = (element: Element) => {
const clearPanelStyles = (element: Element) => {
const panel = element as HTMLElement
panel.style.height = ''
panel.style.overflow = ''
panel.style.willChange = ''
}
const beforeRetrievalPanelLeave = (element: Element) => {
const beforeExpandPanelEnter = (element: Element) => {
const panel = element as HTMLElement
panel.style.height = `${panel.scrollHeight}px`
panel.style.overflow = 'clip'
panel.style.willChange = 'height, opacity, transform'
// v-show briefly sets display:none while reversing leave; computed height
// still includes the running effect, whereas the bounding box is then zero.
const from = panel.style.height ? Number.parseFloat(getComputedStyle(panel).height) : 0
detailMotion.cancel(panel)
panel.style.height = `${from}px`
panel.style.overflow = 'hidden'
panel.style.willChange = 'height, opacity'
}
const leaveRetrievalPanel = (element: Element, done: () => void) => {
const enterExpandPanel = (element: Element, done: () => void) => {
const panel = element as HTMLElement
const height = panel.scrollHeight
playDetailAnimation(
panel,
[
{ height: `${height}px`, opacity: 1, transform: 'translate3d(0, 0, 0)' },
{ height: '0px', opacity: 0, transform: 'translate3d(0, -4px, 0)' }
],
{ duration: LIFECYCLE_LEAVE_MS, easing: lifecycleExitEasing },
() => {
panel.style.willChange = ''
done()
}
// Remove the frozen height while measuring: scrollHeight cannot measure a
// smaller destination when the element still has a larger explicit height.
const from = panel.getBoundingClientRect().height
panel.style.height = ''
const to = panel.getBoundingClientRect().height
panel.style.height = `${from}px`
playDetailAnimation(panel,
[{ height: `${from}px`, opacity: from > 0 ? 1 : 0 }, { height: `${to}px`, opacity: 1 }],
{ duration: PANEL_DURATION_MS, easing: lifecycleEasing },
() => { clearPanelStyles(panel); done() }
)
}
const afterExpandPanelEnter = clearPanelStyles
const beforeExpandPanelLeave = (element: Element) => {
const panel = element as HTMLElement
const from = panel.getBoundingClientRect().height
detailMotion.cancel(panel)
panel.style.height = `${from}px`
panel.style.overflow = 'hidden'
panel.style.willChange = 'height, opacity'
}
const leaveExpandPanel = (element: Element, done: () => void) => {
const panel = element as HTMLElement
const from = panel.getBoundingClientRect().height
playDetailAnimation(panel,
[{ height: `${from}px`, opacity: 1 }, { height: '0px', opacity: 0 }],
{ duration: PANEL_DURATION_MS, easing: lifecycleEasing },
() => { clearPanelStyles(panel); done() }
)
}
const beforeRetrievalPanelEnter = beforeExpandPanelEnter
const enterRetrievalPanel = enterExpandPanel
const afterRetrievalPanelEnter = afterExpandPanelEnter
const beforeRetrievalPanelLeave = beforeExpandPanelLeave
const leaveRetrievalPanel = leaveExpandPanel
watch(
() => selectedFileDetail.value?.id,
() => {
@@ -2554,17 +2523,22 @@ onMounted(() => {
})
onUnmounted(() => {
lifecycleHeightRevision++
detailMotion.dispose()
mobileMediaQuery.removeEventListener('change', syncMobileViewport)
})
</script>
<style scoped>
.fcb-lifecycle-viewport {
overflow: hidden;
will-change: height;
overflow: visible;
}
.fcb-lifecycle-list {
.fcb-lifecycle-viewport > .fcb-lifecycle-list {
position: relative;
display: flex;
flex-direction: column;
gap: 10px;
overflow: visible;
}
@@ -2587,20 +2561,4 @@ onUnmounted(() => {
will-change: grid-template-rows, opacity, transform;
}
.fcb-expand-120-enter-active,
.fcb-expand-120-leave-active {
overflow: hidden;
will-change: height, opacity;
}
.fcb-expand-120-enter-from,
.fcb-expand-120-leave-to { opacity: 0; }
.fcb-expand-120-enter-to,
.fcb-expand-120-leave-from { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
.fcb-expand-120-enter-active,
.fcb-expand-120-leave-active {
transition-duration: 1ms;
}
}
</style>