Skip to content

Commit a5eb470

Browse files
author
lishangxi
committed
fix bug 🐛
1 parent 9faf385 commit a5eb470

File tree

19 files changed

+1040
-25
lines changed

19 files changed

+1040
-25
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"normalizr": "^2.0.0",
7373
"postcss": "^5.2.16",
7474
"random-string": "^0.1.2",
75+
"rc-lightbox": "^2.1.9",
7576
"rc-tween-one": "^0.11.9",
7677
"react": "^15.4.2",
7778
"react-addons-css-transition-group": "^15.3.1",

src/components/App.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ export default class App extends Component{
1313
};
1414
}
1515
componentDidMount(){
16-
this.welcomeLab()
16+
if(window.localStorage){
17+
if(!localStorage.welcome_react_lab){
18+
this.welcomeLab()
19+
localStorage.setItem('welcome_react_lab',true)
20+
}
21+
}
1722
}
1823
welcomeLab() {
1924
Modal.info({
2025
title: '来自世界最友好的提示',
2126
content: (
2227
<div>
23-
<p>这是一个react 组件实验室平台,这个平台集成了React 、ES2015、 Babel、Ant.design 。你可以在平台随意写你的react代码,而不用担心环境配置问题。</p>
28+
<p>这是一个react 组件实验平台,这个平台集成了React 、ES2015、 Babel、Ant.design 。你可以在平台随意写你的react代码,而不用担心环境配置问题。</p>
2429
</div>
2530
),
2631
onOk() {},

src/components/Calendar/Month.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { findDOMNode } from 'react-dom'
33

44
import './index.less'
55

6-
7-
86
export default class Calendar extends Component{
97

108
constructor(props, context) {
@@ -19,11 +17,6 @@ export default class Calendar extends Component{
1917

2018
}
2119

22-
handleClickCell(date){
23-
const d = new Date(date.date)
24-
console.log(`${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`)
25-
}
26-
2720
renderMonthTd(){
2821
//以当前月的第一天为参考点,利用setDate()获取日期
2922
//setDate()会自动转化日期,传入负值,获取上个月的日期,传入超过本月的天数,获取下一个月的日期
@@ -58,7 +51,7 @@ export default class Calendar extends Component{
5851
tdArr.push(
5952
<td
6053
style={ num < 0 || num === 0 || (num > totalDays) ? { background:'#eee'} : null}
61-
onClick={ this.handleClickCell.bind(this,{date}) }
54+
onClick={ this.props.handleClickCell.bind(this,{date}) }
6255
>
6356
{ (date.getMonth() === mm) && date.getDate() === dd ? <span className="day current-day">{ date.getDate() }</span> : <span className="day">{date.getDate()}</span> }
6457
</td>

src/components/Calendar/Week.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,22 @@ export default class CalendarWeek extends Component{
3434
const yy = d.getFullYear()
3535
const mm = d.getMonth()
3636
const dd = d.getDate()
37+
3738
const weekStr = '一二三四五六日'
3839
// const {yy,mm,dd} = this.state
3940
//获取当前是周几
40-
let firstDayWeek = new Date(yy,mm,dd).getDay()
41-
firstDayWeek = firstDayWeek === 0 ? 7 : firstDayWeek
41+
let curDayWeek = new Date(yy,mm,dd).getDay()
42+
curDayWeek = curDayWeek === 0 ? 7 : curDayWeek
4243
const tdArr = []
4344

4445
for(let j=1;j<=7;j++){
45-
let date = new Date(yy,mm,dd-firstDayWeek+j)
46+
let date = new Date(yy,mm,dd-curDayWeek+j)
4647
tdArr.push(
47-
<th>{`周${weekStr[j-1]}/${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`}</th>
48+
<th>
49+
<span className={curDayWeek === j ? 'current-week' : null}>
50+
{`周${weekStr[j-1]}/${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`}
51+
</span>
52+
</th>
4853
)
4954
}
5055

src/components/Calendar/index.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class Calendar extends Component{
3434
if(selected === 'month'){
3535
this.setState(
3636
{
37-
mm: dir === 2 ? mm+1 : m-1
37+
mm: dir === 2 ? mm+1 : mm-1
3838
}
3939
)
4040
}else if(selected === 'week'){
@@ -60,7 +60,7 @@ export default class Calendar extends Component{
6060
if(selected === 'month'){
6161
return (
6262
<div className="fc-view fc-month-view fc-basic-view">
63-
<CalendarMonth date={date} />
63+
<CalendarMonth date={date} handleClickCell={this.handleClickCell} />
6464
</div>
6565
)
6666
}else if(selected === 'week'){
@@ -80,6 +80,16 @@ export default class Calendar extends Component{
8080
selected:mode
8181
})
8282
}
83+
84+
handleClickCell=(date)=>{
85+
const d = new Date(date.date)
86+
if(d.getMonth()+1 !== this.state.mm+1){
87+
this.setState({
88+
mm:d.getMonth(),
89+
})
90+
}
91+
console.log(`${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`)
92+
}
8393
renderTit(){
8494
const {yy,mm,dd,selected} = this.state
8595

@@ -89,10 +99,10 @@ export default class Calendar extends Component{
8999
<h2>{ date.getFullYear() }{ date.getMonth()+1}</h2>
90100
)
91101
}else if(selected === 'week'){
92-
let firstDayWeek = new Date(yy,mm,dd).getDay()
93-
firstDayWeek = firstDayWeek === 0 ? 7 : firstDayWeek
94-
const begin = new Date(yy,mm,dd-firstDayWeek+1)
95-
const end = new Date(yy,mm,dd-firstDayWeek+7)
102+
let curDayWeek = new Date(yy,mm,dd).getDay()
103+
curDayWeek = curDayWeek === 0 ? 7 : curDayWeek
104+
const begin = new Date(yy,mm,dd-curDayWeek+1)
105+
const end = new Date(yy,mm,dd-curDayWeek+7)
96106

97107
return (
98108
<h2>
@@ -108,15 +118,12 @@ export default class Calendar extends Component{
108118
handleClickToday=()=>{
109119
const date = new Date()
110120
this.setState({
111-
yy:date.getFullYear(),
121+
//不要设置dd
112122
mm:date.getMonth(),
113-
dd:date.getDate(),
114123
})
115124
}
116125
render() {
117-
const {yy,mm,dd,selected} = this.state
118-
const date = new Date(yy,mm,dd)
119-
126+
const {selected} = this.state
120127
return (
121128
<div className="fc fc-unthemed fc-ltr">
122129
<div className="fc-toolbar fc-header-toolbar">

src/components/Calendar/index.less

+6
Original file line numberDiff line numberDiff line change
@@ -908,4 +908,10 @@ a.fc-more:hover {
908908
top:10px;
909909
font-size: 14px;
910910
}
911+
.current-week{
912+
display: block;
913+
font-size: 20px;
914+
font-weight: 700;
915+
color:#108ee9;
916+
}
911917
}

src/components/LightBox2/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default class Lightbox2 extends Component{
5353
}
5454

5555
closeLightBox=()=>{
56+
console.log('关闭')
5657
this.setState({
5758
lightboxIsOpen:false
5859
})

src/components/rc-lightbox/README.gif

6.43 MB
Loading

src/components/rc-lightbox/README.md

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
### This is an excellent lightbox. It is modeled on the jQuery version of the lightbox2. It has a great user experience. :100:
2+
## 安装 :rocket:
3+
`npm install rc-lightbox --save`
4+
5+
> tips: 如果你的项目中没有安装 `rc-tween-one` 需要安装一下。
6+
## 用法
7+
8+
`import Lightbox from 'rc-lightbox'`
9+
```
10+
<Lightbox
11+
imgSource={this.state.lightboxImgData}
12+
isOpen={this.state.lightboxIsOpen}
13+
currentImage = {this.state.currentImage}
14+
onClose={this.closeLightBox}
15+
/>
16+
```
17+
### 参数说明 :art:
18+
属性|类型|默认值|说明
19+
-|-|-|-
20+
isOpen|布尔值{Boolean}|false|设置lightbox的状态
21+
imgSource|数组{Array}|[]| [{src:'http://'}]
22+
currentImage|布尔值{Number}|0 | 当前第几张图片
23+
onClose|函数{Function}|-|关闭lightbox
24+
25+
#### 示例代码 :tada:
26+
```
27+
import React, { Component, PropTypes } from 'react'
28+
import { findDOMNode } from 'react-dom'
29+
import Lightbox from 'rc-lightbox'
30+
31+
32+
const MockData = [{
33+
src:'./src/images/01.jpg',
34+
title:'图片1',
35+
},{
36+
src:'./src/images/02.jpg',
37+
title:'图片2',
38+
},{
39+
src:'https://gss0.bdstatic.com/5eR1dDebRNRTm2_p8IuM_a/res/r/image/2016-09-02/9577e9be05aea818907880ac66bdf4a0.jpg'
40+
},{
41+
src:'https://gss0.bdstatic.com/5eR1dDebRNRTm2_p8IuM_a/res/r/image/2016-09-02/177e848bf4f0df538576f5422029c3e6.jpg'
42+
}]
43+
44+
const MockData2 = [{
45+
src:'http://www.people.com.cn/NMediaFile/2016/0902/MAIN201609021911314859050338728.jpg',
46+
title:'图片1',
47+
},{
48+
src:'http://www.people.com.cn/NMediaFile/2016/0902/MAIN201609021348521914980960649.jpg',
49+
title:'图片2',
50+
},{
51+
src:'https://gss0.bdstatic.com/5eR1dDebRNRTm2_p8IuM_a/res/r/image/2016-09-02/9577e9be05aea818907880ac66bdf4a0.jpg'
52+
},{
53+
src:'https://gss0.bdstatic.com/5eR1dDebRNRTm2_p8IuM_a/res/r/image/2016-09-02/177e848bf4f0df538576f5422029c3e6.jpg'
54+
},{
55+
src:'http://www.wallcoo.com/animal/v195_Lively_Dogs/wallpapers/1280x800/Lively_Dogs_wallpaper_MIX88041_wallcoo.com.jpg'
56+
},{
57+
src:'http://www.wallcoo.com/animal/v195_Lively_Dogs/wallpapers/1280x800/Lively_Dogs_wallpaper_MIX88041_wallcoo.com2.jpg'
58+
}]
59+
60+
61+
62+
export default class Lightbox2 extends Component{
63+
64+
constructor(props, context) {
65+
super(props, context)
66+
this.state = {
67+
lightboxImgData:[],
68+
lightboxIsOpen:false,
69+
currentImage:0,
70+
71+
}
72+
}
73+
74+
componentDidMount = ()=>{
75+
76+
//findDOMNode().appendChild('<div></div>')
77+
//document.body.appendChild(findDOMNode(this.refs.mask))
78+
}
79+
80+
closeLightBox=()=>{
81+
this.setState({
82+
lightboxIsOpen:false
83+
})
84+
}
85+
86+
showPicModal(imgGrounp){
87+
this.setState({
88+
lightboxIsOpen:true,
89+
currentImage:imgGrounp.index || 0,
90+
lightboxImgData:imgGrounp.imgs,
91+
})
92+
}
93+
94+
renderImgList = (data)=>{
95+
return (
96+
data.map((item,index)=>{
97+
return (
98+
<li
99+
style={{
100+
WebkitTransform: `opacity:${x}`,
101+
transform: `opacity:${x}`,
102+
}}
103+
key={`img_${index}`}
104+
onClick={this.showPicModal.bind(this,{imgs:data,index})}
105+
>
106+
<img src={item.src} />
107+
</li>
108+
)
109+
})
110+
)
111+
}
112+
113+
114+
115+
render() {
116+
117+
118+
return (
119+
<div className="self-calendar">
120+
<button
121+
onMouseDown={this.handleMouseDown}
122+
onTouchStart={this.handleTouchStart}>
123+
Toggle
124+
</button>
125+
<ul className="img-list clearfix">
126+
{ this.renderImgList(MockData) }
127+
</ul>
128+
<h2>第二组图片</h2>
129+
<ul className="img-list clearfix">
130+
{ this.renderImgList(MockData) }
131+
</ul>
132+
<h2>第三组图片</h2>
133+
<ul className="img-list clearfix">
134+
{ this.renderImgList(MockData2) }
135+
</ul>
136+
137+
{
138+
this.state.lightboxImgData.length?
139+
<Lightbox
140+
imgSource={this.state.lightboxImgData}
141+
isOpen={this.state.lightboxIsOpen}
142+
currentImage = {this.state.currentImage}
143+
onClose={this.closeLightBox}
144+
/> : null
145+
}
146+
147+
148+
</div>
149+
);
150+
}
151+
}
152+
```
153+
#### DEMO
154+
155+
![演示demo](https://github.com/leesx/rc-lightbox/blob/master/README.gif)

0 commit comments

Comments
 (0)