修正布局,删改无用页面

This commit is contained in:
2026-06-24 08:13:12 +08:00
parent 8d8c823616
commit 0bebce3dc1
24 changed files with 2677 additions and 2796 deletions
@@ -8,7 +8,6 @@
>
<view :class="['entry-icon', { accent: item.accent }]">
<image :src="item.icon" mode="aspectFit" class="icon-img" />
<view v-if="item.title === '消息' && hasUnread" class="badge-dot"></view>
</view>
<text class="entry-title">{{ item.title }}</text>
<text class="entry-desc">{{ item.desc }}</text>
@@ -30,148 +29,12 @@
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { getUnreadMessageCount } from '@/api/main.js'
import { ref } from 'vue'
const unreadCount = ref(0)
const showCheckInMenu = ref(false)
const TEST_MODE = false
// 是否有未读消息(用于显示红点)
const hasUnread = computed(() => unreadCount.value > 0)
const loadUnreadCount = async () => {
if (TEST_MODE) {
unreadCount.value = 3
return
}
const token = uni.getStorageSync('token')
if (!token) {
console.log('[QuickEntry] token 不存在,跳过请求')
unreadCount.value = 0
return
}
try {
const userId = uni.getStorageSync('userId') || 1
console.log('[QuickEntry] 请求未读消息数量, userId:', userId)
const res = await getUnreadMessageCount(userId)
console.log('[QuickEntry] 未读消息数量响应数据:', res)
console.log('[QuickEntry] 响应完整类型:', typeof res, Object.prototype.toString.call(res))
let count = 0
// 兼容多种响应格式
if (typeof res === 'number') {
count = res
console.log('[QuickEntry] 使用直接数字格式')
} else if (typeof res === 'string' && res.trim() !== '') {
// 处理字符串数字,如 "20"
count = parseInt(res, 10)
console.log('[QuickEntry] 使用字符串转数字格式:', count)
} else if (res !== null && typeof res === 'object') {
if (typeof res.count === 'number') {
count = res.count
console.log('[QuickEntry] 使用 res.count')
} else if (res.data !== undefined) {
if (typeof res.data === 'number') {
count = res.data
console.log('[QuickEntry] 使用 res.data')
} else if (typeof res.data?.count === 'number') {
count = res.data.count
console.log('[QuickEntry] 使用 res.data.count')
} else if (Array.isArray(res.data?.content)) {
count = res.data.content.length
console.log('[QuickEntry] 使用 res.data.content.length')
} else if (Array.isArray(res.content)) {
count = res.content.length
console.log('[QuickEntry] 使用 res.content.length')
} else if (typeof res.data?.total === 'number') {
count = res.data.total
console.log('[QuickEntry] 使用 res.data.total')
} else if (typeof res.total === 'number') {
count = res.total
console.log('[QuickEntry] 使用 res.total')
}
} else if (Array.isArray(res.content)) {
count = res.content.length
console.log('[QuickEntry] 使用 res.content.length')
} else if (typeof res.total === 'number') {
count = res.total
console.log('[QuickEntry] 使用 res.total')
}
} else {
console.log('[QuickEntry] 无法解析响应格式,res:', res)
}
unreadCount.value = count
uni.setStorageSync('unreadMessageCount', count)
console.log('[QuickEntry] 最终未读数量:', count, 'hasUnread:', hasUnread.value)
} catch (e) {
console.error('[QuickEntry] 获取未读消息数失败:', e)
try {
const count = uni.getStorageSync('unreadMessageCount')
unreadCount.value = count || 0
} catch (e2) {
unreadCount.value = 0
}
}
}
const handleEntryClick = (item) => {
if (item.title === '消息' || item.title === '健身数据') {
if (TEST_MODE) {
uni.showLoading({
title: '加载中...',
mask: true
})
setTimeout(() => {
uni.hideLoading()
if (item.isTabBar) {
uni.switchTab({ url: item.path })
} else {
uni.navigateTo({ url: item.path })
}
}, 300)
return
}
const token = uni.getStorageSync('token')
if (!token) {
uni.showModal({
title: '请登录',
content: '是否跳转到登录页面?',
confirmText: '确定',
cancelText: '取消',
confirmColor: '#FF6B35',
success: (res) => {
if (res.confirm) {
uni.navigateTo({
url: '/pages/login/login'
})
}
}
})
return
}
uni.showLoading({
title: '加载中...',
mask: true
})
setTimeout(() => {
uni.hideLoading()
if (item.title === '消息') {
uni.navigateTo({
url: `${item.path}?unreadCount=${unreadCount.value}`
})
} else if (item.isTabBar) {
uni.switchTab({ url: item.path })
} else {
uni.navigateTo({ url: item.path })
}
}, 300)
} else if (item.title === '签到') {
if (item.title === '签到') {
const token = uni.getStorageSync('token')
if (!token) {
uni.showModal({
@@ -192,7 +55,6 @@ const handleEntryClick = (item) => {
}
showCheckInMenu.value = !showCheckInMenu.value
} else if (item.path) {
// tabbar 页面使用 switchTab
if (item.isTabBar) {
uni.switchTab({
url: item.path
@@ -233,44 +95,14 @@ const handleGroupCourseCheckIn = () => {
})
}
onMounted(() => {
loadUnreadCount()
})
uni.$on('pageShow', () => {
loadUnreadCount()
})
const entries = [
{
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/course.png',
title: '找课程',
desc: '精品课程',
accent: false,
path: "/pages/searchCourse/searchCourse"
path: "/pages/groupCourse/list"
},
{
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/plan.png',
title: '训练计划',
desc: '个性定制',
accent: true,
path: "/pages/train/index",
isTabBar: true
},
{
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/data.png',
title: '健身数据',
desc: '记录分析',
accent: false,
path: "/pages/memberInfo/bodyTestTrend"
},
{
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/message.png',
title: '消息',
desc: '通知消息',
accent: true,
path: "/pages/message/index"
},
{
icon: 'https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/icons/checkIn.png',
title: '签到',
@@ -23,6 +23,7 @@
v-for="(course, index) in courses"
:key="course.id || index"
class="course-card"
@click="handleJoinCourse(course)"
>
<!-- 课程图片区域 -->
<view class="course-image">
@@ -30,8 +31,6 @@
<image :src="course.image" mode="aspectFill" class="img" />
<!-- 图片渐变遮罩 -->
<view class="course-overlay"></view>
<!-- 差几人提示右上角 -->
<text v-if="course.remainingSlots > 0" class="remaining-slots">{{ course.remainingSlots }}</text>
<!-- 课程信息区域 -->
<view class="course-info">
<!-- 课程名称 -->
@@ -50,10 +49,6 @@
<text>{{ course.level }}</text>
</view>
</view>
<!-- 课程标签 -->
<view class="meta-item course-type-tag">
<text :class="['tag', course.tagType]">{{ course.tag }}</text>
</view>
</view>
</view>
</view>
@@ -65,7 +60,7 @@
<text>{{ course.participants }}人参与</text>
</view>
<!-- 去参与按钮 -->
<view class="join-btn" @click="handleJoinCourse(course)">
<view class="join-btn" @click.stop="handleJoinCourse(course)">
<text>去参与</text>
</view>
</view>
@@ -82,28 +77,6 @@ import { getGroupCoursePage } from '@/api/main.js'
// 推荐课程数据列表
const courses = ref([])
// 课程类型映射(用于显示标签)
const getCourseTypeName = (type) => {
const typeMap = {
'1': '瑜伽',
'2': '搏击',
'3': '塑形'
}
return typeMap[type] || '课程'
}
// 根据课程信息获取标签文本
const getTag = (course) => {
if (course.currentMembers / course.maxMembers >= 0.8) return '热门'
return getCourseTypeName(course.courseType)
}
// 根据课程信息获取标签样式类型
const getTagType = (course) => {
if (course.currentMembers / course.maxMembers >= 0.8) return 'hot'
return 'default'
}
// 计算课程时长
const calculateDuration = (startTime, endTime) => {
if (!startTime || !endTime) return '60分钟'
@@ -142,19 +115,15 @@ const fetchRecommendCourses = async () => {
return course.status !== '2' && course.currentMembers < course.maxMembers
})
// 只取前5个符合条件的课程
courses.value = filteredCourses.slice(0, 5).map(course => {
const remainingSlots = course.maxMembers - course.currentMembers
// 只取前3个符合条件的课程
courses.value = filteredCourses.slice(0, 3).map(course => {
return {
id: course.id,
image: getImageUrl(course.coverImage),
tag: getTag(course),
tagType: getTagType(course),
name: course.courseName || '未知课程',
duration: calculateDuration(course.startTime, course.endTime),
level: getCourseLevel(course),
participants: course.currentMembers || 0,
remainingSlots: remainingSlots,
rawData: course
}
})
@@ -250,50 +219,6 @@ onMounted(() => { fetchRecommendCourses() })
background: linear-gradient(to top, rgba(45, 74, 90, 0.7) 0%, transparent 60%);
}
.remaining-slots {
position: absolute;
top: 16rpx;
right: 16rpx;
padding: 6rpx 12rpx;
border-radius: 10rpx;
font-size: 20rpx;
font-weight: 600;
color: #ffffff;
background: linear-gradient(135deg, #FF6B35, #FF8F66);
z-index: 3;
}
.course-tag {
position: absolute;
top: 16rpx;
right: 16rpx;
padding: 6rpx 12rpx;
border-radius: 10rpx;
font-size: 20rpx;
font-weight: 600;
color: #ffffff;
background: linear-gradient(135deg, #7AB5CC, #9CCFDF);
z-index: 2;
&.hot {
background: linear-gradient(135deg, #6BA8C0, #8CC5D5);
}
&.new {
background: linear-gradient(135deg, #6DB5C8, #90CEDD);
}
&.free {
background: linear-gradient(135deg, #7AB5CC, #9CCFDF);
}
&.full {
background: linear-gradient(135deg, #A0B8C8, #B8CCD8);
}
&.ended {
background: linear-gradient(135deg, #B0C0CC, #C4D2DC);
}
&.default {
background: linear-gradient(135deg, #7AB5CC, #9CCFDF);
}
}
.course-info {
position: absolute;
left: 0;
@@ -349,21 +274,6 @@ onMounted(() => { fetchRecommendCourses() })
background: rgba(255, 255, 255, 0.25);
}
.course-type-tag {
background: transparent !important;
padding: 0 !important;
.tag {
padding: 4rpx 10rpx;
border-radius: 6rpx;
font-size: 20rpx;
font-weight: 600;
background: linear-gradient(135deg, #FF8F66, #FFB088);
color: #ffffff;
&.hot {
background: linear-gradient(135deg, #FF6B35, #FF8F66);
}
}
}
.meta-icon {
width: 22rpx;
@@ -5,13 +5,6 @@
<view class="section-header">
<!-- 区域标题 -->
<text class="section-title">今日推荐</text>
<!-- 查看更多按钮 -->
<view class="view-more" @click="handleViewMore">
<text>查看更多</text>
<text class="arrow">
<uni-icons type="right" size="20" color="#8CA0B0"></uni-icons>
</text>
</view>
</view>
<!-- 推荐列表 -->
@@ -19,8 +12,9 @@
<!-- 推荐项 -->
<view
v-for="(item, index) in recommends"
:key="index"
:key="item.id || index"
class="recommend-item"
@click="handleItemClick(item)"
>
<!-- 推荐项图片 -->
<image :src="item.image" mode="aspectFill" class="item-image" />
@@ -38,7 +32,7 @@
<!-- 推荐项操作区域 -->
<view class="item-action">
<!-- 开始训练按钮 -->
<view class="start-btn">
<view class="start-btn" @click.stop="handleItemClick(item)">
<text class="start-btn-text">开始训练</text>
</view>
<!-- 参与人数 -->
@@ -50,34 +44,71 @@
</template>
<script setup>
const handleViewMore = () => {
uni.navigateTo({ url: '/pages/discover/index' })
}
import { ref, onMounted } from 'vue'
import { getGroupCoursePage } from '@/api/main.js'
// 今日推荐数据列表
const recommends = [
{
image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=300&q=80',
title: '晨间活力唤醒跑',
tags: ['20分钟', '初级'],
desc: '唤醒身体,开启活力一天',
participants: '2784'
},
{
image: 'https://images.unsplash.com/photo-1517836357463-d25dfeac3438?w=300&q=80',
title: '全身力量塑形',
tags: ['50分钟', '中级'],
desc: '全身综合训练,塑造完美线条',
participants: '4126'
},
{
image: 'https://images.unsplash.com/photo-1490645935967-10de6ba17061?w=300&q=80',
title: '蛋白增肌饮食指南',
tags: ['营养饮食', '12分钟'],
desc: '科学饮食搭配,助力肌肉增长',
participants: '1865'
const recommends = ref([])
// 计算课程时长
const calculateDuration = (startTime, endTime) => {
if (!startTime || !endTime) return '60分钟'
const start = new Date(startTime)
const end = new Date(endTime)
const diffMs = end - start
if (diffMs <= 0) return ''
const durationMinutes = Math.floor(diffMs / (1000 * 60))
return `${durationMinutes}分钟`
}
// 获取课程难度
const getCourseLevel = (course) => {
if (course.courseType === '2') return '中级'
if (course.courseType === '3') return '高级'
if (course.courseType === '1') return '初级'
return '初级'
}
// 处理图片URL
const getImageUrl = (coverImage) => {
if (!coverImage) return 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=300&q=80'
if (coverImage.startsWith('http')) return coverImage
return `https://your-domain.com${coverImage}`
}
// 获取今日推荐
const fetchTodayRecommend = async () => {
try {
const res = await getGroupCoursePage({
page: 0, size: 10, sort: 'current_members', order: 'desc'
}, { cache: true, cacheTime: 5 * 60 * 1000 })
if (res && res.content && Array.isArray(res.content)) {
const filteredCourses = res.content.filter(course => {
return course.status !== '2' && course.currentMembers < course.maxMembers
})
recommends.value = filteredCourses.slice(0, 3).map(course => {
return {
id: course.id,
image: getImageUrl(course.coverImage),
title: course.courseName || '未知课程',
tags: [calculateDuration(course.startTime, course.endTime), getCourseLevel(course)],
desc: course.description || '精彩课程,不容错过',
participants: String(course.currentMembers || 0)
}
})
}
} catch (err) {
console.error('获取今日推荐失败:', err)
}
]
}
const handleItemClick = (item) => {
if (!item.id) { uni.showToast({ title: '课程信息不完整', icon: 'none' }); return }
uni.navigateTo({ url: `/pages/groupCourse/detail?id=${item.id}` })
}
onMounted(() => { fetchTodayRecommend() })
</script>
<style lang="scss" scoped>
@@ -100,18 +131,6 @@ const recommends = [
color: #2D4A5A;
}
.view-more {
display: flex;
align-items: center;
gap: 4rpx;
font-size: 26rpx;
color: var(--tabbar-text-inactive);
}
.arrow {
font-size: 32rpx;
}
.recommend-list {
display: flex;
flex-direction: column;