微信小程序日历选择器插件点击日历日期可以获取到年月日

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>点击日期选择</view>
</view>

wxss

/* pages/calendar/calendar.wxss */.canlendarBgView {flex-grow: 1;display: flex;flex-direction: column;align-items: center;
}.canlendarView {color: #6666CC;display: flex;flex-direction: column;
}.canlendarTopView {height: 80rpx;font-size: 28rpx;display: flex;flex-direction: row;align-items: center;justify-content: center;
}.leftBgView {text-align: right;height: 80rpx;display: flex;flex-direction: row-reverse;
}.leftView {width: 80rpx;height: 100%;display: flex;flex-direction: row;align-items: center;justify-content: center;
}.centerView {width: 50%;height: 80rpx;text-align: center;display: flex;flex-direction: row;align-items: center;justify-content: center;
}.rightBgView {height: 80rpx;display: flex;flex-direction: row;
}.rightView {width: 80rpx;height: 100%;display: flex;flex-direction: row;align-items: center;justify-content: center;
}.weekBgView {height: 50rpx;line-height: 50rpx;opacity: 0.5;display: flex;flex-direction: row;justify-content: center;align-items: center;
}.weekView {flex-grow: 1;text-align: center;font-size: 28rpx;
}.dateBgView {height: 500rpx;display: flex;flex-direction: row;flex-wrap: wrap;
}.dateEmptyView {width: 107.1428571429rpx;color: #fff;display: flex;align-items: center;justify-content: center;
}.dateView {width: 107.1428571429rpx;color: #fff;display: flex;align-items: center;justify-content: center;
}.datesView {width: 60rpx;height: 60rpx;color: #6666CC;font-size: 26rpx;font-weight: 200;display: flex;align-items: center;justify-content: center;
}.dateSelectView {border-radius: 50%;position: relative;left: 0;top: 0;color: #fff;background-color: #6666CC;
}

js

//index.js
//获取应用实例
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(`点击的日期:${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})}}
})

点击下载:点击打开链接

微信小程序(日历/日期)选择插件相关推荐

  1. 微信小程序日历日期选择(单/多)

    日历日期选择(单/多) 示例库 代码片段

  2. 微信小程序日历(酒店入住日期选择)

    微信小程序日历(酒店入住日期选择) wxml代码. <!-- 日历--> <!-- 引入wxs文件,用来在界面中使用函数 --> <wxs src="../.. ...

  3. 适配mpvue平台的的微信小程序日历组件mpvue-calendar

    mpvue-calendar 基于vue-calendar的适配mpvue平台的的微信小程序日历组件 预览 安装 npm i mpvue-calendar 使用 import Calendar fro ...

  4. 手把手教你写一个微信小程序日历组件

    今天我们一起写一个微信小程序日历组件 微信小程序日历组件 github.com/749264345/w- 好,我们先看一下要实现的模样,如下图 由以上截图我们可以看到 1.日历可以通过按钮[切换展示效 ...

  5. 微信小程序日历加课表项目

    最近花了不少时间做了个微信小程序,期间遇到了挺多技术问题的,写个博客记录一下,我先上小程序使用图片! 1.进入小程序首先要登录才能添加行程和查看行程 2.登录成功后 3.首页日历日期是可点击,点击后是 ...

  6. 微信小程序日历签到组件(原创)

    微信小程序日历签到组件(原创) 开发原因: 为满足定制需要,市面上又找不到车子和轮子,干脆自己撸了并开源分享有需要的人用 其他说明: 该组件js日期均已使用yyyy/MM/dd格式连接解决ios不兼容 ...

  7. 微信小程序日历(公历)

    微信小程序日历(公历) 周六加班的时候,突然想看看日历是怎么实现的,就试着写了一下. --------------------------分割线-------------------------- J ...

  8. 微信小程序拍照视频上传php,微信小程序-拍照或选择图片并上传文件

    微信小程序-拍照或选择图片并上传文件 调用拍照API:https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-picture.html?t=201612 ...

  9. 微信小程序实现城市选择效果(超详细)

    直接进入正题 首先在项目中同级创建一个components文件夹,在文件夹下创建region-picker文件夹,在该文件夹点击右键新建Component就会创建名为 region-picker.js ...

  10. 在微信小程序中,使用wxParse插件解析HTML/md富文本

    1. 在微信小程序中,使用wxParse插件解析HTML富文本 下载文件 GitHub地址:https://github.com/icindy/wxParse 解压文件,在解压后的文件夹里找到wxPa ...

最新文章

  1. Intersection of Two Linked Lists
  2. 必备技能,conda创建python虚拟环境,完美管理项目
  3. springmvc导出excel并弹出下载框
  4. HDU - 1024 Max Sum Plus Plus 最大m段子段和+滚动数组优化
  5. C--数据结构--树的学习
  6. Intel Skylake (Server) 架构/微架构/流水线 (5) - 非时效存储
  7. 二叉线索树的线索化以及遍历
  8. 右下角出现测试模式 win7 内部版本7601如何去掉
  9. 《Effective C#》Item 14:使用构造函数初始化语句
  10. 21天Jmeter打卡Day8 get/delete/put之间的请求
  11. 《沟通的技术——让交流、会议与演讲更有效》一第一部分 建导准备
  12. Android简易项目--傻瓜式阿拉伯语输入法(Dummy Arabic Input)
  13. CashFiesta注册网赚
  14. ADByby 自定义过滤语法简表
  15. 对promise、resolve和reject的简单理解
  16. Linux日文教程,Ubuntu日语、法语输入法的设置
  17. 我能成为一名布道师吗?
  18. scrapy爬虫实战教程
  19. vue2.0移动端 使用vue-pdf插件实现PDF文件流在线预览
  20. 曾仕强讲易经:元、亨、利、贞

热门文章

  1. 李时珍告诉你怎么不得病!放在手机上别丢了
  2. block IO层框架分析2
  3. Altium Designer-打开丝印层、位号,不显示器件位号问题
  4. ajax返回request,WordPress的Ajax请求返回0(Wordpress ajax request return 0)
  5. 如何定位Unity死循环导致的完全卡死
  6. 2020 年 11月 程序员工资统计,平均 14327 元
  7. 不止蔡徐坤,程序员也越努力越幸运?你是练习时长几年的程序员?
  8. pandas 第十二期组队-pandas基础
  9. Python利用百度地图获取两地距离 最详细过程和源代码
  10. JAVA打印空三角形