React & Calendar
React & Calendar
日历

https://github.com/YutHelloWorld/calendar/blob/master/src/Calendar.js
// 国际化 i18n & L10n ??? local.config.json
renderTable() {
const weekdays = this.props.locale === 'en' ? ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
: ['日', '一', '二', '三', '四', '五', '六']
return (
<table className="calendar-table">
<tbody onClick={this.handleSelectDate}>
<tr>
{
weekdays.map((w, i) => <th key={w} >{w}</th>)
}
</tr>
{this.state.list.map(arr => {
return (
<tr key={arr[0]}>
{arr.map(value =>
(<td key={value}>
<span
data-date={value}
className={this.getClassName(value)}
>
{value.slice(8)}
</span>
</td>)
)}
</tr>
)
})}
</tbody>
</table>
)
}
https://github.com/YutHelloWorld/calendar/blob/master/src/utils/index.js
/**
* 获取日历展示日期列表
*
* @export
* @param {Number} y
* @param {Number} m
* @returns
*/
export function getDateList(y, m) {
const year = y
const month = m - 1
let list = []
const now = new Date(year, month)
const monthEnd = new Date(year, month + 1, 0) // 当月最后一天
const lastMonthEnd = new Date(year, month, 0) // 上月最后一天
const firstDay = now.getDay() // 当月第一天
const mEDate = monthEnd.getDate()
const lMEDate = lastMonthEnd.getDate()
// 计算上月出现在 中的日期
for (let i = 0; i < firstDay; i++) {
const tempM = month > 0 ? month : 12
const tempY = month > 0 ? year : year - 1
const strMonth = tempM < 10 ? `0${tempM}` : tempM
list.unshift(`${tempY}-${strMonth}-${lMEDate - i}`)
}
// 当月
for (let i = 1; i < mEDate + 1; i++) {
const strI = i < 10 ? '0' + i : i
const tempM = month + 1
const strMonth = tempM < 10 ? `0${tempM}` : tempM
list.push(`${year}-${strMonth}-${strI}`)
}
const tempLen = 42 - list.length
// 下月
for (let i = 1; i < tempLen + 1; i++) {
const strI = i < 10 ? '0' + i : i
const tempM = month + 2 < 13 ? month + 2 : 1
const tempY = month + 2 < 13 ? year : year + 1
const strMonth = tempM < 10 ? `0${tempM}` : `${tempM}`
list.push(`${tempY}-${strMonth}-${strI}`)
}
return list
}
const weeks = ["日", "一", "二", "三", "四", "五", "六"];
https://cloud.tencent.com/developer/article/1497665
https://segmentfault.com/a/1190000016296697
import * as React from 'react'
const WEEK_NAMES = ['日', '一', '二', '三', '四', '五', '六']
const LINES = [1,2,3,4,5,6]
const MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
export default class Calendar extends React.Component {
state = {
month: 0,
year: 0,
currentDate: new Date()
}
componentWillMount() {
this.setCurrentYearMonth(this.state.currentDate)
}
setCurrentYearMonth(date) {
var month = Calendar.getMonth(date)
var year = Calendar.getFullYear(date)
this.setState({
month,
year
})
}
static getMonth(date: Date): number{
return date.getMonth()
}
static getFullYear(date: Date): number{
return date.getFullYear()
}
static getCurrentMonthDays(month: number): number {
return MONTH_DAYS[month]
}
static getWeeksByFirstDay(year: number, month: number): number {
var date = Calendar.getDateByYearMonth(year, month)
return date.getDay()
}
static getDayText(line: number, weekIndex: number, weekDay: number, monthDays: number): any {
var number = line * 7 + weekIndex - weekDay + 1
if ( number <= 0 || number > monthDays ) {
return <span> </span>
}
return number
}
static formatNumber(num: number): string {
var _num = num + 1
return _num < 10 ? `0${_num}` : `${_num}`
}
static getDateByYearMonth(year: number, month: number, day: number=1): Date {
var date = new Date()
date.setFullYear(year)
date.setMonth(month, day)
return date
}
checkToday(line: number, weekIndex: number, weekDay: number, monthDays: number): Boolean {
var { year, month } = this.state
var day = Calendar.getDayText(line, weekIndex, weekDay, monthDays)
var date = new Date()
var todayYear = date.getFullYear()
var todayMonth = date.getMonth()
var todayDay = date.getDate()
return year === todayYear && month === todayMonth && day === todayDay
}
monthChange(monthChanged: number) {
var { month, year } = this.state
var monthAfter = month + monthChanged
var date = Calendar.getDateByYearMonth(year, monthAfter)
this.setCurrentYearMonth(date)
}
render() {
var { year, month } = this.state
console.log(this.state)
var monthDays = Calendar.getCurrentMonthDays(month)
var weekDay = Calendar.getWeeksByFirstDay(year, month)
return (<div>
{this.state.month}
<table cellPadding={0} cellSpacing={0} className="table">
<caption>
<div className="caption-header">
<span className="arrow" onClick={this.monthChange.bind(this, -1)}><</span>
<span>{year} - {Calendar.formatNumber(month)}</span>
<span className="arrow" onClick={this.monthChange.bind(this, 1)}>></span>
</div>
</caption>
<thead>
<tr>
{
WEEK_NAMES.map((week, key) => {
return <td key={key}>{week}</td>
})
}
</tr>
</thead>
<tbody>
{
LINES.map((l, key) => {
return <tr key={key}>
{
WEEK_NAMES.map((week, index) => {
return <td key={index} style={{color: this.checkToday(key, index, weekDay, monthDays) ? 'red' : '#000'}}>
{Calendar.getDayText(key, index, weekDay, monthDays)}
</td>
})
}
</tr>
})
}
</tbody>
</table>
</div>)
}
}
https://github.com/LingyuCoder/react-lunar-calendar/blob/master/index.jsx
https://rsuitejs.com/components/calendar
https://github.com/rsuite/rsuite
https://www.cnblogs.com/ajanuw/p/10100320.html
https://github.com/hanse/react-calendar
https://github.com/BelkaLab/react-yearly-calendar
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
React & Calendar的更多相关文章
- React 学习笔记(学习地址汇总)
好的博文地址:http://www.ruanyifeng.com/blog/2015/03/react.html 官网学习地址:http://facebook.github.io/react/docs ...
- react路由深度解析
先看一段代码能否秒懂很重要 这是app.js 全局js的入口 import React from 'react' import { render } from 'react-dom' import ...
- react native 中时间选择插件
npm install react-native-datepicker --save import DatePicker from 'react-native-datepicker'; <Vie ...
- React Router 4.x 开发,这些雷区我们都帮你踩过了
前言 在前端框架层出不穷的今天,React 以其虚拟 DOM .组件化开发思想等特性迅速占据了主流位置,成为前端开发工程师热衷的 Javascript 库.作为 React 体系中的重要组成部分:Re ...
- react学习一篇就够了
webstrom自动格式化代码 命令 js框架 MVC 安装 npm install create-react-app -g 生成项目(项目名npm发包包命名规范 /^[a-z0-9_-]$/) cr ...
- React Router API文档
React Router API文档 一.<BrowserRouter> 使用HTML5历史记录API(pushState,replaceState和popstate事件)的<Rou ...
- Expo大作战(四十)--expo sdk api之 Calendar,Constants
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
- 时间选择控件YearPicker(基于React,antd)
不知道为什么蚂蚁金服团队没有在ant design的DatePicker中单独给出选择年份的组件,这给我们这种懒人造成了很大的痛苦,自己手造轮子是很麻烦的.毕竟只是一个伸手党,emmmmm..... ...
- React半科普文
React半科普文 什么是React getting started 文件分离 Server端编译 定义一个组件 使用property 组件嵌套 组件更新 Virtual DOM react nati ...
随机推荐
- https://www.cs.cmu.edu/~dga/papers/cuckoo-conext2014.pdf 检验hash冲突
https://github.com/google/cityhash We like to test hash functions with SMHasher, among other things. ...
- spring restTemplate 进行http请求的工具类封装
本文为博主原创,未经允许不得转载: 1.对常用调用的方法进行封装: import org.springframework.http.HttpHeaders; import com.alibaba.fa ...
- httpd反向代理实践(一)
div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...
- 《进击吧!Blazor!》第一章 3.页面制作
作者介绍 陈超超Ant Design Blazor 项目贡献者拥有十多年从业经验,长期基于.Net技术栈进行架构与开发产品的工作,Ant Design Blazor 项目贡献者,现就职于正泰集团 写专 ...
- Java调用RestFul接口
使用Java调用RestFul接口,以POST请求为例,以下提供几种方法: 一.通过HttpURLConnection调用 1 public String postRequest(String url ...
- 利用powershell隐藏执行后门
运行后门时,有些后门不能中断.双击运行这种后门会产生一个黑框. 一条命令就能使其在后台执行 命令解释: start-process启动一个进程 -windowstyle窗口样式 hidden隐藏
- 压缩文件 .zip.001 .zip.002合并
可以把名字特别长的命名为1 这样简单些 copy /B 1.zip.001+1.zip.002 1.zip
- python通过注册表准确获得Windows桌面路径(为了一定的通用性)
参考文章:https://blog.csdn.net/u013948858/article/details/75072873 使用python内置的winreg模块,非常方便: import winr ...
- docker部署 springboot 多模块项目+vue
之前学习了docker,今天就来试试将这个项目打包成docker镜像并通过运行一个镜像来运行项目.这里使用的项目是el-admin.是一个开源的springboot后端管理框架(前端vue),有兴趣的 ...
- HDU4787 GRE Words Revenge【AC自动机 分块】
HDU4787 GRE Words Revenge 题意: \(N\)次操作,每次记录一个\(01\)串或者查询一个\(01\)串能匹配多少个记录的串,强制在线 题解: 在线的AC自动机,利用分块来降 ...