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

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 ...
随机推荐
- [Python] networkx入门 转
networkx是python的一个第三方包,可以方便地调用各种图算法的计算. 通过调用python画图包matplotlib能实现图的可视化. 1.安装 正好整理一下python第三方包的安装方法. ...
- SQL Server PageIOLatch和PageLatch
Latch是轻量级的锁,它是SQL Server内部用来同步资源访问的一个数据结构,使数据的访问同步有序,这意味着,当一个线程获得资源R的Latch的独占使用权时,如果其他的线程也想访问这个Latch ...
- WPF实现特殊统计图
效果图: ActiveFunItem.xaml代码: <UserControl x:Class="SunCreate.Vipf.Client.UI.ActiveFunItem" ...
- 背水一战 Windows 10 (65) - 控件(WebView): 对 WebView 中的内容截图, 通过 Share Contract 分享 WebView 中的被选中的内容
[源码下载] 背水一战 Windows 10 (65) - 控件(WebView): 对 WebView 中的内容截图, 通过 Share Contract 分享 WebView 中的被选中的内容 作 ...
- RunC容器逃逸漏洞席卷业界,网易云如何做到实力修复?
近日,业界爆出的runC容器越权逃逸漏洞CVE-2019-5736,席卷了整个基于runC的容器云领域,大量云计算厂商和采用容器云的企业受到影响.网易云方面透露,经过技术团队的紧急应对,网易云上的容器 ...
- 一致性hash理解、拜占庭将军问题解读和CAP理论总结
一致性hash理解 白话概述: 比如说存储图片,有10台服务器用来存储,对图片名进行hash(pic_name)%10得到的值就是图片存放的服务器序号.这是正常的hash算法分散图片存储.但是有一天, ...
- Java 命令行启动时指定配置文件目录
java -jar -Xbootclasspath/a:/home/tms/conf /home/tms/bin/S17-tms.jar 先指定配置文件目录: 再指定jar包路径: 运行clas ...
- Java 单元测试顺序执行
坑死我了,原来@Before会执行多次. 通过函数名可以实现顺序执行,执行顺序和函数的位置无关. import org.junit.Before; import org.junit.BeforeCla ...
- Xamarin.Android 使用线程无法更改页面文本问题
前言: 刚接触Xamarin.Android不到一个月时间,却被他折磨的不要不要的,随着开发会出现莫名其妙的问题,网上类似Xamarin.Android的文档也不多,于是本片文章是按照Java开发An ...
- odoo开发笔记 -- 字段增加唯一约束
前台违反约束效果: 后台模型中定义代码: name = fields.Char(string="Name", copy=False) # 流水号 _sql_constraints ...