国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 熱點(diǎn) > 微信 > 正文

微信小程序日歷/日期選擇插件使用方法詳解

2024-07-22 01:19:17
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

微信小程序日歷選擇器插件點(diǎn)擊日歷日期可以獲取到年月日,具體內(nèi)容如下

wxml

<view class="canlendarBgView"> <view class="canlendarView">  <view class="canlendarTopView">   <view class="leftBgView" bindtap="handleCalendar" data-handle="prev">    <view class="leftView">《</view>   </view>   <view class="centerView">{{cur_year || "--"}} 年 {{cur_month || "--"}} 月</view>   <view class="rightBgView" bindtap="handleCalendar" data-handle="next">    <view class="rightView">》</view>   </view>  </view>  <view class="weekBgView">   <view class="weekView" wx:for="{{weeks_ch}}" wx:key="{{index}}" data-idx="{{index}}">{{item}}</view>  </view>  <view class="dateBgView">   <view wx:if="{{hasEmptyGrid}}" class="dateEmptyView" wx:for="{{empytGrids}}" wx:key="{{index}}" data-idx="{{index}}">   </view>   <view class="dateView" wx:for="{{days}}" wx:key="{{index}}" data-idx="{{index}}" bindtap="dateSelectAction">    <view class="datesView {{index == todayIndex ? 'dateSelectView' : ''}}">{{item}}</view>   </view>  </view> </view> <view>點(diǎn)擊日期選擇</view></view>

js

//index.js//獲取應(yīng)用實(shí)例Page({ data: {  hasEmptyGrid: false,  cur_year: '',  cur_month: '', }, onLoad(options) {  this.setNowDate(); },  dateSelectAction: function (e) {  var cur_day = e.currentTarget.dataset.idx;  this.setData({   todayIndex: cur_day  })  console.log(`點(diǎn)擊的日期:${this.data.cur_year}年${this.data.cur_month}月${cur_day + 1}日`); },  setNowDate: function () {  const date = new Date();  const cur_year = date.getFullYear();  const cur_month = date.getMonth() + 1;  const todayIndex = date.getDate() - 1;  console.log(`日期:${todayIndex}`)  const weeks_ch = ['日', '一', '二', '三', '四', '五', '六'];  this.calculateEmptyGrids(cur_year, cur_month);  this.calculateDays(cur_year, cur_month);  this.setData({   cur_year: cur_year,   cur_month: cur_month,   weeks_ch,   todayIndex,  }) },  getThisMonthDays(year, month) {  return new Date(year, month, 0).getDate(); }, getFirstDayOfWeek(year, month) {  return new Date(Date.UTC(year, month - 1, 1)).getDay(); }, calculateEmptyGrids(year, month) {  const firstDayOfWeek = this.getFirstDayOfWeek(year, month);  let empytGrids = [];  if (firstDayOfWeek > 0) {   for (let i = 0; i < firstDayOfWeek; i++) {    empytGrids.push(i);   }   this.setData({    hasEmptyGrid: true,    empytGrids   });  } else {   this.setData({    hasEmptyGrid: false,    empytGrids: []   });  } }, calculateDays(year, month) {  let days = [];   const thisMonthDays = this.getThisMonthDays(year, month);   for (let i = 1; i <= thisMonthDays; i++) {   days.push(i);  }   this.setData({   days  }); }, handleCalendar(e) {  const handle = e.currentTarget.dataset.handle;  const cur_year = this.data.cur_year;  const cur_month = this.data.cur_month;  if (handle === 'prev') {   let newMonth = cur_month - 1;   let newYear = cur_year;   if (newMonth < 1) {    newYear = cur_year - 1;    newMonth = 12;   }    this.calculateDays(newYear, newMonth);   this.calculateEmptyGrids(newYear, newMonth);    this.setData({    cur_year: newYear,    cur_month: newMonth   })   } else {   let newMonth = cur_month + 1;   let newYear = cur_year;   if (newMonth > 12) {    newYear = cur_year + 1;    newMonth = 1;   }    this.calculateDays(newYear, newMonth);   this.calculateEmptyGrids(newYear, newMonth);    this.setData({    cur_year: newYear,    cur_month: newMonth   })  } }})            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 凌云县| 宁远县| 翁牛特旗| 元谋县| 饶河县| 合阳县| 枣强县| 徐汇区| 九龙县| 扶绥县| 葫芦岛市| 虎林市| 翁牛特旗| 惠安县| 大埔区| 柘城县| 丹凤县| 法库县| 平罗县| 油尖旺区| 隆化县| 长岛县| 墨脱县| 凤山市| 云龙县| 邹平县| 固始县| 延寿县| 来安县| 广南县| 萨迦县| 贡觉县| 罗山县| 贡觉县| 泰兴市| 醴陵市| 浦县| 疏勒县| 丰镇市| 榆树市| 腾冲县|