|
|
@@ -161,39 +161,36 @@
|
|
|
@click="doSignIn"
|
|
|
:disabled="isSignedToday"
|
|
|
>
|
|
|
- {{ isSignedToday ? '今日已签到' : '立即签到' }}
|
|
|
- </button>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- </uni-popup>
|
|
|
- </view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import api from '../../utils/api.js'
|
|
|
export default {
|
|
|
data() {
|
|
|
- return {
|
|
|
- profile: {
|
|
|
- realName: '',
|
|
|
- avatarUrl: '',
|
|
|
- badge: '',
|
|
|
- rating: 5.0,
|
|
|
- level: '',
|
|
|
- levelName: '',
|
|
|
- nextLevelName: '',
|
|
|
- points: 0,
|
|
|
- currentLevelPoints: 0,
|
|
|
- nextLevelPoints: 100,
|
|
|
- pointsToNextLevel: 0,
|
|
|
- levelProgress: 0
|
|
|
- },
|
|
|
- // 签到相关
|
|
|
- isSignedToday: false,
|
|
|
- continuousDays: 0,
|
|
|
- totalDays: 0,
|
|
|
- }
|
|
|
- },
|
|
|
+ return {
|
|
|
+ profile: {
|
|
|
+ realName: '',
|
|
|
+ avatarUrl: '',
|
|
|
+ badge: '',
|
|
|
+ rating: 5.0,
|
|
|
+ level: '',
|
|
|
+ levelName: '',
|
|
|
+ nextLevelName: '',
|
|
|
+ points: 0,
|
|
|
+ currentLevelPoints: 0,
|
|
|
+ nextLevelPoints: 100,
|
|
|
+ pointsToNextLevel: 0,
|
|
|
+ levelProgress: 0
|
|
|
+ },
|
|
|
+ // 签到相关
|
|
|
+ isSignedToday: false,
|
|
|
+ continuousDays: 0,
|
|
|
+ totalDays: 0,
|
|
|
+ currentDate: new Date(),
|
|
|
+ calendarTitle: '',
|
|
|
+ calendarDays: []
|
|
|
+ }
|
|
|
+ },
|
|
|
onLoad() {
|
|
|
this.loadProfileData()
|
|
|
this.checkSignInStatus()
|
|
|
@@ -204,15 +201,13 @@
|
|
|
this.loadProfileData()
|
|
|
},
|
|
|
methods: {
|
|
|
- // ...
|
|
|
- }
|
|
|
- }
|
|
|
-</script>
|
|
|
+ // 生成日历数据
|
|
|
+ generateCalendar() {
|
|
|
+ const date = this.currentDate || new Date()
|
|
|
+ const year = date.getFullYear()
|
|
|
const month = date.getMonth()
|
|
|
-
|
|
|
// 设置日历标题
|
|
|
this.calendarTitle = `${year}年·${month + 1}月`
|
|
|
-
|
|
|
// 获取当月第一天
|
|
|
const firstDay = new Date(year, month, 1)
|
|
|
// 获取当月第一天是星期几(0-6,0表示周日)
|
|
|
@@ -223,9 +218,7 @@
|
|
|
const lastDayDate = lastDay.getDate()
|
|
|
// 获取上个月最后一天的日期
|
|
|
const prevMonthLastDay = new Date(year, month, 0).getDate()
|
|
|
-
|
|
|
const days = []
|
|
|
-
|
|
|
// 添加上个月的日期
|
|
|
for (let i = firstDayWeek - 1; i >= 0; i--) {
|
|
|
days.push({
|
|
|
@@ -235,7 +228,6 @@
|
|
|
isChecked: false
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
// 添加当月的日期
|
|
|
const today = new Date()
|
|
|
const isCurrentMonth = today.getFullYear() === year && today.getMonth() === month
|
|
|
@@ -248,7 +240,6 @@
|
|
|
isChecked: isToday && this.isSignedToday
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
// 添加下个月的日期,补满6行
|
|
|
const totalDays = 42 // 6行7列
|
|
|
const nextMonthDays = totalDays - days.length
|
|
|
@@ -260,45 +251,32 @@
|
|
|
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,
|
|
|
@@ -332,27 +310,19 @@
|
|
|
// 检查今日是否已签到
|
|
|
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
|
|
|
@@ -363,8 +333,6 @@
|
|
|
}
|
|
|
}
|
|
|
this.isSignedToday = !!signed
|
|
|
-
|
|
|
- // 获取签到统计
|
|
|
const stats = await api.matchmaker.checkinStats(userId)
|
|
|
console.log('获取签到统计返回结果:', stats)
|
|
|
if (stats) {
|
|
|
@@ -372,7 +340,6 @@
|
|
|
this.totalDays = stats.totalDays || 0
|
|
|
}
|
|
|
} else {
|
|
|
- // 没有有效的userId,重置签到状态
|
|
|
this.isSignedToday = false
|
|
|
this.continuousDays = 0
|
|
|
this.totalDays = 0
|
|
|
@@ -380,7 +347,6 @@
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('检查签到状态失败:', error)
|
|
|
- // API调用失败时,重置签到状态
|
|
|
this.isSignedToday = false
|
|
|
this.continuousDays = 0
|
|
|
this.totalDays = 0
|
|
|
@@ -388,7 +354,6 @@
|
|
|
},
|
|
|
// 显示签到弹框
|
|
|
showSignInPopup() {
|
|
|
- // 无论是否已签到,都显示签到弹框,让用户可以看到签到记录
|
|
|
this.$refs.signInPopup.open()
|
|
|
},
|
|
|
// 关闭签到弹框
|
|
|
@@ -398,26 +363,18 @@
|
|
|
// 执行签到
|
|
|
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
|
|
|
@@ -430,39 +387,30 @@
|
|
|
}
|
|
|
}
|
|
|
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'
|
|
|
@@ -523,10 +471,8 @@
|
|
|
content: '确定要退出登录吗?',
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
- // 清除本地存储
|
|
|
uni.removeStorageSync('token')
|
|
|
uni.removeStorageSync('userInfo')
|
|
|
- // 跳转到登录页
|
|
|
uni.navigateTo({
|
|
|
url: '/pages/page3/page3'
|
|
|
})
|