新增首页骨架屏并优化页面体验
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
<template>
|
||||
<SkeletonBase>
|
||||
<view class="skeleton-banner"></view>
|
||||
|
||||
<view class="skeleton-entry">
|
||||
<view v-for="i in 4" :key="i" class="skeleton-entry-item">
|
||||
<view class="skeleton-icon"></view>
|
||||
<view class="skeleton-text"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="skeleton-section">
|
||||
<view class="skeleton-section-title"></view>
|
||||
<view v-for="i in 3" :key="i" class="skeleton-course-item">
|
||||
<view class="skeleton-course-img"></view>
|
||||
<view class="skeleton-course-info">
|
||||
<view class="skeleton-course-title"></view>
|
||||
<view class="skeleton-course-desc"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</SkeletonBase>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import SkeletonBase from './SkeletonBase.vue'
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.skeleton-banner {
|
||||
height: 300rpx;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
margin: 20rpx;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
|
||||
.skeleton-entry {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
padding: 30rpx 20rpx;
|
||||
}
|
||||
|
||||
.skeleton-entry-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.skeleton-icon {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
border-radius: 40rpx;
|
||||
}
|
||||
|
||||
.skeleton-text {
|
||||
width: 60rpx;
|
||||
height: 24rpx;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.skeleton-section {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.skeleton-section-title {
|
||||
height: 40rpx;
|
||||
width: 200rpx;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
border-radius: 8rpx;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.skeleton-course-item {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 24rpx;
|
||||
padding: 20rpx;
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
|
||||
.skeleton-course-img {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.skeleton-course-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.skeleton-course-title {
|
||||
height: 36rpx;
|
||||
width: 80%;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.skeleton-course-desc {
|
||||
height: 28rpx;
|
||||
width: 60%;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- components/TabBar.vue -->
|
||||
<template>
|
||||
<view class="tab-bar">
|
||||
<view v-if="shouldShowTabBar" class="tab-bar">
|
||||
<view
|
||||
v-for="(tab, index) in tabs"
|
||||
:key="tab.path"
|
||||
@@ -19,7 +19,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, watch, onMounted, onBeforeUnmount } from 'vue'
|
||||
import { ref, watch, onMounted, onBeforeUnmount } from 'vue'
|
||||
import {
|
||||
PAGE,
|
||||
TAB_ROUTES,
|
||||
@@ -37,6 +37,28 @@ const emit = defineEmits(['update:active', 'tab-change'])
|
||||
// 当前激活的索引 - 默认从路由获取
|
||||
const currentActiveIndex = ref(-1)
|
||||
|
||||
// 是否需要显示 TabBar
|
||||
const shouldShowTabBar = ref(true)
|
||||
|
||||
// 不需要显示 TabBar 的页面路径列表(注意:不要带开头的 /)
|
||||
const HIDE_TABBAR_PAGES = [
|
||||
'pages/memberInfo/courseList', // 预约课程
|
||||
'pages/memberInfo/courseDetail', // 课程详情
|
||||
'pages/memberInfo/booking', // 我的预约
|
||||
'pages/memberInfo/bodyTestReport', // 体测报告
|
||||
'pages/groupCourse/list', // 团课列表
|
||||
'pages/groupCourse/detail', // 团课详情
|
||||
'pages/searchCourse/searchCourse', // 搜索课程
|
||||
'pages/checkIn/checkIn', // 会员签到
|
||||
'pages/memberInfo/myCourses', // 我的课程
|
||||
'pages/memberInfo/coupons', // 我的优惠券
|
||||
'pages/memberInfo/points', // 我的积分
|
||||
'pages/memberInfo/pointsMall', // 积分商城
|
||||
'pages/memberInfo/referral', // 邀请好友
|
||||
'pages/memberInfo/userInfo', // 个人信息
|
||||
'pages/memberInfo/memberCard', // 我的会员卡
|
||||
]
|
||||
|
||||
// 从路由获取当前激活的 tab
|
||||
function getActiveIndexFromRoute() {
|
||||
const routePath = getCurrentRoutePath()
|
||||
@@ -64,38 +86,77 @@ function syncActiveState() {
|
||||
}
|
||||
}
|
||||
|
||||
// 检查当前页面是否需要隐藏 TabBar
|
||||
function checkShouldShow() {
|
||||
let routePath = getCurrentRoutePath()
|
||||
|
||||
// 标准化路径:去掉开头的 /
|
||||
if (routePath.startsWith('/')) {
|
||||
routePath = routePath.slice(1)
|
||||
}
|
||||
// 去掉查询参数(?后面的内容)
|
||||
if (routePath.includes('?')) {
|
||||
routePath = routePath.split('?')[0]
|
||||
}
|
||||
|
||||
// 检查是否在隐藏列表中
|
||||
const shouldHide = HIDE_TABBAR_PAGES.includes(routePath)
|
||||
shouldShowTabBar.value = !shouldHide
|
||||
|
||||
console.log('=== TabBar 显示控制 ===')
|
||||
console.log('原始路径:', getCurrentRoutePath())
|
||||
console.log('标准化路径:', routePath)
|
||||
console.log('是否隐藏:', shouldHide)
|
||||
console.log('是否显示 TabBar:', shouldShowTabBar.value)
|
||||
}
|
||||
|
||||
// 监听路由变化(页面切换时自动同步)
|
||||
let routeWatcher = null
|
||||
let appRouteCallback = null
|
||||
|
||||
onMounted(() => {
|
||||
// 初始同步
|
||||
syncActiveState()
|
||||
checkShouldShow()
|
||||
|
||||
// 监听路由变化(App 端)
|
||||
// #ifdef APP-PLUS
|
||||
routeWatcher = plus.globalEvent.addEventListener('newintent', () => {
|
||||
setTimeout(syncActiveState, 50)
|
||||
})
|
||||
// App 端:监听页面显示
|
||||
routeWatcher = setInterval(() => {
|
||||
syncActiveState()
|
||||
checkShouldShow()
|
||||
}, 300)
|
||||
// #endif
|
||||
|
||||
// 监听页面显示(跨端通用)
|
||||
uni.onAppRoute ? uni.onAppRoute(() => {
|
||||
setTimeout(syncActiveState, 50)
|
||||
}) : null
|
||||
// #ifdef MP-WEIXIN
|
||||
// 小程序端:监听路由变化
|
||||
if (typeof uni.onAppRoute === 'function') {
|
||||
appRouteCallback = () => {
|
||||
setTimeout(() => {
|
||||
syncActiveState()
|
||||
checkShouldShow()
|
||||
}, 100)
|
||||
}
|
||||
uni.onAppRoute(appRouteCallback)
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// 清理监听
|
||||
// #ifdef APP-PLUS
|
||||
if (routeWatcher) {
|
||||
plus.globalEvent.removeEventListener('newintent', routeWatcher)
|
||||
clearInterval(routeWatcher)
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
if (appRouteCallback && typeof uni.offAppRoute === 'function') {
|
||||
uni.offAppRoute(appRouteCallback)
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
|
||||
// 监听 props 变化
|
||||
watch(() => props.active, () => {
|
||||
// 只有当 props 主动变化且不是来自路由同步时才更新
|
||||
const routeIndex = getActiveIndexFromRoute()
|
||||
if (routeIndex !== currentActiveIndex.value) {
|
||||
syncActiveState()
|
||||
@@ -179,6 +240,7 @@ function onTabTap(index) {
|
||||
isSwitching = false
|
||||
// 跳转完成后,再次同步确保高亮正确
|
||||
syncActiveState()
|
||||
checkShouldShow()
|
||||
}, 100)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user