From a0623e8bd9a121a38959e005f5569c3d4e250e96 Mon Sep 17 00:00:00 2001 From: xingyy <64720302+Concur-max@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:29:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(liveRoom):=20=E5=AE=9E=E7=8E=B0=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E4=BB=B7=E6=A0=BC=E5=8A=A8=E7=94=BB=E6=95=88?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 gsap 和 countup.js 库 - 实现价格滚动动画效果 - 优化价格显示逻辑 --- app/pages/liveRoom/index.client.vue | 49 ++++++++++++++++++++++------- package.json | 2 ++ pnpm-lock.yaml | 16 ++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/app/pages/liveRoom/index.client.vue b/app/pages/liveRoom/index.client.vue index 743ffcd..b1b8288 100644 --- a/app/pages/liveRoom/index.client.vue +++ b/app/pages/liveRoom/index.client.vue @@ -12,12 +12,15 @@ import {message} from "~/components/x-message/useMessage.js" import {showConfirmDialog} from 'vant'; 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) const player = ref(null) const {quoteStatus, show, playerId, show1, auctionData, getSocketData, getLiveLink, fullLive} = liveStore() const pullLink = ref('') - definePageMeta({ i18n: 'login.title', }) @@ -67,16 +70,45 @@ const initializePlayer = async () => { onMounted(async () => { pullLink.value = await getLiveLink() initializePlayer() + + }) onBeforeUnmount(() => { player.value?.dispose() player.value = null }) -watch(() => fullLive.value, (newVal) => { - if (newVal) { - getSocketData() +const createCountUp = (element, value, options = {}) => { + const defaultOptions = { + duration: 1.5, + separator: ',', + decimal: '.', + decimalPlaces: 0, + enableScrollSpy: true, } + + const countUp = new CountUp(element, Number(value), { ...defaultOptions, ...options }) + + if (!countUp.error) { + countUp.start() + } else { + console.error(countUp.error) + } + + return countUp +} + +watch(() => fullLive.value, async (newVal) => { + if (!newVal) return + + await getSocketData() + + nextTick(() => { + const { nowAuctionPrice } = auctionData.value + + createCountUp(countUpRef.value, nowAuctionPrice.nowPrice) + createCountUp(nextPriceRef.value, nowAuctionPrice.nextPrice) + }) }) const goBuy = async () => { @@ -91,9 +123,6 @@ const goBuy = async () => { const tipOpen = () => { message.warning(useI18n().t('live_room.warn_mess')) -} -const updateShow = () => { - } @@ -107,13 +136,11 @@ const updateShow = () => { style="bottom:calc(var(--safe-area-inset-bottom) + 26px)">