feat(liveRoom): 实现直播间价格动画效果

- 引入 gsap 和 countup.js 库
- 实现价格滚动动画效果
- 优化价格显示逻辑
This commit is contained in:
xingyy 2025-02-17 14:50:28 +08:00
parent a0623e8bd9
commit 3893938ac1

View File

@ -14,6 +14,7 @@ import {artworkBuy} from "@/api/goods/index.js"
import {useI18n} from 'vue-i18n'
import gsap from 'gsap'
import {CountUp} from 'countup.js'
const countUpRef = ref(null)
const nextPriceRef = ref(null)
@ -79,6 +80,8 @@ onBeforeUnmount(() => {
player.value = null
})
const createCountUp = (element, value, options = {}) => {
console.log('element', element)
console.log('value', value)
const defaultOptions = {
duration: 1.5,
separator: ',',
@ -86,7 +89,6 @@ const createCountUp = (element, value, options = {}) => {
decimalPlaces: 0,
enableScrollSpy: true,
}
const countUp = new CountUp(element, Number(value), {...defaultOptions, ...options})
if (!countUp.error) {
@ -103,14 +105,13 @@ watch(() => fullLive.value, async (newVal) => {
await getSocketData()
nextTick(() => {
const { nowAuctionPrice } = auctionData.value
createCountUp(countUpRef.value, nowAuctionPrice.nowPrice)
createCountUp(nextPriceRef.value, nowAuctionPrice.nextPrice)
})
watchEffect(() => {
createCountUp(countUpRef.value, auctionData.value?.nowAuctionPrice?.nowPrice)
})
watchEffect(() => {
createCountUp(nextPriceRef.value, auctionData.value?.nowAuctionPrice?.nextPrice)
})
const goBuy = async () => {
const res = await artworkBuy({
auctionArtworkUuid: auctionData.value?.artwork?.uuid,
@ -134,13 +135,13 @@ const tipOpen = () => {
<sideButton class="absolute top-196px right-0 z-999"></sideButton>
<div class="absolute left-1/2 transform -translate-x-1/2 flex flex-col items-center"
style="bottom:calc(var(--safe-area-inset-bottom) + 26px)">
<div class="text-16px text-#FFB25F font-600">
{{ $t('live_room.now_price') }}{{ auctionData?.nowAuctionPrice?.currency }}
<span ref="countUpRef" ></span>
<div class="text-16px text-#FFB25F font-600 flex">
<div class="mr-5px">{{ $t('live_room.now_price') }}{{ auctionData?.nowAuctionPrice?.currency }}</div>
<div ref="countUpRef" class="min-w-50px"></div>
</div>
<div class="text-16px text-#fff font-600">
{{ $t('live_room.lower_price') }}{{ auctionData?.nowAuctionPrice?.currency }}
<span ref="nextPriceRef" ></span>
<div class="text-16px text-#fff font-600 flex">
<div class="mr-5px">{{ $t('live_room.lower_price') }}{{ auctionData?.nowAuctionPrice?.currency }}</div>
<div ref="nextPriceRef" class="min-w-50px"></div>
</div>
<div v-if="quoteStatus" class="mt-10px mb-10px">
<van-button @click="goBuy" color="#FFB25F" class="w-344px !h-[40px]">
@ -189,12 +190,13 @@ const tipOpen = () => {
/* 定义过渡动画 */
.fade-enter-active {
transition: opacity 1s ease;
transition: opacity 1.5s ease;
}
.fade-leave-active {
transition: opacity 0.2s ease;
}
/* 定义进入和离开的状态 */
.fade-enter-from,
.fade-leave-to {