python 微信小程序签到系统_微信小程序实现签到的日历功能

1358f31b7e4b41449818ae6cb75753be.png

前言

因为要做签到,所以要写了个日历。

只有基础的日历,签到需要自行实现。

(我等下也要实现签到了…)

效果图

b3ddeb718b8cc1e59b37e96df05a3b97.png

wxml

{{ item }}

wx:for="{{ dateData }}">

{{ item.day }}

wxss.calendar{

margin-top: 10%;}.month{

display: flex;

flex-flow: row wrap;

font-size: 1.1rem; }.item{

width: 14.28%;

text-align: center;

line-height: 3rem;}.othe{

color: grey}

js// pages/sing_in/sing_in.jsPage({

data: {

dateData: [],

isSignin: false,

week: ['日','一','二','三','四','五','六'],

},

onLoad: function (options) {

this.initCurrMonthData()

},

/**

* year string 年 如:2020

* month string 月 如: 5

* return array 所有天数 如:[1,2,3...,31]

**/

monthDays(year,month){

let days_count = new Date(year,month,0).getDate() //月总天数 如:31

let days = []; //存放月的天数

for(let i = 1; i <= days_count; i++)

days.push(i)

return days;

},

//初始化当月数据

initCurrMonthData(){

let currDate = new Date(); //当前日期

let currMonthDays = this.monthDays(currDate.getFullYear(),currDate.getMonth() + 1) //当月 +1是因为月从0开始 只有0-11

let lastMonthDays = this.monthDays(currDate.getFullYear(),currDate.getMonth() ) //上个月

let currFirstWeek = new Date(currDate.getFullYear(),currDate.getMonth() - 1, 1).getDay() + 1; //这个月的1号是星期几 -1是因从0开始

//月最后一天是星期几

let dateData = [];

dateData = currMonthDays.map(val => this.formatDay(val)) //当月的数据

for(let i = 0; i < currFirstWeek; i++) //上月要显示的

dateData.unshift(

this.formatDay( lastMonthDays.pop(),'last')

);

let nextLenth = 42 - dateData.length; // 42是因为 6 * 7格式

for(var i = 1; i <= nextLenth; i++) //下个月需要显示的日期

dateData.push(

this.formatDay( i, 'next')

);

this.setData({

dateData : dateData })

},

formatDay(day,type = 'curr'){ //日期数据的格式化

return {day:day,type:type};

},

onShareAppMessage: function () {

}})

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值