日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

日历代码(微信小程序)

發(fā)布時間:2024/8/1 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 日历代码(微信小程序) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

wxml代碼:`

<!--wxml--> <!--日歷,記錄女性月經(jīng)周期--> <view class="calendar"><!--年份和月份--> <view class="flex calendar-choose"><!--圖標--> <view class="previcon" bindtap="changeMonth"> <image src="../../images/small.png"></image> </view><!--顯示月份--> <view class="mouth-picker"> <view class="month">{{cur_month}}月</view> </view><!--顯示年份--> <view class="year-picker"> <view class="year">{{cur_year}}年</view> </view><!--圖標--> <view class="nexticon" bindtap="changeYear"> <image src="../../images/big.png" ></image> </view></view><view class="flex week-list"> <view class="week-itm" wx:for="{{weeklist}}">{{item}}</view> </view><view class="flex days-list"> <view class="day lm" wx:for="{{lastMonthDaysList}}" data-handle="prev"> <text>{{item}}</text> </view> <block wx:for="{{currentMonthDaysList}}"> <view class="day"> <text>{{item}}</text> </view> </block> <view class="day nm" wx:for="{{nextMonthDaysList}}" data-handle="next" > <text>{{item}}</text> </view> </view></view>

wxss代碼:

.calendar{width:100%;height:300rpx;}.calendar-choose{height:100rpx;line-height:100rpx;background:#fefefe;padding:0 30rpx;font-size:34rpx;color:#353535;border-bottom: 1rpx solid #e5e5e5;display:flex;justify-content:space-between; }.calendar .previcon, .calendar .nexticon{width:20%;height:40%;margin-top:12rpx; }.previcon image, .nexticon image {width:100%;height:100%; }.calendar .mouth-picker{width:600rpx;text-align: center;}.calendar .year-picker{width:600rpx;text-align: center;}.calendar .week-list {width:100%;height:70rpx;background:#b9c4c9;display:flex;justify-content:space-around; }.calendar .week-itm{font-size:30rpx;color:white;width:14.28%;height:100%;padding-left:43rpx;padding-top:15rpx; }.calendar .days-list{width:100%;display:flex;flex-wrap:wrap; }.day{width: 14%;height:60rpx;border-right:1rpx solid #e5e5e5;border-bottom:1rpx solid #e5e5e5;color:#333;position: relative;text-align: center;line-height: 60rpx;}.calendar .days-list .lm,.calendar .days-list .nm{color:#b6b6b6;}.calendar .day .ep{color:#333;}

js代碼:

Page({data: {cur_month: 0,cur_year: 0,weeklist: ['日', '一', '二', '三', '四', '五', '六'] }, onLoad: function (options) {var cur_year = new Date().getFullYear(); //獲取當前年var cur_month = new Date().getMonth(); //獲取當前月this.setData({cur_year: cur_year,cur_month: cur_month + 1});this.calendar(cur_year, cur_month + 1);},//頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作onPullDownRefresh: function () {},/**頁面上拉觸底事件的處理函數(shù)**/onReachBottom: function () {},/*用戶點擊右上角分享*/onShareAppMessage: function () {return {title: '簡單日歷實現(xiàn)小程序版本',desc: '簡單日歷實現(xiàn)小程序版本',path: '/pages/index/index'};},calendar: function(year, month) {var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];/*** 本月天數(shù)*/if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {days[1] = 29;}var day = days[month - 1];/*** 本月第一天星期幾*/var myDate = new Date(year, month - 1, 1);var weektime = myDate.getDay();/*** 上個月的天數(shù)*/if(month == 1) {var prevyear = year - 1;var prevmonth = 12;var prevday = 31;} else {prevmonth = month - 1;prevday = days[prevmonth - 1];}/*** 下個月的天數(shù)*/if(month == 12) {var nextyear = year + 1;var nextmonth = 1;var nextday = 31;} else {nextmonth = month + 1;nextday = days[nextmonth - 1];}/*** 日歷上第一個數(shù)字*/if(weektime == 0) {var firstnumber = 1;} else {firstnumber = prevday - weektime + 1;}/*** 日歷上最后一個數(shù)字*/if(firstnumber == 1) {var lastnumber = 7 - (day % 7);} else {if ((prevday - firstnumber + 1 + day) % 7 == 0) {lastnumber = day;} else {var remainder = (prevday - firstnumber + 1 + day) % 7;lastnumber = 7 - remainder;}}var lastMonthDaysList = [];var currentMonthDaysList = [];var nextMonthDaysList = [];if(firstnumber == 1) {lastMonthDaysList = [];} else{for(var i = firstnumber; i <= prevday; i++) {lastMonthDaysList.push(i);}}for(var i = 1; i <= day; i++) {currentMonthDaysList.push(i);}if(lastnumber == day) {nextMonthDaysList = [];} else {for(var i = 1; i <= lastnumber; i++) {nextMonthDaysList.push(i);}}this.setData({lastMonthDaysList: lastMonthDaysList,currentMonthDaysList: currentMonthDaysList,nextMonthDaysList: nextMonthDaysList})},changeMonth: function(e) {var cur_year = this.data.cur_year;if(this.data.cur_month == 1) {var cur_month = 12;cur_year = cur_year - 1;} else {cur_month = this.data.cur_month - 1;}this.setData({cur_year: cur_year,cur_month: cur_month});//console.log('cur_year', cur_year);//console.log('cur_month', cur_month);this.calendar(cur_year, cur_month);},changeYear: function(e) {var cur_year = this.data.cur_year - 1;var cur_month = this.data.cur_month;this.setData({cur_year: cur_year,cur_month: cur_month})this.calendar(cur_year, cur_month);}})

效果圖:

(有在網(wǎng)上參考別人的代碼,寫的不好,歡迎交流。)

總結(jié)

以上是生活随笔為你收集整理的日历代码(微信小程序)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。