最近项目中使用到了日历,在网上找了一些参考,自己改改,先看效果图

wxml

<view class="date">
<image class="direction" src="/images/icon/left.png" bindtap='minusMouth'/>
<label>{{year}}年{{mouth}}月</label>
<image class="direction" src="/images/icon/right.png" bindtap='plusMouth' />
</view>
<view class="header">
<block wx:for="{{weeks}}" wx:key="index">
<text class="weeks-item-text">{{item}}</text>
</block>
</view> <view class="body-days">
<block wx:for="{{days}}" wx:key="index">
<block wx:if="{{item !== nowDate }}">
<view class="days-item" data-date='{{year}}-{{mouth}}-{{item}}' bindtap='selDate'>
<view class="days-item-text" wx:if="{{item>0}}">{{item}}</view>
</view>
</block>
<block wx:else>
<view class="days-item days-item-selected" data-date='{{year}}-{{mouth}}-{{item}}' bindtap='selDate'>
<view class="days-item-text" wx:if="{{item>0}}">{{item}}</view>
</view>
</block>
</block>
</view>

wxss

.date {
display: flex;
flex-direction: row;
justify-content: center;
line-height: 3em;
align-items: center;
} .direction {
width: 40rpx;
margin: 15rpx;
height: 40rpx;
} .header {
display: flex;
flex-direction: row;
background: #5DD79C;
color: #fff
} .weeks-item-text {
width: 100%;
line-height: 2em;
font-size: 40rpx;
text-align: center;
border-left: 1px solid #ececec; } .body-days {
display: flex;
flex-direction: row;
flex-wrap: wrap;
text-align: center;
} .days-item {
width: 14.285%;
display: flex;
justify-content: center;
align-content: center;
} .days-item-text {
width: 60rpx;
padding: 26rpx;
font-size: 26rpx;
/* border-radius: 50%; */
border: 1rpx solid #ececec;
/* margin-top: 34rpx;
margin-bottom: 34rpx; */
color: #000;
}
/* 选中状态 */
.days-item-selected{
background: #5DD79C
}

js

