From e3d0ffe1e6dcf48230936340ded0169b6f9db747 Mon Sep 17 00:00:00 2001 From: Wenzhe Date: Tue, 3 Feb 2026 23:44:05 +0800 Subject: [PATCH] v1.2.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、增加loading组件,用于预加载scroll-view的背景图片,然后使得scroll-view进行隐藏的滚动到首页 2、调整首页滚动逻辑,使得可以完全屏蔽滚动;同时修改向上滚动逻辑 --- components/LoadingComponent.vue | 216 +++++++++++++++++++++++ components/SinglePageContainer.vue | 269 ++++++++++++----------------- 2 files changed, 325 insertions(+), 160 deletions(-) create mode 100644 components/LoadingComponent.vue diff --git a/components/LoadingComponent.vue b/components/LoadingComponent.vue new file mode 100644 index 0000000..f2a9a47 --- /dev/null +++ b/components/LoadingComponent.vue @@ -0,0 +1,216 @@ + + + + + \ No newline at end of file diff --git a/components/SinglePageContainer.vue b/components/SinglePageContainer.vue index 5ff5b74..3964f6c 100644 --- a/components/SinglePageContainer.vue +++ b/components/SinglePageContainer.vue @@ -14,6 +14,7 @@ import EndPage from './EndPage.vue' import LotteryFormModal from './LotteryFormModal.vue' import AICoupletForm from './AICoupletForm.vue' import CoupletDisplay from './CoupletDisplay.vue' +import LoadingComponent from './LoadingComponent.vue' const sceneStore = useSceneStore() const collectionStore = useCollectionStore() @@ -52,6 +53,10 @@ const hasSubmittedUserInfo = ref(false) const hasScrolled = ref(false) // 标记是否正在自动滚动 const isAutoScrolling = ref(false) +// 是否显示加载组件 +const showLoading = ref(true) +// 是否已完成图片加载 +const isImagesLoaded = ref(false) // 推荐关键词 @@ -140,8 +145,95 @@ const collectedSeals = computed(() => { } }) -// 组件挂载后初始化 -onMounted(() => { +// 处理加载完成事件 +const handleLoadingComplete = () => { + isImagesLoaded.value = true + console.log('图片加载完成,准备初始化页面') + + // 确保 scrollContainer 已初始化并滚动到最下方 + ensureScrollContainerReady() +} + +// 确保 scrollContainer 已初始化并滚动到最下方 +const ensureScrollContainerReady = () => { + // 等待 DOM 渲染完成 + nextTick(() => { + const checkScrollContainer = () => { + if (!scrollContainer.value) { + console.log('scrollContainer 尚未初始化,延迟重试...') + setTimeout(checkScrollContainer, 100) + return + } + + const container = scrollContainer.value + console.log('scrollContainer 已初始化:', { + scrollHeight: container.scrollHeight, + clientHeight: container.clientHeight + }) + + // 如果 scrollHeight 为 0,说明内容还未渲染 + if (container.scrollHeight === 0) { + console.log('内容尚未渲染,延迟重试...') + setTimeout(checkScrollContainer, 100) + return + } + + // 标记正在自动滚动 + isAutoScrolling.value = true + + // 设置首页 section ID,使用 scroll-into-view 滚动到首页 + homeSectionId.value = 'home-section' + console.log('使用 scroll-into-view 滚动到首页') + + // 设置活动场景为首页 + activeSceneIndex.value = scenes.value.length - 1 + + // 等待 scroll-into-view 生效 + setTimeout(() => { + // 再次检查并滚动到最下方,确保滚动位置正确 + try { + const targetScrollTop = container.scrollHeight - container.clientHeight + if (typeof container.scrollTo === 'function') { + container.scrollTo({ + top: targetScrollTop, + duration: 0 + }) + } else { + container.scrollTop = targetScrollTop + } + console.log('已滚动到最下方,scrollTop:', container.scrollTop) + } catch (error) { + console.error('滚动失败:', error) + } + + // 自动滚动结束 + isAutoScrolling.value = false + // 强制将 hasScrolled 设置为 false,确保滑动提示能够显示 + hasScrolled.value = false + console.log('scrollContainer 准备就绪,hasScrolled:', hasScrolled.value) + }, 300) + } + + // 开始检查 scrollContainer + checkScrollContainer() + }) +} + +// 处理开始按钮点击事件 +const handleStart = () => { + // 隐藏加载组件 + showLoading.value = false + + // 确保滑动提示能够显示 + hasScrolled.value = false + console.log('点击开始按钮,hasScrolled:', hasScrolled.value) + + // 初始化页面 + initPage() +} + +// 初始化页面函数 +const initPage = () => { // 记录页面访问 recordPageVisit({ user_agent: navigator.userAgent, @@ -163,114 +255,15 @@ onMounted(() => { } }) - // 添加滚动事件监听 - 使用uniapp的scroll-view事件绑定 - // scroll-view 组件通过 @scroll 事件监听滚动,无需手动添加事件监听器 + // 标记页面准备就绪 + titleImageShown.value = true + isAutoScrolling.value = false + console.log('页面准备就绪') +} - - // 页面加载时滚动到最底部(首页) - const scrollToHomePage = () => { - // 标记正在自动滚动 - isAutoScrolling.value = true - - if (!scrollContainer.value) { - console.log('scrollContainer 尚未初始化') - return - } - - // 保存当前容器引用,避免异步回调中丢失 - const container = scrollContainer.value - - console.log('scrollContainer 已初始化:', { - element: container, - scrollHeight: container.scrollHeight, - clientHeight: container.clientHeight, - scrollTop: container.scrollTop, - classList: container.classList - }) - - // 如果scrollHeight为0,说明内容还未渲染 - if (container.scrollHeight === 0) { - console.log('内容尚未渲染,延迟重试...') - setTimeout(scrollToHomePage, 100) - return - } - - // 首页是最后一个场景,索引为 scenes.value.length - 1 - // 应该位于页面最底部 - const homeIndex = scenes.value.length - 1 - - // 方法1: 使用 scroll-into-view(uniapp 原生支持) - console.log('使用 scroll-into-view 滚动到首页') - homeSectionId.value = 'home-section' - - // 设置活动场景为首页 - activeSceneIndex.value = homeIndex - - // 设置活动场景为首页 - activeSceneIndex.value = homeIndex - - // 验证滚动是否成功,如果不成功,延迟后重试 - setTimeout(() => { - if (!container) { - console.log('scrollContainer 已卸载') - return - } - - console.log('验证滚动结果:', { - currentScrollTop: container.scrollTop, - scrollHeight: container.scrollHeight, - clientHeight: container.clientHeight, - isAtBottom: Math.abs(container.scrollTop - (container.scrollHeight - container.clientHeight)) < 50 - }) - - // 检查是否已经滚动到底部 - const isAtBottom = Math.abs(container.scrollTop - (container.scrollHeight - container.clientHeight)) < 50 - - if (!isAtBottom) { - console.log('滚动验证失败,使用备用方法重试...') - // 方法2: 使用 scrollTo 或 scrollTop - try { - const targetScrollTop = container.scrollHeight - container.clientHeight - if (typeof container.scrollTo === 'function') { - container.scrollTo({ - top: targetScrollTop, - duration: 0 - }) - } else { - container.scrollTop = targetScrollTop - } - } catch (error) { - console.log('备用方法失败:', error) - container.scrollTop = container.scrollHeight - container.clientHeight - } - - // 再次验证后显示容器 - setTimeout(() => { - // 标记页面准备就绪,隐藏加载提示并显示页面 - isPageReady.value = true - titleImageShown.value = true - // 自动滚动结束 - isAutoScrolling.value = false - console.log('设置 isPageReady = true,准备显示页面') - }, 50) - } else { - console.log('成功滚动到首页') - // 滚动成功后显示容器 - // 标记页面准备就绪,隐藏加载提示并显示页面 - isPageReady.value = true - titleImageShown.value = true - // 自动滚动结束 - isAutoScrolling.value = false - console.log('设置 isPageReady = true,准备显示页面') - } - }, 300) - } - - // 初始滚动到首页 - 延迟更长时间确保内容渲染 - setTimeout(scrollToHomePage, 800) - - // 额外的确保措施,等待更长时间后再次尝试 - setTimeout(scrollToHomePage, 1500) +// 组件挂载后初始化 +onMounted(() => { + console.log('SinglePageContainer 组件挂载') }) // 处理滚动事件(从下往上滑动) @@ -512,15 +505,15 @@ onUnmounted(() => {