前言
因为要做签到,所以要写了个日历。
只有基础的日历,签到需要自行实现。
(我等下也要实现签到了…)
相关学习推荐:微信小程序开发教程
效果图
wxml
<view class="sign-wrapper"> <view class="calendar"> <view class="month"> <view class="item" wx:for="{{ week }}"> {{ item }} </view> <view class="item {{ item.type != 'curr' ? 'othe' : '' }}" wx:for="{{ datedata }}"> {{ item.day }} </view> </view> </view> </view>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 () { }})相关学习推荐:微信公众号开发教程
腾讯云gpu服务器收费想把备案主体变更为另外一个企业反思企业网站优化和网站推广的效果美国服务器速度慢是怎么回事Spark API编程中spark文件操作和debug是怎样的腾讯云云服务器怎么搭建网站腾讯云服务器老年人买学生学校使用阿里云服务器收费价格表