Page({

  /**
* 页面的初始数据
*/
data: {
date: [],
weeks: ['日', '一', '二', '三', '四', '五', '六'],
days: [],
year: 0,
mouth: 0,
nowDate:''
}, /**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this
that.dateData();
var myDate = new Date();//获取系统当前时间
var nowDate = myDate.getDate();
that.setData({
nowDate:nowDate
})
console.log(nowDate) },
// 点击日期事件
selDate:function(e){
let that = this
// 日期 年月日
var seldate = e.currentTarget.dataset.date
// 天
var selday = e.currentTarget.dataset.day
console.log(seldate)
that.setData({
nowDate: selday
})
}, //用户点击减少月份
minusMouth: function () {
var mouth;
var year;
mouth = this.data.mouth
year = this.data.year
mouth--
if (mouth < 1) {
mouth = 12
year--
}
this.updateDays(year, mouth)
},
//用户点击增加月份
plusMouth: function () {
var mouth;
var year;
mouth = this.data.mouth
year = this.data.year
mouth++
if (mouth > 12) {
mouth = 1
year++
}
this.updateDays(year, mouth)
},
dateData: function () {
var date = new Date();
var days = [];
var year = date.getFullYear();
var mouth = date.getMonth() + 1;
this.updateDays(year, mouth) },
updateDays: function (year, mouth) {
var days = [];
var dateDay, dateWeek;
// 根据日期获取每个月有多少天
var getDateDay = function (year, mouth) {
return new Date(year, mouth, 0).getDate();
}
//根据日期获取这天是周几
var getDateWeek = function (year, mouth) { return new Date(year, mouth - 1, 1).getDay();
} dateDay = getDateDay(year, mouth)
dateWeek = getDateWeek(year, mouth) // console.log(dateDay);
// console.log(dateWeek);
//向数组中添加天
for (let index = 1; index <= dateDay; index++) {
days.push(index)
}
//向数组中添加,一号之前应该空出的空格
for (let index = 1; index <= dateWeek; index++) {
days.unshift(0)
}
this.setData({
days: days,
year: year,
mouth: mouth,
})
}
})

微信小程序日历课表的更多相关文章

  1. 微信小程序日历面板插件

    创建日历面板组件,在components目录下创建calendar文件夹 1.calendar.js // components/calendar/calendar.js var util = req ...

  2. 微信小程序日历插件

    1/   wxml代码 <view class="timePick"> <picker mode="date" fields="mo ...

  3. 微信小程序 --- 日历效果

    wxml部分: <view class='box1' style='width: {{ sysW * 7 }}px'> <view class='dateBox'>{{ yea ...

  4. 微信小程序日历签到

    近日做了一个项目需要用到日历插件,在网上找了一部分感觉跟项目不对口,所以就查考了其他的日历插件做了一个. 需求: 如图: 代码如下: index.wxml: <!--pages/pictrues ...

  5. [组件封装]微信小程序-日历

    描述 切换月份, 当天文案为今天, 日期背景变色, 日期红点标识, 点击选中日期. 效果 源码 calendar.wxml <view class="component"&g ...

  6. 微信小程序--图片相关问题合辑

    图片上传相关文章 微信小程序多张图片上传功能 微信小程序开发(二)图片上传 微信小程序上传一或多张图片 微信小程序实现选择图片九宫格带预览 ETL:微信小程序之图片上传 微信小程序wx.preview ...

  7. 微信小程序资源整理

    微信小程序相关的文档.教程.开源项目等资源的整理,以便于开发学习使用. —— —— 收录仅作个人学习使用,涉及侵权行为及时联系: maple_6392@163.com 项目地址:GitHub | 码云 ...

  8. 微信小程序+OLAMI(欧拉蜜)自然语言API接口制作智能查询工具--快递、聊天、日历等

    微信小程序最近比较热门,再加上自然语义理解也越来越被人关注,于是我想赶赶潮流,做一个小程序试试.想来想去快递查询应该是一种比较普遍的需求. 如果你也在通过自然语言接口做点什么,希望我的这篇博客能帮到你 ...

  9. 微信小程序横版日历,tab栏

    代码地址如下:http://www.demodashi.com/demo/14243.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

随机推荐

  1. Junit 命令行测试 报错:Could not find class 理解及解决方法

    一.报错 : 『Could not find class』 下面给出三个示例比较,其中只有第一个是正确的. 1. MyComputer:bin marikobayashi$ java -cp .:./ ...

  2. 找出数组中求和等于y的所有子数组

    算法记录: 给定一个数组x,每个元素都是正整数,找出其中满足条件"求和等于y"的所有子数组.(简化问题,每个元素都不相等) x=[x1,...,xn],暴力搜索,复杂度O(2^n) ...

  3. Weex是如何让JS调用产生原生UIView的?

    从官方的Demo,我们知道,要在客户端显示Weex页面,是通过WXSDKInstance的实例实现的.我们先来看看这个类里面都有什么: @interface WXSDKInstance : NSObj ...

  4. 833. Find And Replace in String

    To some string S, we will perform some replacement operations that replace groups of letters with ne ...

  5. PHP基础架构

    PHP基础架构 一.PHP简介 PHP是一种非常流行的高级脚本语言,尤其适合Web开发,快速.灵活和实用是PHP最重要的特点.PHP自1995年由Lerdorf创建以来,在全球得到了非常广泛的应用. ...

  6. MANIFEST.MF文件详解

    1. 依赖包是否在classpath中: 2. 资源文件目录是否在classpath中: 3. 主类是否正确: 具体配置参考 maven-jar-plugin 配置 <plugin> &l ...

  7. 【WebAPI No.5】Core WebAPI中的自定义格式化

    介绍 Web API为JSON和XML提供媒体类型格式化程序.框架默认将这些格式化程序插入管道中.客户端可以在HTTP请求的Accept标头中请求JSON或XML. 格式化数据这个东西,其实没有什么最 ...

  8. PHP-CPP开发扩展(六)

    PHP-CPP是一个用于开发PHP扩展的C++库.本节讲解在C++中PHP异常.变量.常量的实现相关知识. 异常 PHP和C++都支持异常,而PHP-CPP库这两种语言之间的异常处理是完全透明的.你在 ...

  9. Eureka安全认证

    Eureka 服务加入安全认证只需要在之前的服务中增加三处步骤即可: 1.在Eureka Server中加入spring-boot-starter-security依赖 <dependencie ...

  10. visual studio code 在 mac 下按 F12无效

    vsc 默认通过 F12可以查看定义(Go to Definition),可以查看类或方法的定义: 但是在 mac 环境下,有时按 F12并不生效,但是菜单栏的 Go 选项是被启动的,此时需要进行 2 ...