微信小程序?qū)崿F(xiàn)日歷小功能
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)日歷功能的具體代碼,供大家參考,具體內(nèi)容如下

代碼
<!-- 日歷 -->
<view class="gradient">
<view class="box">
<view class="spaceAroundCenter flex_align_justify_b">
<view class="flex-item">
<view class="item-content flex_align_justify_c" bindtap="doDay" data-key='left'>
<view class="glyphicon glyphicon-triangle-left">
<van-icon name="arrow-left" class="flex_align" />
</view>
</view>
</view>
<view class="flex-item item-content-current-day">
<view class="item-content flex_align_justify_c">{{currentDate}}</view>
</view>
<view class="flex-item">
<view class="item-content flex_align_justify_c" bindtap="doDay" data-key="right">
<view class="glyphicon glyphicon-triangle-right">
<van-icon name="arrow" class="flex_align" />
</view>
</view>
</view>
</view>
<view class="spaceAroundCenter">
<view class="spaceAroundCenter_date">一</view>
<view class="spaceAroundCenter_date">二</view>
<view class="spaceAroundCenter_date">三</view>
<view class="spaceAroundCenter_date">四</view>
<view class="spaceAroundCenter_date">五</view>
<view class="spaceAroundCenter_date">六</view>
<view class="spaceAroundCenter_date">日</view>
</view>
<view class="spaceAroundCenter">
<view class="flex-item day_item" wx:for="{{currentDayList}}" wx:for-index='key' wx:for-item="vo" wx:key="{{key}}">
<view id='{{vo}}' class="item-content flex_align_justify_c bk-color-day" wx:if="{{vo == currentDay}}" bindtap='onClickItem'>{{vo}}</view>
<view id='{{vo}}' class="item-content flex_align_justify_c bk-color-dayClick" wx:elif="{{vo == currentClickKey && currentClickKey != '' && vo != ''}}" bindtap='onClickItem'>{{vo}}</view>
<view id='{{vo}}' class="item-content flex_align_justify_c" bindtap='onClickItem' wx:else>{{vo}}</view>
<view class="day_item_circle" wx:if="{{currentClickKey!=''&¤tClickKey==vo&&remindlist.length>=1}}"></view>
</view>
</view>
</view>
</view>
CSS:
/* 日歷 */
.gradient{
background: #fff;
margin-bottom: 16rpx;
overflow: hidden;
border-bottom: 1rpx solid #f1f1f1;
}
.gradient .box{
padding: 0 24rpx;
}
.glyphicon .iconfont{
font-size: 46rpx;
}
.spaceAroundCenter {
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: space-around;
}
.spaceAroundCenter_date{
font-size: 28rpx;
}
.flex-item {
/* flex-flow: nowrap;
flex-grow: 1;
flex-shrink: 1; */
width: 14.2%;
/* padding: 10rpx 0; */
height: 85rpx;
display: flex;
align-items: center;
justify-content: center;
}
.item-content {
font-size: 28rpx;
width:80%;
height: 60%;
}
/* 當(dāng)前日期 */
.bk-color-day {
color: #fff;
border-radius: 50%;
background-color: #dd5923;
}
/* 當(dāng)前選中日期 */
.bk-color-dayClick {
color: #fff;
border-radius: 50%;
background-color: #30318b;
}
.item-content-current-day {
flex-grow: 2;
}
.day_item{
position: relative;
}
.day_item_circle{
width: 10rpx;
height: 10rpx;
background: #dd5923;
position: absolute;
bottom: 0;
border-radius: 50%;
}
js:
Page({
data: {
currentDayList: '',
currentObj:'',
arr: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
currentDate:'',
currentDay:'',
year:'',
month:'',
currentClickKey:'',
remindlist:[1,2,3]
},
onLoad: function (options) {
var currentObj = this.getCurrentDayString()
this.setData({
currentDate: currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月',
currentDay: currentObj.getDate(),
currentObj: currentObj,
year: currentObj.getFullYear(),
month: currentObj.getMonth() + 1
})
this.setSchedule(currentObj);
},
doDay: function (e) {
this.setData({
currentClickKey:''
})
var arr = this.data.arr;
for (let i in arr) {
var newarr = 'arr[' + i + ']';
this.setData({
[newarr]: ''
})
}
var that = this
var currentObj = that.data.currentObj
var Y = currentObj.getFullYear();
var m = currentObj.getMonth() + 1;
var d = currentObj.getDate();
var str = ''
if (e.currentTarget.dataset.key == 'left') {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
} else {
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
}
currentObj = new Date(str)
this.setData({
currentDate: currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月',
currentObj: currentObj,
year: currentObj.getFullYear(),
month: (currentObj.getMonth() + 1),
day: ''
})
this.setSchedule(currentObj);
},
getCurrentDayString: function () {
var objDate = this.data.currentObj
if (objDate != '') {
return objDate
} else {
var c_obj = new Date()
var a = c_obj.getFullYear() + '/' + (c_obj.getMonth() + 1) + '/' + c_obj.getDate()
return new Date(a)
}
},
setSchedule: function (currentObj) {
var that = this
var m = currentObj.getMonth() + 1
var Y = currentObj.getFullYear()
var d = currentObj.getDate();
var dayString = Y + '/' + m + '/' + currentObj.getDate()
var currentDayNum = new Date(Y, m, 0).getDate()
var currentDayWeek = currentObj.getUTCDay() + 1
var result = currentDayWeek - (d % 7 - 1);
var firstKey = result <= 0 ? 7 + result : result;
var currentDayList = []
var f = 0
for (var i = 0; i < 42; i++) {
let data = []
if (i < firstKey - 1) {
currentDayList[i] = ''
} else {
if (f < currentDayNum) {
currentDayList[i] = f + 1
f = currentDayList[i]
} else if (f >= currentDayNum) {
currentDayList[i] = ''
}
}
}
that.setData({
currentDayList: currentDayList
})
},
// 設(shè)置點(diǎn)擊事件
onClickItem: function (e) {
// console.log(JSON.stringify(e));
// console.log(JSON.stringify(e.currentTarget));
this.setData({
currentClickKey: e.currentTarget.id
});
},
})
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開(kāi)發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript閉包_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了JavaScript閉包,閉包(closure)是Javascript語(yǔ)言的一個(gè)難點(diǎn),也是它的特色,很多高級(jí)應(yīng)用都要依靠閉包實(shí)現(xiàn)2017-06-06
javascript 漢字轉(zhuǎn)拼音實(shí)現(xiàn)代碼
主要是提前定義了很多文字,這樣的方法不是很是,如果庫(kù)中沒(méi)有這個(gè)詞,是看不到相關(guān)信息的。2009-12-12
JSON序列化與解析原生JS方法且IE6和chrome測(cè)試通過(guò)
JSON序列化與解析本文通過(guò)原生JS方法實(shí)現(xiàn),IE6和chrome下均測(cè)試通過(guò),喜歡的朋友可以嘗試操作下2013-09-09
js實(shí)現(xiàn)網(wǎng)頁(yè)收藏功能
這篇文章主要介紹了js實(shí)現(xiàn)動(dòng)態(tài)添加或刪除網(wǎng)址功能,以及js實(shí)現(xiàn)網(wǎng)頁(yè)收藏功能,感興趣的小伙伴們可以參考一下2015-12-12
小程序中監(jiān)聽(tīng)頁(yè)面滾動(dòng)的幾種方法實(shí)例
這段時(shí)間接了一個(gè)微信小程序項(xiàng)目,從此打開(kāi)小程序的新世界大門,下面這篇文章主要給大家介紹了關(guān)于小程序中監(jiān)聽(tīng)頁(yè)面滾動(dòng)的幾種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04
《javascript設(shè)計(jì)模式》學(xué)習(xí)筆記二:Javascript面向?qū)ο蟪绦蛟O(shè)計(jì)繼承用法分析
這篇文章主要介紹了Javascript面向?qū)ο蟪绦蛟O(shè)計(jì)繼承用法,結(jié)合實(shí)例形式分析了《javascript設(shè)計(jì)模式》中JavaScript面向?qū)ο蟪绦蛟O(shè)計(jì)繼承相關(guān)概念、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04
用javascript取得傳遞參數(shù)的個(gè)數(shù)的代碼
用javascript取得傳遞參數(shù)的個(gè)數(shù)的代碼...2007-10-10
使用JavaScript實(shí)現(xiàn)Java的List功能(實(shí)例講解)
使用JavaScript實(shí)現(xiàn)Java的List功能(實(shí)例講解)。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-11-11
JavaScript 復(fù)制對(duì)象與Object.assign方法無(wú)法實(shí)現(xiàn)深復(fù)制
這篇文章主要介紹了JavaScript 復(fù)制對(duì)象與Object.assign方法無(wú)法實(shí)現(xiàn)深復(fù)制,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11

