feat:home页面监听滚轮高度实现右下角客服展示等功能

This commit is contained in:
小张 2025-08-30 02:28:29 +08:00
parent 8000bde1b9
commit 2aab0f7152

View File

@ -501,13 +501,13 @@
<RegisterModal v-model:show="registerModalVisible" @success="handleAuthSuccess" />
<!-- 固定按钮组 -->
<div class="fixed-buttons-group">
<div class="fixed-button customer-btn" title="客服">
<div class="fixed-buttons-group" :class="{ 'show': showFixedButtons }">
<!-- <div class="fixed-button customer-btn" title="客服">
<img src="/images/icon/customer.jpg" alt="客服" />
</div>
<div class="fixed-button phone-btn" title="电话">
<img src="/images/icon/phone.jpg" alt="电话" />
</div>
</div> -->
<div class="fixed-button issue-btn" title="问题" @click="showIssueModal">
<img src="/images/icon/issue.jpg" alt="问题" />
</div>
@ -520,7 +520,7 @@
</template>
<script setup lang="ts">
import { computed, ref, onMounted } from 'vue'
import { computed, ref, onMounted, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { useCourseStore } from '@/stores/course'
@ -622,9 +622,64 @@ const scrollToTop = () => {
})
}
//
const handleScroll = () => {
try {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
const windowHeight = window.innerHeight || document.documentElement.clientHeight
const documentHeight = Math.max(
document.body.scrollHeight || 0,
document.body.offsetHeight || 0,
document.documentElement.clientHeight || 0,
document.documentElement.scrollHeight || 0,
document.documentElement.offsetHeight || 0
)
console.log('🔍 滚动事件触发:', {
scrollTop,
windowHeight,
documentHeight,
timestamp: new Date().toLocaleTimeString()
})
//
if (documentHeight <= windowHeight) {
showFixedButtons.value = true
console.log('✅ 页面高度不足,直接显示按钮')
return
}
//
const scrollableHeight = documentHeight - windowHeight
const scrollPercentage = (scrollTop / scrollableHeight) * 100
console.log('📊 滚动计算结果:', {
scrollTop,
windowHeight,
documentHeight,
scrollableHeight,
scrollPercentage: scrollPercentage.toFixed(2) + '%',
shouldShow: scrollPercentage >= 80,
currentShow: showFixedButtons.value
})
// 80%
const shouldShow = scrollPercentage >= 80
if (shouldShow !== showFixedButtons.value) {
showFixedButtons.value = shouldShow
console.log(shouldShow ? '🟢 显示固定按钮组' : '🔴 隐藏固定按钮组')
}
} catch (error) {
console.error('❌ 滚动处理函数出错:', error)
}
}
// 广
const showAdvertisement = ref(true)
//
const showFixedButtons = ref(false)
// 广
const closeAdvertisement = () => {
showAdvertisement.value = false
@ -808,8 +863,47 @@ const aiCards = computed(() => [
//
//
let scrollHandler: (() => void) | null = null
onMounted(async () => {
await courseStore.fetchCourses()
//
scrollHandler = () => {
console.log('🎯 滚动事件被触发 - 时间:', new Date().toLocaleTimeString())
handleScroll()
}
// - 使
window.addEventListener('scroll', scrollHandler, { passive: true })
document.addEventListener('scroll', scrollHandler, { passive: true })
document.body.addEventListener('scroll', scrollHandler, { passive: true })
console.log('✅ 滚动事件监听器已绑定')
//
setTimeout(() => {
console.log('🔄 执行初始滚动检查')
handleScroll()
}, 1000)
//
setTimeout(() => {
console.log('🧪 测试滚动监听 - 手动触发一次')
window.dispatchEvent(new Event('scroll'))
}, 2000)
})
onUnmounted(() => {
//
if (scrollHandler) {
window.removeEventListener('scroll', scrollHandler)
document.removeEventListener('scroll', scrollHandler)
document.body.removeEventListener('scroll', scrollHandler)
scrollHandler = null
console.log('🗑️ 滚动事件监听器已移除')
}
})
</script>
@ -867,8 +961,18 @@ onMounted(async () => {
display: flex;
flex-direction: column;
gap: 15px;
z-index: 1000;
opacity: 0;
visibility: hidden;
transform: translateY(20px);
transition: all 0.3s ease;
}
/* 显示状态 */
.fixed-buttons-group.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.fixed-button {