|
|
@@ -334,23 +334,35 @@
|
|
|
try {
|
|
|
// 从本地存储获取用户信息
|
|
|
const userInfo = uni.getStorageSync('userInfo')
|
|
|
- const testUserId = 19
|
|
|
- const userId = userInfo && userInfo.userId ? userInfo.userId : testUserId
|
|
|
+ const userId = userInfo && userInfo.userId ? userInfo.userId : null
|
|
|
|
|
|
- // 调用API检查签到状态
|
|
|
- const res = await api.matchmaker.checkinStatus(userId)
|
|
|
- console.log('检查签到状态返回结果:', res)
|
|
|
- this.isSignedToday = res || false
|
|
|
-
|
|
|
- // 获取签到统计
|
|
|
- const stats = await api.matchmaker.checkinStats(userId)
|
|
|
- console.log('获取签到统计返回结果:', stats)
|
|
|
- if (stats) {
|
|
|
- this.continuousDays = stats.continuousDays || 0
|
|
|
- this.totalDays = stats.totalDays || 0
|
|
|
+ // 只有在有有效userId时才调用API
|
|
|
+ if (userId) {
|
|
|
+ // 调用API检查签到状态
|
|
|
+ const res = await api.matchmaker.checkinStatus(userId)
|
|
|
+ console.log('检查签到状态返回结果:', res)
|
|
|
+ this.isSignedToday = res || false
|
|
|
+
|
|
|
+ // 获取签到统计
|
|
|
+ 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
|
|
|
}
|
|
|
},
|
|
|
// 显示签到弹框
|
|
|
@@ -367,33 +379,47 @@
|
|
|
try {
|
|
|
// 从本地存储获取用户信息
|
|
|
const userInfo = uni.getStorageSync('userInfo')
|
|
|
- const testUserId = 19
|
|
|
- const userId = userInfo && userInfo.userId ? userInfo.userId : testUserId
|
|
|
+ const userId = userInfo && userInfo.userId ? userInfo.userId : null
|
|
|
|
|
|
- // 调用签到API
|
|
|
- const res = await api.matchmaker.doCheckin(userId)
|
|
|
- console.log('签到API返回结果:', res)
|
|
|
- // 直接使用返回的布尔值判断签到结果
|
|
|
- if (res) {
|
|
|
- // 签到成功
|
|
|
- uni.showToast({
|
|
|
- title: '签到成功',
|
|
|
- icon: 'success'
|
|
|
- })
|
|
|
- // 更新签到状态
|
|
|
- this.isSignedToday = true
|
|
|
- // 重新生成日历,更新当天签到状态
|
|
|
- this.generateCalendar()
|
|
|
- // 刷新个人资料(更新积分)
|
|
|
- this.loadProfileData()
|
|
|
- // 关闭弹框
|
|
|
- this.closeSignInPopup()
|
|
|
+ // 只有在有有效userId时才调用API
|
|
|
+ if (userId) {
|
|
|
+ // 调用签到API
|
|
|
+ const res = await api.matchmaker.doCheckin(userId)
|
|
|
+ console.log('签到API返回结果:', res)
|
|
|
+ // 直接使用返回的布尔值判断签到结果
|
|
|
+ if (res) {
|
|
|
+ // 签到成功
|
|
|
+ uni.showToast({
|
|
|
+ title: '签到成功',
|
|
|
+ icon: 'success'
|
|
|
+ })
|
|
|
+ // 更新签到状态
|
|
|
+ this.isSignedToday = true
|
|
|
+ // 重新生成日历,更新当天签到状态
|
|
|
+ this.generateCalendar()
|
|
|
+ // 刷新个人资料(更新积分)
|
|
|
+ this.loadProfileData()
|
|
|
+ // 关闭弹框
|
|
|
+ this.closeSignInPopup()
|
|
|
+ } else {
|
|
|
+ // 今日已签到
|
|
|
+ uni.showToast({
|
|
|
+ title: '今日已签到',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
} else {
|
|
|
- // 今日已签到
|
|
|
+ // 没有有效的userId,提示用户登录
|
|
|
uni.showToast({
|
|
|
- title: '今日已签到',
|
|
|
+ title: '请先登录',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
+ // 跳转到登录页
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/page3/page3'
|
|
|
+ })
|
|
|
+ }, 1000)
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('签到失败:', error)
|