相思资源网 Design By www.200059.com
本文实例为大家分享了微信小程序实现日历功能的具体代码,供大家参考,具体内容如下
效果图:
代码:
<view class="calendar"> <view class="selectDate"> <view class="goleft iconfont icon-jianzuo" bindtap="prevMonth"></view> <view class="date-wrap"> {{year}}年{{month}}月 </view> <view class="goright iconfont icon-jianzuo" bindtap="nextMonth"></view> </view> <view class="week"> <view wx:for="{{weekArr}}" wx:for-index="index" wx:for-item="item" wx:key="key" style="width:{{param}}px;height:{{param-17}}px;line-height:{{param-17}}px">{{item}}</view> </view> <view class="date" style='width: {{ param * 7 }}px;'> <block wx:for="{{dateArr}}" wx:for-index="index" wx:for-item="item" wx:key="key"> <view style="{{index ==0" class="{{index+1==day"><view class="day">{{item}}</view></view> </block> </view> </view><!--end calendar-->
data: { year:'', month:'', day:'', weekArr: ['日', '一', '二', '三', '四', '五','六'], dateArr:[], firstDay:'', lastDay:'', param:null, clockNum:3, }, getDate: function () { //获取当月日期 var mydate = new Date(); var year = mydate.getFullYear(); var month = mydate.getMonth(); var months = month + 1; this.data.year = year; this.data.month = months; this.data.day = mydate.getDate(); var fist = new Date(year, month, 1); this.data.firstDay = fist.getDay(); var last = new Date(year, months, 0); this.data.lastDay = last.getDate(); this.setData({ year: this.data.year, month: this.data.month, day: this.data.day, firstDay: this.data.firstDay, lastDay: this.data.lastDay }) console.log("今天:" + this.data.day); }, setDate: function () { for (var i = 1; i < this.data.lastDay + 1; i++) { this.data.dateArr.push(i); } this.setData({ dateArr: this.data.dateArr, firstDay: this.data.firstDay }) }, prevMonth:function(){ //上一月 var months=""; var years=""; if(this.data.month ==1){ years=this.data.year-1 this.data.month=12; months=this.data.month; }else{ years=this.data.year; months = this.data.month - 1; } var first = new Date(years, months-1, 1); this.data.firstDay = first.getDay(); var last = new Date(years, months, 0); this.data.lastDay = last.getDate(); this.setData({ month: months, year:years, firstDay: this.data.firstDay, lastDay: this.data.lastDay }) this.data.dateArr = []; for (var i = 1; i < this.data.lastDay + 1; i++) { this.data.dateArr.push(i); } this.setData({ dateArr: this.data.dateArr }) }, nextMonth:function(){ //下一月 var months=""; var years=""; if(this.data.month== 12){ this.data.month=0; months = this.data.month; years = this.data.year+1; }else{ months = this.data.month+1; years = this.data.year; } var months = this.data.month + 1; var first = new Date(years, months-1,1); this.data.firstDay= first.getDay(); var last = new Date(years,months,0); this.data.lastDay= last.getDate(); this.setData({ month: months, year:years, firstDay:this.data.firstDay, lastDay:this.data.lastDay }) this.data.dateArr = []; for (var i = 1; i < this.data.lastDay + 1; i++) { this.data.dateArr.push(i); } this.setData({ dateArr: this.data.dateArr }) }, onLoad: function (options) { this.getDate(); this.setDate(); var res = wx.getSystemInfoSync(); this.setData({ param:res.windowHeight/12, }) },
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
微信小程序,日历
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无微信小程序实现日历功能的评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。