广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >js实现签到日历
  • 746
分享到

js实现签到日历

2024-04-02 19:04:59 746人浏览 八月长安
摘要

本文实例为大家分享了js实现签到日历的具体代码,供大家参考,具体内容如下 wxml代码 <view class="boxMain" style="height:{{dateL

本文实例为大家分享了js实现签到日历的具体代码,供大家参考,具体内容如下

wxml代码

<view class="boxMain" style="height:{{dateList.length>35?'805rpx':'730rpx'}}">
    <view class="calendarHeader">
        <view>本月已签到<text>{{recordList.length}}</text>天</view>
    </view>
    <view class="calendarChange">
        <view class="calendarChangeLeftRight" catchtap="initDateList" data-month="{{chooseMonth-1}}">
            <image mode="widthFix" src="{{static}}left_arrow.png"></image>
        </view>                
        <text>{{chooseYear}}年{{chooseMonth+1}}月</text>
        <view class="calendarChangeLeftRight" catchtap="initDateList" data-month="{{chooseMonth+1}}">
            <image mode="widthFix" src="{{static}}right_arrow.png"></image>
        </view>
    </view>
    <view class="calendarContent">
        <view class="calendarWeek">
            <text>日</text>
            <text>一</text>
            <text>二</text>
            <text>三</text>
            <text>四</text>
            <text>五</text>
            <text>六</text>
        </view>
        <view class="calendarDays">
            <view wx:for="{{dateList}}" wx:key="index" wx:for-item="dateItem">
                <view style="color:{{dateItem.type=='current'?'#ffffff':(dateItem.type=='before'?'#979797':(dateItem.type=='selected'?'#FE7458':''))}};background-color:{{ dateItem.type=='current'?'#FE7458':(dateItem.type=='before'?'#F8F8FA':(dateItem.type=='selected'?'#ffdcd5':'')) }}">
                    {{dateItem.day}}
                </view>      
            </view>
        </view>
    </view>
</view>

js代码:

const app = getApp()
const Http = require('../../config/api.js');
Page({
  data: {
    static: app.data.static,
    recordList: [],
    totalReward: {},
    dateList: [],
    chooseYear: new Date().getFullYear(),
    chooseMonth: new Date().getMonth(),
    currentDay: new Date().getDate(),
    dayNumsByMonth: null
  },
  onLoad() {
    this.initDateList(); //初始化日历
  },
  initDateList: function (e) {
    let that = this;
 
    let chooseMonth = that.data.chooseMonth;
    let chooseYear = that.data.chooseYear;
 
    let currentDate = new Date();
    let currentYear = currentDate.getFullYear();
    let currentMonth = currentDate.getMonth();
 
    if (e) {
      chooseMonth = e.currentTarget.dataset.month;
      if (chooseMonth >= 12) {
        chooseMonth = chooseMonth - 12;
        chooseYear = chooseYear + 1;
      } else if (chooseMonth < 0) {
        chooseMonth = chooseMonth + 12;
        chooseYear = chooseYear - 1;
      } else {
        chooseMonth = chooseMonth;
      }
      let monthCount = (currentYear - chooseYear) * 12 + currentMonth - chooseMonth;
      if (monthCount > 0 && Math.abs(monthCount) > 6) {
        wx.showToast({
          title: '往前最多查看六个月',
          icon: 'none',
          duration: 1500
        })
 
        return
      } else if (monthCount < 0 && Math.abs(monthCount) > 1) {
        wx.showToast({
          title: '往后最多查看一个月',
          icon: 'none',
          duration: 1500
        })
        return
      }
    }
 
    that.setData({
      chooseMonth: chooseMonth,
      chooseYear: chooseYear
    })
    var dateList = [];
 
    let firstDayWeek = new Date(that.data.chooseYear, that.data.chooseMonth, 1).getDay();
    let dayNumsByMonth = new Date(that.data.chooseYear, that.data.chooseMonth + 1, 0).getDate();
    that.setData({
      dayNumsByMonth: dayNumsByMonth
    })
 
    for (let i = 0; i < 43; i++) {
      let day = i - firstDayWeek + 1;
      if (day > dayNumsByMonth && (i == 35 || i == 42)) {
        that.setData({
          dateList: dateList
        });
        return
      }
      dateList.push({
        'year': '',
        'month': '',
        'day': '',
        'type': '',
      })
 
      if (day > 0 && day <= dayNumsByMonth) {
        dateList[i].year = that.data.chooseYear;
        dateList[i].month = that.isTen(that.data.chooseMonth + 1);
        dateList[i].day = that.isTen(day);
        if (that.data.chooseYear == currentYear && that.data.chooseMonth == currentMonth) {
 
          if (day < that.data.currentDay) {
            dateList[i].type = 'before';
          } else if (day > that.data.currentDay) {
            dateList[i].type = 'after';
          } else {
            dateList[i].type = 'current'
          }
          
        } else if (that.data.chooseYear < currentYear || (that.data.chooseYear == currentYear && that.data.chooseMonth < currentMonth)) {
          dateList[i].type = 'before';
         
        } else {
          dateList[i].type = 'after';
        }
      }
    }
  },
  isTen: function (v) {
    return v >= 10 ? v : `0${v}`
  }
});

