因?yàn)橐龊灥?所以要寫了個(gè)日歷。
只有基礎(chǔ)的日歷,簽到需要自行實(shí)現(xiàn)。
(我等下也要實(shí)現(xiàn)簽到了…)
效果圖wxml相關(guān)學(xué)習(xí)推薦:微信小程序開(kāi)發(fā)教程
<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 所有天數(shù) 如:[1,2,3...,31] **/ monthDays(year,month){ let days_count = new Date(year,month,0).getDate() //月總天數(shù) 如:31 let days = []; //存放月的天數(shù) for(let i = 1; i <= days_count; i++) days.push(i) return days; }, //初始化當(dāng)月數(shù)據(jù) initCurrMonthData(){ let currDate = new Date(); //當(dāng)前日期 let currMonthDays = this.monthDays(currDate.getFullYear(),currDate.getMonth() + 1) //當(dāng)月 +1是因?yàn)樵聫?開(kāi)始 只有0-11 let lastMonthDays = this.monthDays(currDate.getFullYear(),currDate.getMonth() ) //上個(gè)月 let currFirstWeek = new Date(currDate.getFullYear(),currDate.getMonth() - 1, 1).getDay() + 1; //這個(gè)月的1號(hào)是星期幾 -1是因從0開(kāi)始 //月最后一天是星期幾 let dateData = []; dateData = currMonthDays.map(val => this.formatDay(val)) //當(dāng)月的數(shù)據(jù) for(let i = 0; i < currFirstWeek; i++) //上月要顯示的 dateData.unshift( this.formatDay( lastMonthDays.pop(),'last') ); let nextLenth = 42 - dateData.length; // 42是因?yàn)?6 * 7格式 for(var i = 1; i <= nextLenth; i++) //下個(gè)月需要顯示的日期 dateData.push( this.formatDay( i, 'next') ); this.setData({ dateData : dateData }) }, formatDay(day,type = 'curr'){ //日期數(shù)據(jù)的格式化 return {day:day,type:type}; }, onShareAppMessage: function () { }})
相關(guān)學(xué)習(xí)推薦:微信公眾號(hào)開(kāi)發(fā)教程
網(wǎng)頁(yè)題目:微信小程序?qū)崿F(xiàn)簽到的日歷功能
文章網(wǎng)址:http://www.chinadenli.net/article17/cgphdj.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、營(yíng)銷型網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)