This commit is contained in:
田岩
2025-11-04 09:35:41 +08:00
parent df1004edca
commit a35d0af64a
10 changed files with 542 additions and 61 deletions
+64 -40
View File
@@ -21,13 +21,12 @@
</text>
</view>
<scroll-view scroll-y="true" class="scroll-Y" :show-scrollbar="false">
<view class="calendar-div" :class="{expand:expand}">
<view class="calendar-div" :class="{ expand: expand }">
<view
class="calendar-line"
v-for="(line, lineIndex) in dateGroups"
v-show="nowLine === lineIndex || expand"
>
<view
class="calendar-day"
v-for="(day, dayIndex) in line.days"
@@ -57,10 +56,13 @@
<view class="button-div">
<uv-button
class="button"
text="签到"
:text="isSigned ? '已签到' : '签到'"
loadingText="签到中"
:custom-style="customStyle"
:color="buttonColor"
@click="expand = !expand"
@click="checkIn"
:disabled="isSigned"
:loading="checkInLoading"
></uv-button>
</view>
</view>
@@ -73,7 +75,8 @@
<script setup>
import { ref, computed } from 'vue';
import { optionErrorIcon, optionSuccessIcon } from '@/common/imgSvg';
import { addPointsByCheckIn, queryCheckIn } from '@/api/pointsAndRank.js';
import common from '@/common/common';
const popup = ref(null);
const buttonColor = 'linear-gradient( 270deg, #E0914A 0%, #EDBE7F 100%)';
const customStyle = {
@@ -82,17 +85,17 @@
const dateGroups = ref([]);
const expand = ref(false); // 展开状态
const isSigned = ref(false); // 今日签到状态
const continuousDay = ref(6); // 连续签到
const continuousDay = ref(0); // 连续签到
// 判断一下当前的签到显示在第几周
const nowLine = computed(() => {
// 计算当前需要显示图标的天数(已签到则是连续天数,未签到则是下一天)
const currentDay = isSigned.value ? continuousDay.value : continuousDay.value + 1;
// 按每周7天分行,行数从0开始(例如:1-7天 → 第0行,8-14天 → 第1行...
// 注意:如果天数从1开始(不是0),需要减1再计算
return Math.floor((currentDay - 1) / 7);
// 计算当前需要显示图标的天数(已签到则是连续天数,未签到则是下一天)
const currentDay = isSigned.value ? continuousDay.value : continuousDay.value + 1;
// 按每周7天分行,行数从0开始(例如:1-7天 → 第0行,8-14天 → 第1行...
// 注意:如果天数从1开始(不是0),需要减1再计算
return Math.floor((currentDay - 1) / 7);
});
const emits = defineEmits(['checkInFun'])
// 切换显示状态
const switchStatus = () => {
expand.value = !expand.value;
@@ -101,6 +104,26 @@
const close = () => {
popup.value.close();
};
const checkInLoading = ref(false);
// 签到
const checkIn = () => {
if (checkInLoading.value) return;
checkInLoading.value = true;
addPointsByCheckIn({days:6})
.then((res) => {
console.log('签到结果', res);
checkInLoading.value = false;
isSigned.value = true;
continuousDay.value = continuousDay.value + 1;
common.msg('签到成功,请明日继续!')
emits('checkInFun', true)
})
.catch((err) => {
checkInLoading.value = false;
common.msg('签到失败,请稍后再试');
});
};
/**
* 生成35天日期列表(分5组,每组7天),包含类型标记和text字段
* 以"前X天"为第一天,第1天显示1,每7天显示5,第30天显示30
@@ -172,31 +195,33 @@
return groupedList;
}
// 示例:X=10时,以"10天前"为第1天,生成35天列表
try {
const X = continuousDay.value - (isSigned.value ? 1 : 0);
// const X = 10;
console.log(`${continuousDay.value}`);
console.log(`${X}天前为第1天的35天分组日期:`);
dateGroups.value = generateGroupedDateList(X);
dateGroups.value.forEach((group) => {
console.log(`\n第${group.groupIndex + 1}`);
console.log(
group.days.map((day) => ({
日期: day.date,
天数序号: day.index, // 显示当前是第几天
text: day.text,
类型: day.type
}))
);
});
} catch (err) {
console.error(err.message);
}
const open = () => {
const open = (checkInToday,days) => {
isSigned.value = checkInToday==='Y'?true:false// 今日签到状态
// isSigned.value = false// 今日签到状态
continuousDay.value = days // 连续签到
// 示例:X=10时,以"10天前"为第1天,生成35天列表
try {
const X = continuousDay.value - (isSigned.value ? 1 : 0);
// const X = 10;
console.log(`${continuousDay.value}`);
console.log(`${X}天前为第1天的35天分组日期`);
dateGroups.value = generateGroupedDateList(X);
// dateGroups.value.forEach((group) => {
// console.log(`\n第${group.groupIndex + 1}组:`);
// console.log(
// group.days.map((day) => ({
// 日期: day.date,
// 天数序号: day.index, // 显示当前是第几天
// text: day.text,
// 类型: day.type
// }))
// );
// });
} catch (err) {
console.error(err.message);
}
popup.value.open();
};
defineExpose({ open, close });
@@ -217,8 +242,7 @@
display: none;
}
}
.calendar-day-bg {
width: 70rpx;
height: 84rpx;