wxss代码

.boxMain {
  background-color: #fff;
  margin: 36rpx 30rpx 22rpx 30rpx;
  border-radius: 10rpx;
  padding: 0 20rpx;
  display: flex;
  flex-direction: column;
}
 
.boxMain .calendarHeader {
  display: flex;
  justify-content: space-between;
  color: #333333;
  font-size: 28rpx;
  margin-top: 40rpx;
  padding: 0 4rpx;
}
 
.boxMain .calendarHeader view text {
  color: #FE7458;
  padding: 0 6rpx;
}
 
.boxMain .calendarHeader view:last-child {
  font-size: 24rpx;
}
 
.boxMain .calendarChange {
  display: flex;
  padding: 0 50rpx;
  align-items: center;
  justify-content: space-between;
  background-color: #F8F8FA;
  border-radius: 25rpx;
  height: 50rpx;
  line-height: 50rpx;
  font-size: 24rpx;
  text-align: center;
  margin: 25rpx 0;
}
.boxMain .calendarChange .calendarChangeLeftRight{
  width: 50rpx;
  height: 50rpx;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.boxMain .calendarChange image{
  width: 12rpx;
  margin: 0 auto;
}
.boxMain .calendarContent .calendarWeek{
  font-size: 26rpx;
  display: flex;    
  justify-content: space-between;
}
.boxMain .calendarContent .calendarWeek text{
  width: 14%;
  height: 40rpx;
  text-align: center;
}
.boxMain .calendarContent .calendarDays{
  font-size: 26rpx;
  display: flex;
  justify-content: space-between;
  flex-wrap:wrap;
  align-items: center;
  margin-top: 47rpx;
}
.boxMain .calendarContent .calendarDays>view{
  width: 14%;
  text-align: center;
  display: block;    
  margin-bottom: 32rpx;
  height: 46rpx;
  line-height: 46rpx;
}
.boxMain .calendarContent .calendarDays>view>view{
  width: 46rpx;
  height: 46rpx;
  margin: 0 auto;
  border-radius: 50%;
}
.boxMain .calendarContent .calendarDays .box{
  margin-top: -10rpx;
}
.boxMain .calendarContent .calendarDays .box image{
  width: 42rpx;
}
.boxMain .calendarContent .calendarDays .box text{
  float: left;
  margin-top: -20rpx;
  padding-left: 4rpx;
  color: #FE7458;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: js实现签到日历

本文链接: https://www.lsjlt.com/news/166219.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • js实现签到日历
    本文实例为大家分享了js实现签到日历的具体代码,供大家参考,具体内容如下 wxml代码 <view class="boxMain" style="height:{{dateL...
    99+
    2022-11-13
  • php js怎么实现日历签到
    本篇内容主要讲解“php js怎么实现日历签到”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“php js怎么实现日历签到”吧!php js实现日历签到的方法:首先创建好前台代码“$("...
    99+
    2023-06-20
  • vue实现签到日历效果
    本文实例为大家分享了vue实现签到日历效果的具体代码,供大家参考,具体内容如下 先看看我们的效果图: 一、页面部分: <template>   <div clas...
    99+
    2022-11-13
  • JavaScript自定义日历实现签到功能
    本文实例为大家分享了JavaScript自定义日历签到功能的具体代码,供大家参考,具体内容如下 先看下效果图 红色块为已签到的日期,样式可以随意更改,清晰明了,话不多说上代码: &...
    99+
    2022-11-13
  • Android自定义view实现日历打卡签到
    本文实例为大家分享了Android自定义view实现日历打卡签到的具体代码,供大家参考,具体内容如下 1.说明 自己写一个view实现每天签到的功能,设置背景图片 源码下载 2.效果...
    99+
    2022-11-12
  • 微信小程序实现日历签到功能
    本文实例为大家分享了微信小程序实现日历签到的具体代码,供大家参考,具体内容如下 wxml: <!--pages/signin/signin.wxml--> <vi...
    99+
    2022-11-13
  • 微信小程序日历签到怎么实现
    这篇文章主要介绍“微信小程序日历签到怎么实现”,在日常操作中,相信很多人在微信小程序日历签到怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”微信小程序日历签到怎么实现”的疑惑有所帮助!接下来,请跟着小编...
    99+
    2023-06-26
  • js如何实现日历功能
    这篇文章给大家分享的是有关js如何实现日历功能的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。突然发现日期对象可以进行 加减 , 利用这个特性写了一个可以说是对只要会JavaScr...
    99+
    2022-10-19
  • js实现简单日历效果
    本文实例为大家分享了js实现简单日历效果的具体代码,供大家参考,具体内容如下 ## css模块 <style type="text/css"> *{ ma...
    99+
    2022-11-12
  • 原生Js实现日历挂件
    本文实例为大家分享了js实现日历挂件的具体代码,供大家参考,具体内容如下 Css code #date { width: 220px; padding-bottom: ...
    99+
    2022-11-11
  • Android如何自定义view实现日历打卡签到
    这篇文章主要介绍Android如何自定义view实现日历打卡签到,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!Android是什么Android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备...
    99+
    2023-06-14
  • 如何用js实现日历功能
    这篇文章主要讲解了“如何用js实现日历功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何用js实现日历功能”吧! 示例代码...
    99+
    2022-10-19
  • js如何实现前端日历控件
    这篇文章主要介绍js如何实现前端日历控件,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!首先说下控件的依赖包,加载控件的时候必须先加载jQuery, jQuqery.UI, 另外jqu...
    99+
    2022-10-19
  • js+html+css实现简单日历效果
    本文实例为大家分享了js+html+css实现简单日历效果的具体代码,供大家参考,具体内容如下 效果: 遇到的问题与解决方法: 1.“日”上移 方法:在&l...
    99+
    2022-11-13
  • 原生Js如何实现日历挂件
    本篇内容主要讲解“原生Js如何实现日历挂件”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“原生Js如何实现日历挂件”吧!JS是什么JS是JavaScript的简称,它是一种直译式的脚本语言,其解释...
    99+
    2023-06-14
  • js如何实现日历的简单算法
    这篇文章将为大家详细讲解有关js如何实现日历的简单算法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。最近有用到日历可需要编辑文本的日历,为了...
    99+
    2022-10-19
  • 基于element日历组件实现签卡记录
    本文实例为大家分享了基于element日历组件实现签卡记录的具体代码,供大家参考,具体内容如下 使用element日历组件为基础,实现可以查看每天签卡记录 <template&...
    99+
    2022-11-13
  • java实现日历功能
    本文实例为大家分享了java实现日历功能的具体代码,供大家参考,具体内容如下 完成一个 java application应用程序,输出一份当前所在时区当前时间的一个月的日历(1号到2...
    99+
    2022-11-13
  • Java实现桌面日历
    本文实例为大家分享了Java实现桌面日历的具体代码,供大家参考,具体内容如下 问题描述: 编写一个程序,有一个窗口,该窗口为BorderLayout布局。窗口的中心添加一个Panel...
    99+
    2022-11-13
  • php怎么实现日历
    本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑php怎么实现日历?PHP实现的日历功能示例具体如下:<php header("Content-Type:text/html;charset=utf-8...
    99+
    2016-05-29
    PHP 日历
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作