const month = date.getMonth() // 设置日历标题 this.calendarTitle = `${year}年·${month + 1}月` // 获取当月第一天 const firstDay = new Date(year, month, 1) // 获取当月第一天是星期几(0-6,0表示周日) const firstDayWeek = firstDay.getDay() // 获取当月最后一天 const lastDay = new Date(year, month + 1, 0) // 获取当月最后一天的日期 const lastDayDate = lastDay.getDate() // 获取上个月最后一天的日期 const prevMonthLastDay = new Date(year, month, 0).getDate() const days = [] // 添加上个月的日期 for (let i = firstDayWeek - 1; i >= 0; i--) { days.push({ date: prevMonthLastDay - i, isCurrentMonth: false, isToday: false, isChecked: false }) } // 添加当月的日期 const today = new Date() const isCurrentMonth = today.getFullYear() === year && today.getMonth() === month for (let i = 1; i <= lastDayDate; i++) { const isToday = isCurrentMonth && today.getDate() === i days.push({ date: i, isCurrentMonth: true, isToday: isToday, isChecked: isToday && this.isSignedToday }) } // 添加下个月的日期,补满6行 const totalDays = 42 // 6行7列 const nextMonthDays = totalDays - days.length for (let i = 1; i <= nextMonthDays; i++) { days.push({ date: i, isCurrentMonth: false, isToday: false, isChecked: false }) } this.calendarDays = days }, // 加载个人资料数据 async loadProfileData() { try { // 从本地存储获取用户信息 const userInfo = uni.getStorageSync('userInfo') console.log('从本地存储获取到的用户信息:', userInfo) // 模拟用户信息,用于测试 const testUserId = 19 const userId = userInfo && userInfo.userId ? userInfo.userId : testUserId console.log('使用的userId:', userId) // 调用API获取红娘信息 console.log('开始调用API获取红娘信息...') const matchmakerInfo = await api.matchmaker.getByUserId(userId) console.log('API调用结果:', matchmakerInfo) if (matchmakerInfo) { // 等级名称映射 const levelNames = ['', '青铜', '白银', '黄金', '铂金', '钻石'] // 获取当前等级和下一级名称 const currentLevel = matchmakerInfo.level || 1 const nextLevel = currentLevel < 5 ? currentLevel + 1 : 5 const nextLevelName = levelNames[nextLevel] // 根据性别设置默认头像 const defaultAvatars = { male: 'http://115.190.125.125:9000/dynamic-comments/dynamics/5c645152-9940-41d3-83a9-69ee6e0c0aaa.png', female: 'http://115.190.125.125:9000/dynamic-comments/dynamics/c7fb04d7-ee4d-4b3d-bcef-f246da9c841f.png' } const avatarUrl = matchmakerInfo.gender === 1 ? defaultAvatars.male : defaultAvatars.female // 打印获取到的数据,用于调试 console.log('获取到的红娘信息:', matchmakerInfo) // 更新profile数据,将下划线命名转换为驼峰命名 this.profile = { realName: matchmakerInfo.real_name || '', avatarUrl: avatarUrl, badge: matchmakerInfo.type_name || '', rating: matchmakerInfo.rating || 5.0, level: currentLevel, levelName: matchmakerInfo.level_name || levelNames[currentLevel], nextLevelName: nextLevelName, points: matchmakerInfo.points || 0, currentLevelPoints: matchmakerInfo.current_level_points || 0, nextLevelPoints: matchmakerInfo.next_level_points || 100, pointsToNextLevel: matchmakerInfo.points_to_next_level || 0, levelProgress: matchmakerInfo.level_progress || 0 } console.log('更新后的profile数据:', this.profile) } else { console.log('matchmakerInfo为空,无法更新profile数据') } } catch (error) { console.error('加载个人资料失败:', error) uni.showToast({ title: '加载失败,请稍后重试: ' + error.message, icon: 'none' }) } }, // 返回上一页 goBack() { uni.navigateBack() }, // 检查今日是否已签到 async checkSignInStatus() { try { // 从本地存储获取用户信息 const userInfo = uni.getStorageSync('userInfo') const userId = userInfo && userInfo.userId ? userInfo.userId : null // 只有在有有效userId时才调用API if (userId) { // 调用API检查签到状态 const res = await api.matchmaker.checkinStatus(userId) console.log('检查签到状态返回结果:', res) // 只在明确标记为已签到时才置为 true,避免对象/字符串被当成 true let signed = false if (typeof res === 'boolean') { signed = res } else if (typeof res === 'string') { // 后端可能返回 'true' / 'false' signed = res === 'true' } else if (typeof res === 'number') { // 约定 1 表示已签到,0 表示未签到 signed = res === 1 } else if (res && typeof res === 'object') { // 常见结构兼容:{ todaySigned: true } / { signed: true } / { isSignedToday: true } if (typeof res.todaySigned === 'boolean') signed = res.todaySigned else if (typeof res.signed === 'boolean') signed = res.signed else if (typeof res.isSignedToday === 'boolean') signed = res.isSignedToday else if (typeof res.data === 'object' && res.data) { if (typeof res.data.todaySigned === 'boolean') signed = res.data.todaySigned else if (typeof res.data.signed === 'boolean') signed = res.data.signed else if (typeof res.data.isSignedToday === 'boolean') signed = res.data.isSignedToday } } this.isSignedToday = !!signed // 获取签到统计 const stats = await api.matchmaker.checkinStats(userId) console.log('获取签到统计返回结果:', stats) if (stats) { this.continuousDays = stats.continuousDays || 0 this.totalDays = stats.totalDays || 0 } } else { // 没有有效的userId,重置签到状态 this.isSignedToday = false this.continuousDays = 0 this.totalDays = 0 console.warn('没有有效的userId,无法检查签到状态') } } catch (error) { console.error('检查签到状态失败:', error) // API调用失败时,重置签到状态 this.isSignedToday = false this.continuousDays = 0 this.totalDays = 0 } }, // 显示签到弹框 showSignInPopup() { // 无论是否已签到,都显示签到弹框,让用户可以看到签到记录 this.$refs.signInPopup.open() }, // 关闭签到弹框 closeSignInPopup() { this.$refs.signInPopup.close() }, // 执行签到 async doSignIn() { try { // 从本地存储获取用户信息 const userInfo = uni.getStorageSync('userInfo') const userId = userInfo && userInfo.userId ? userInfo.userId : null // 只有在有有效userId时才调用API if (userId) { // 调用签到API const res = await api.matchmaker.doCheckin(userId) console.log('签到API返回结果:', res) // 解析返回结果,兼容多种返回结构 let success = false let alreadySigned = false if (typeof res === 'boolean') { // true 表示本次签到成功,false 表示失败或已签到 success = res } else if (typeof res === 'string') { // 'ok' / 'success' 之类 success = res === 'true' || res === 'ok' || res === 'success' } else if (res && typeof res === 'object') { // { success: true, todaySigned: true } 等结构 if (typeof res.success === 'boolean') success = res.success if (typeof res.todaySigned === 'boolean') alreadySigned = res.todaySigned else if (typeof res.signed === 'boolean') alreadySigned = res.signed else if (typeof res.isSignedToday === 'boolean') alreadySigned = res.isSignedToday if (res.data && typeof res.data === 'object') { if (typeof res.data.success === 'boolean') success = res.data.success if (typeof res.data.todaySigned === 'boolean') alreadySigned = res.data.todaySigned else if (typeof res.data.signed === 'boolean') alreadySigned = res.data.signed else if (typeof res.data.isSignedToday === 'boolean') alreadySigned = res.data.isSignedToday } } if (success) { // 签到成功 uni.showToast({ title: '签到成功', icon: 'success' }) // 更新签到状态 this.isSignedToday = true // 重新生成日历,更新当天签到状态 this.generateCalendar() // 刷新个人资料(更新积分) this.loadProfileData() // 关闭弹框 this.closeSignInPopup() } else if (alreadySigned) { // 接口明确表示今日已签到 uni.showToast({ title: '今日已签到', icon: 'none' }) } else { // 签到失败 uni.showToast({ title: '签到失败,请稍后重试', icon: 'none' }) } } else { // 没有有效的userId,提示用户登录 uni.showToast({ title: '请先登录', icon: 'none' }) // 跳转到登录页 setTimeout(() => { uni.navigateTo({ url: '/pages/page3/page3' }) }, 1000) } } catch (error) { console.error('签到失败:', error) uni.showToast({ title: error.msg || '签到失败,请稍后重试', icon: 'none' }) } }, // 签到(旧方法,保持兼容) handleSignIn() { this.showSignInPopup() }, // 我的资源 handleMyResources() { uni.navigateTo({ url: '/pages/matchmaker-workbench/my-resources' }) }, // 活动中心 handleActivityCenter() { uni.navigateTo({ url: '/pages/activities/list' }) }, // 积分商城 handlePointsMall() { console.log('积分商城') uni.showToast({ title: '积分商城开发中', icon: 'none' }) }, // 编辑资料 handleEditProfile() { console.log('编辑资料') uni.navigateTo({ url: '/pages/matchmaker-workbench/edit-profile' }) }, // 账户设置 handleAccountSettings() { console.log('账户设置') uni.showToast({ title: '账户设置开发中', icon: 'none' }) }, // 退出登录 handleLogout() { uni.showModal({ title: '退出登录', content: '确定要退出登录吗?', success: (res) => { if (res.confirm) { // 清除本地存储 uni.removeStorageSync('token') uni.removeStorageSync('userInfo') // 跳转到登录页 uni.navigateTo({ url: '/pages/page3/page3' }) } } }) }, // 导航到工作台 navigateToWorkbench() { uni.navigateTo({ url: '/pages/matchmaker-workbench/index' }) }, // 导航到我的资源 navigateToMyResources() { uni.navigateTo({ url: '/pages/matchmaker-workbench/my-resources' }) }, // 导航到排行榜 navigateToRanking() { uni.navigateTo({ url: '/pages/matchmaker-workbench/ranking' }) }, // 导航到消息 navigateToMessage() { uni.navigateTo({ url: '/pages/matchmaker-workbench/message' }) }, // 导航到我的 navigateToMine() { // 已在我的页面,无需跳转 } } }