uniapp小程序自定义日历(签到、补签功能)

devtools/2025/2/26 12:06:17/

1、切换月份根据当前月判断,只能切换当前月份之前的时间。

2、补卡功能,根据后台设置自己写上即可,可补签多少天。

3、点击签到是签到当前天的,不能指定签到时间。

备注:当前代码只构建了排版样式和切换月份功能,签到状态根据个人开发以及接口返回的详细内容再次处理。

<template><view class="sign-in"><view class="sign-in-date"><view>今日签到 <textstyle="color: #F05C1C;display: inline-block;margin-left: 15rpx;margin-right: 15rpx;">18积分</text> 待领取</view><view><view class="date-icon" @click="LastMonth"><image src="/static/left-Date.png" style="width: 100%;height: 100%;"></image></view><text>{{DateTitle}}</text><view class="date-icon"><image src="/static/right-Date.png" style="width: 100%;height: 100%;" @click="NextMonth"v-if="!hideDateIcon"></image></view></view><view><view><view class="week" v-for="(item,index) in weekFor" :key="index">{{item}}</view></view><view><view class="date" v-for="(item,index) in DateFor" :key="index"><image src="/static/success-QD.png" class="SuccessCss" v-if="item==22"></image><image src="/static/error-QD.png" class="SuccessCss" v-if="item==21"></image><text v-if="item!==22 && item!==21">{{item}}</text></view></view></view><view>签到</view></view></view>
</template><script>export default {data() {return {weekFor: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],DateTitle: '',MeDateTitle: '',DateFor: [],hideDateIcon: false}},onShow() {const currentDate = new Date();const year = currentDate.getFullYear();const month = currentDate.getMonth() + 1; // getMonth() 返回的月份是从0开始的,所以要加1  const day = currentDate.getDate();const formattedDate = `${year}年${month}月`;const daysInMonth = new Date(year, month, 0).getDate(); // 0代表上一个月的最后一天  const firstDayOfMonth = new Date(year, month - 1, 1); // month - 1 因为月份是从0开始的  const firstDayOfWeek = firstDayOfMonth.getDay(); // 0=周日, 1=周一, ..., 6=周六  const daysOfWeek = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];const firstDayOfWeekStr = daysOfWeek[firstDayOfWeek];console.log(`当前日期: ${formattedDate}`);this.DateTitle = ` ${formattedDate}`this.MeDateTitle = ` ${formattedDate}`console.log(`该月份的天数: ${daysInMonth}天`);this.DateFor = []for (let i = 1; i <= daysInMonth; i++) {this.DateFor.push(i);}console.log(`今天是: ${day}号`);console.log(`当前月份的第一天是: ${firstDayOfWeekStr}`);const emptyDaysMap = {'周一': 0,'周二': 1,'周三': 2,'周四': 3,'周五': 4,'周六': 5,'周日': 6};const emptyDaysCount = emptyDaysMap[firstDayOfWeekStr];for (let i = 0; i < emptyDaysCount; i++) {this.DateFor.unshift('');}this.checkDate();},methods: {//上个月LastMonth() {const [year, month] = this.DateTitle.split('年').map(part => part.replace('月', ''));const date = new Date(year, month - 1);date.setMonth(date.getMonth() - 1);const newYear = date.getFullYear();const newMonth = date.getMonth() + 1;this.DateTitle = `${newYear}年${newMonth}月`;this.getMonthInfo(); // 获取当前月份的信息   },//下个月NextMonth() {const [year, month] = this.DateTitle.split('年').map(part => part.replace('月', ''));const date = new Date(year, month - 1);date.setMonth(date.getMonth() + 1);const newYear = date.getFullYear();const newMonth = date.getMonth() + 1; // 获取新的月份,注意要加1  this.DateTitle = `${newYear}年${newMonth}月`;this.getMonthInfo(); // 获取当前月份的信息  },getMonthInfo() {const [year, month] = this.DateTitle.split('年').map(part => part.replace('月', ''));const numDays = new Date(year, month, 0).getDate(); // 获取当前月份的天数  const firstDay = new Date(year, month - 1, 1).getDay(); // 获取当前月份第一天是星期几  console.log(`当前月份有 ${numDays} 天,第一天是星期 ${firstDay === 0 ? '日' : firstDay}`);this.DateFor = [];for (let i = 1; i <= numDays; i++) {this.DateFor.push(i);}const daysOfWeek = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];const firstDayOfWeekStr = daysOfWeek[firstDay]; // 获取第一天的星期几字符串  // 计算空白天数  const emptyDaysMap = {'周一': 0,'周二': 1,'周三': 2,'周四': 3,'周五': 4,'周六': 5,'周日': 6,};const emptyDaysCount = emptyDaysMap[firstDayOfWeekStr]; // 获取空白天数  for (let i = 0; i < emptyDaysCount; i++) {this.DateFor.unshift('');}this.checkDate();},checkDate() {const meDateParts = this.MeDateTitle.match(/(\d+)年(\d+)月/);const dateParts = this.DateTitle.match(/(\d+)年(\d+)月/);if (meDateParts && dateParts) {const meYear = meDateParts[1];const meMonth = meDateParts[2];const dateYear = dateParts[1];const dateMonth = dateParts[2];// 判断是否为同一年月  this.hideDateIcon = (meYear === dateYear && meMonth === dateMonth);}},}}
</script><style lang="scss">.sign-in {width: 100vw;min-height: 100vh;float: left;background: #0F0817;.sign-in-date {width: 702rpx;border-radius: 24rpx;margin: 0 auto;background: linear-gradient(161deg, #1B1B24 29%, rgba(240, 92, 28, 0.33) 100%);padding-top: 32rpx;padding-bottom: 32rpx;}.sign-in-date>view:nth-child(1) {width: 654rpx;height: 30rpx;margin: 0 auto;display: flex;align-items: center;color: #FFFFFF;font-size: 24rpx;}.sign-in-date>view:nth-child(2) {width: 654rpx;height: 30rpx;margin: 49rpx auto 0;display: flex;align-items: center;justify-content: space-between;font-family: Akkurat Pro, Akkurat Pro;font-weight: bold;font-size: 28rpx;color: #FFFFFF;.date-icon {width: 44rpx;height: 44rpx;text-align: center;line-height: 44rpx;}}.sign-in-date>view:nth-child(3) {width: 654rpx;margin: 40rpx auto 0;}.sign-in-date>view:nth-child(3)>view:nth-child(1) {width: 100%;height: 93.4rpx;display: flex;align-items: center;.week {width: 93.4rpx;height: 93.4rpx;text-align: center;line-height: 93.4rpx;font-family: Akkurat Pro, Akkurat Pro;font-weight: bold;font-size: 24rpx;color: #FFFFFF;}}.sign-in-date>view:nth-child(3)>view:nth-child(2) {width: 100%;display: flex;align-items: center;flex-wrap: wrap;.date {width: 93.4rpx;height: 93.4rpx;text-align: center;line-height: 93.4rpx;font-family: Akkurat Pro, Akkurat Pro;font-weight: bold;font-size: 24rpx;color: #FFFFFF;display: flex;align-items: center;justify-content: center;.SuccessCss {width: 55rpx;height: 55rpx;text-align: center;line-height: 55rpx;}}}.sign-in-date>view:nth-child(4) {width: 654rpx;height: 88rpx;background: #F05C1C;border-radius: 59rpx;text-align: center;line-height: 88rpx;font-family: PingFang HK, PingFang HK;font-weight: 600;font-size: 32rpx;color: #FFFFFF;margin: 50rpx auto 0;}}
</style>


http://www.ppmy.cn/devtools/162780.html

相关文章

RAG技术落地:核心痛点与应对策略全面解析

RAG技术落地&#xff1a;核心痛点与应对策略全面解析 RAG技术落地&#xff1a;核心痛点与应对策略全面解析一、技术实现层的四大挑战二、数据质量管理的生死线三、产业落地的软性痛点四、未来技术演进方向 RAG技术落地&#xff1a;核心痛点与应对策略全面解析 检索增强生成&a…

UE(虚幻)学习(五)初学创建NPC移动和遇到的问题

最近在学习UE中遇到一些问题&#xff0c;把这些问题记录一下&#xff0c;因为实在废了很大功夫。 在学习了UE5的例子中的第三人称移动Demo&#xff0c;想实现几个NPC在场景内移动。 本来想自己写一个类&#xff0c;遇到一堆问题花费了好几天时间&#xff0c;所以我把问题写下来…

【qt计算器】

qt计算器 目录注释部分模块配置目标配置模板配置源文件配置头文件配置UI 文件配置1. 头文件保护宏2. 包含必要的头文件3. 命名空间声明4. 类的定义5. 构造函数和析构函数6. 私有槽函数7. 私有成员变量8. 头文件保护宏结束1. 包含头文件2. 构造函数 MainWindow::MainWindow(QWid…

使用机器学习进行土地覆盖分类

土地利用和土地覆盖 (LULC) 分类在林业和农业领域发挥着重要作用&#xff0c;无论是种植园管理、生态系统恢复、碳市场计划还是其他应用。监测土地覆盖和土地利用变化是特许权所有者的一项强制性任务&#xff0c;需要对其特许权区域进行一致且准确的分析。 作为一名 GIS 分析师…

数据结构——排序2

今天&#xff0c;我们来讲解一下选择排序和冒泡排序还有堆排序。 选择排序的基本思想&#xff1a;每一次从待排序的数据元素中选出最小&#xff08;或最大&#xff09;的一个元素&#xff0c;存放在序列的起始位置&#xff0c;直到全部待排序的数据元素排完 。 下图中只选取了它…

显卡(Graphics Processing Unit,GPU)架构详细解读

显卡架构主要分为两大类&#xff1a;GPU 核心架构&#xff08;也称为图形处理单元架构&#xff09;和显卡的其他组件&#xff08;如内存、控制器、输出接口等&#xff09;。本篇文章将对显卡架构进行详细分析&#xff0c;重点介绍 GPU 核心架构、显卡计算单元、显存结构、显卡管…

实现 INFINI Console 与 GitHub 的单点登录集成:一站式身份验证解决方案

本文将为您详细解析如何通过 GitHub OAuth 2.0 协议&#xff0c;为 INFINI Console 实现高效、安全的单点登录&#xff08;Single Sign-On, SSO&#xff09;集成。通过此方案&#xff0c;用户可直接使用 GitHub 账户无缝登录 INFINI Console&#xff0c;简化身份验证流程&#…

Spring Boot + Redis 实现分布式锁

在 Spring Boot 中结合 Redis 实现分布式锁&#xff0c;可以通过 Redisson 或 Jedis 等客户端来操作 Redis&#xff0c;从而实现分布式锁。以下是使用 Redisson 实现分布式锁的示例。 1. 添加依赖 在 pom.xml 中添加 Redisson 依赖&#xff1a; 登录后复制 <dependency>&…