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

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,
})
}
})
微信小程序日历课表的更多相关文章
- 微信小程序日历面板插件
创建日历面板组件,在components目录下创建calendar文件夹 1.calendar.js // components/calendar/calendar.js var util = req ...
- 微信小程序日历插件
1/ wxml代码 <view class="timePick"> <picker mode="date" fields="mo ...
- 微信小程序 --- 日历效果
wxml部分: <view class='box1' style='width: {{ sysW * 7 }}px'> <view class='dateBox'>{{ yea ...
- 微信小程序日历签到
近日做了一个项目需要用到日历插件,在网上找了一部分感觉跟项目不对口,所以就查考了其他的日历插件做了一个. 需求: 如图: 代码如下: index.wxml: <!--pages/pictrues ...
- [组件封装]微信小程序-日历
描述 切换月份, 当天文案为今天, 日期背景变色, 日期红点标识, 点击选中日期. 效果 源码 calendar.wxml <view class="component"&g ...
- 微信小程序--图片相关问题合辑
图片上传相关文章 微信小程序多张图片上传功能 微信小程序开发(二)图片上传 微信小程序上传一或多张图片 微信小程序实现选择图片九宫格带预览 ETL:微信小程序之图片上传 微信小程序wx.preview ...
- 微信小程序资源整理
微信小程序相关的文档.教程.开源项目等资源的整理,以便于开发学习使用. —— —— 收录仅作个人学习使用,涉及侵权行为及时联系: maple_6392@163.com 项目地址:GitHub | 码云 ...
- 微信小程序+OLAMI(欧拉蜜)自然语言API接口制作智能查询工具--快递、聊天、日历等
微信小程序最近比较热门,再加上自然语义理解也越来越被人关注,于是我想赶赶潮流,做一个小程序试试.想来想去快递查询应该是一种比较普遍的需求. 如果你也在通过自然语言接口做点什么,希望我的这篇博客能帮到你 ...
- 微信小程序横版日历,tab栏
代码地址如下:http://www.demodashi.com/demo/14243.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
随机推荐
- [UWP]实现一个轻量级的应用内消息通知控件
在UWP应用开发中,我们常常有向用户发送一些提示性消息的需求.这种时候我们一般会选择MessageDialog.ContentDialog或者ToastNotification来完成功能. 但是,我们 ...
- Varnish实现Web站点加速
Varnish 是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang使用3台Varnish代替了原来的12台Squid,性能比以前更好. Varnish 的作者Poul-He ...
- extern的使用详解(多文件编程)——C语言
extern——关键字 extern是C语言中的一个关键字,一般用在变量名前或函数名前,作用是用来说明“此变量/函数是在别处定义的,要在此处引用”,extern这个关键字大部分读者应该是在变量的存储类 ...
- 微信小程序如何套用iconfont
前言 如果你在开发微信时,没有图标的话,可以到http://www.iconfont.cn/ 官方下使用图标,那么我们去使用一些吧,到官方网址下点击使用~ 下载代码即可使用,看看下载的文件吧. 如图可 ...
- SQL-2--TRIGGER
触发器TRIGGER 是一个被指定关联到一个表的数据库对象,当对一个表的特定事件出现时,它将被激活. 触发器是数据库响应 INSERT , UPDATE, DELITE 语句而自动执行的一条SQL语句 ...
- SpringBoot跨域小结
前言:公司的SpringBoot项目出于某种原因,经常样处理一些跨域请求. 一.以前通过查阅相关资料自己写的一个处理跨域的类,如下. 1.1首先定义一个filter(拦截所有请求,包括跨域请求) pu ...
- python 离散序列 样本数伸缩(原创)
解决问题: 有一个固定长度的1维矩阵,将这个矩阵的取样点进行扩充和减少 功能函数: def discrete_scale(data, num): import numpy as np import c ...
- 关于一个div上下左右居中的css方法
1:通过position:absolute定位,上下左右的值都设为0,margin:auto:需要知道div的宽高 { width: 64px; height: 64px; border: 1px s ...
- mysql 开发进阶篇系列 34 工具篇 mysqlcheck(MyISAM表维护工具)
一.概述 mysqlcheck客户端工具可以检查和修复MyISAM表,还可以优化和分析表.实际上,它集成了mysql工具中check,repair,analyze,optimize功能,对于check ...
- Java NIO中的通道Channel(二)分散/聚集 Scatter/Gather
什么是Scatter/Gather scatter/gather指的在多个缓冲区上实现一个简单的I/O操作,比如从通道中读取数据到多个缓冲区,或从多个缓冲区中写入数据到通道: scatter(分散): ...