/
index.js
193 lines (185 loc) · 4.98 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import React from 'react'
import Shuffle from 'shufflejs'
import CustomBreadcrumb from '../../../components/CustomBreadcrumb/index'
import TypingCard from '../../../components/TypingCard'
import {Card,Button,Modal,BackTop} from 'antd'
class GalleryDemo extends React.Component{
state = {
image:'',
visible:false,
photos : [
{
groups:['nature'],
style:'itemOne',
size:'1x1',
src:require('./img/01.jpeg')
},
{
groups:['nature'],
style:'itemOne',
size:'1x1',
src:require('./img/02.jpeg')
},
{
groups:['nature'],
style:'itemOne',
size:'1x1',
src:require('./img/03.jpeg')
},
{
groups:['scenery'],
style:'itemOne',
size:'1x1',
src:require('./img/04.jpeg')
},
{
groups:['scenery'],
style:'itemTwoRow',
size:'1x2',
src:require('./img/05.jpeg')
},
{
groups:['nature'],
style:'itemOne',
size:'1x1',
src:require('./img/06.jpeg')
},
{
groups:['nature','scenery'],
style:'itemTwoCol',
size:'2x1',
src:require('./img/07.jpeg')
},
{
groups:['other'],
style:'itemOne',
size:'1x1',
src:require('./img/08.jpeg')
},
{
groups:['other'],
style:'itemOne',
size:'1x1',
src:require('./img/09.jpeg')
},
{
groups:['nature'],
style:'itemOne',
size:'1x1',
src:require('./img/10.jpeg')
},
{
groups:['other'],
style:'itemOne',
size:'1x1',
src:require('./img/11.jpeg')
},
{
groups:['other','scenery'],
style:'itemOne',
size:'1x1',
src:require('./img/12.jpeg')
},
]
}
componentDidMount(){
this.shuffle = new Shuffle(this.shuffleDemo, {
itemSelector: '.photo-item',
sizer: this.sizer,
});
}
componentDidUpdate() {
// this.shuffle.resetItems();
}
componentWillUnmount() {
this.shuffle.destroy();
this.shuffle = null;
}
_whenPhotosLoaded(photos) {
return Promise.all(photos.map(photo => new Promise((resolve) => {
const image = document.createElement('img');
image.src = photo.src;
if (image.naturalWidth > 0 || image.complete) {
resolve(photo);
} else {
image.onload = () => {
resolve(photo);
};
}
})));
}
showImg = (src)=>{
this.setState({
visible:true,
image:src
})
}
render(){
const cardContent = `<ul class='card-ul'}>
<li>快速 - 在初始化,排序或过滤器上只有一个强制同步布局(又称回流</li>
<li>回应(尝试调整窗口大小!)</li>
<li>按组过滤项目</li>
<li>项目可以有多个组,大小不同</li>
<li>排序项目</li>
<li>高级过滤(如搜索)</li>
</ul>`
return (
<div>
<CustomBreadcrumb arr={['其它','画廊']}/>
<TypingCard title='shufflejs插件' source={cardContent} height={290}/>
<Card bordered={false}>
<Button style={{marginRight:20}} onClick={()=>this.shuffle.filter()}>全部</Button>
<Button style={{marginRight:20}} onClick={()=>this.shuffle.filter('scenery')}>风景</Button>
<Button style={{marginRight:20}} onClick={()=>this.shuffle.filter('nature')}>自然</Button>
<Button style={{marginRight:20}} onClick={()=>this.shuffle.filter('other')}>其他</Button>
</Card>
<div style={{padding: '20px 32px',minHeight:500}}>
<div ref={(div)=>this.shuffleDemo=div}>
{
this.state.photos.map((item,index)=>(
<div
className='photo-item'
data-groups={JSON.stringify(item.groups)}
onClick={()=>this.showImg(item.src)}
style={styles[item.style]} key={item.src}>
<div className={'aspect aspect--'+item.size}>
<div className='aspect__inner'>
<img src={item.src} alt="" width='100%' height='100%'/>
</div>
</div>
</div>
))
}
<div style={{width:'8.33333%'}} ref={(div)=>this.sizer = div}/>
</div>
</div>
<Modal
footer={null} closable={false}
visible={this.state.visible}
wrapClassName="vertical-center-modal"
onCancel={()=>this.setState({visible:false})}>
<img src={this.state.image} alt="" width='100%'/>
</Modal>
<BackTop visibilityHeight={200} style={{right: 50}}/>
</div>
)
}
}
const styles = {
itemOne:{
width:'25%',
marginBottom:8,
padding:'0 4px'
},
itemTwoCol:{
width:'50%',
marginBottom:8,
padding:'0 4px'
},
itemTwoRow:{
width:'25%',
marginBottom:8,
padding:'0 4px'
}
}
export default GalleryDemo