plateList.js
17.1 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/**
* Created by Cassie on 2018/03/06
*/
import React, { Component } from 'react';
import {
NativeModules,
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
FlatList,
Animated,
Modal,
StatusBar,
ActivityIndicator,
} from 'react-native';
import VideoPlayer from 'react-native-video-controls';
import {height,zoomW,zoomH} from '../../utils/getSize';
import {getHeaderPadding,xnBorderWidth,xnToast,numChange} from "../../utils/utils";
import AppService from "../../service/AppService";
const isTop = require('../../img/isTop.png');
const cover = require('../../img/cover.png');
const video = require('../../img/video.png');
const top1 = require('../../img/top1.png');
const top2 = require('../../img/top2.png');
const top3 = require('../../img/top3.png');
const back = require('../../img/back_gray.png');
const close = require('../../img/close.png');
const search = require('../../img/search.png');
const more = require('../../img/more.png');
const post = require('../../img/post.png');
const plate = require('../../img/plate.png');
const selected = require('../../img/selected.png');
const defaultIcon = require('../../img/defaultIcon.png');
const Platform = require('Platform');
export default class PlateList extends Component {
static navigationOptions = ({ navigation, screenProps })=>({
title:navigation.state.params.name,
headerLeft:(
<TouchableOpacity style={styles.backWrap} onPress={navigation.state.params?navigation.state.params.back:null}>
<Image source={back} resizeMode="contain" />
</TouchableOpacity>
),
headerRight:(<View style={styles.rightTop}>
<TouchableOpacity style={[styles.rightIcon,{marginRight:(6/zoomW)}]} onPress={() => navigation.state.params?navigation.state.params.toSearch():null}>
<Image source={search} style={styles.searchIcon} resizeMode="contain" />
</TouchableOpacity>
<TouchableOpacity style={styles.rightIcon} onPress={() =>{
navigation.state.params? navigation.state.params.showRight():null
}}>
<Image source={more} style={styles.moreIcon} resizeMode="contain" />
</TouchableOpacity>
</View>)
});
constructor(props) {
super(props);
this.state = {
list:[],
right:new Animated.Value(-(228/zoomW)),
showModal:false,
loading:true,
all:true
};
}
componentWillMount(){
if(this.props.navigation.state.params.fromHome) {
global.go_back_key = this.props.navigation.state.key;
}
this.setState({
title:this.props.navigation.state.params.name,
id:this.props.navigation.state.params.id
});
this.getList('IS_BOARD_TOP',null);
}
componentDidMount(){
let _this=this;
//设置头部
this.props.navigation.setParams({
name:this.props.navigation.state.params.name,
back:()=>{
this.props.navigation.goBack();
},
showRight:()=>{
_this.getPlate();
_this.setState({
showModal:true
},function(){
Animated.timing(
this.state.right,
{toValue:0,duration:200}
).start();
});
},
toSearch:()=>{
this.props.navigation.navigate('Search',{});
}
});
};
/*获取列表*/
getList(type,good){
this.setState({
loading:true
});
AppService.findPostList({boardId:this.props.navigation.state.params.id,sortColumn:type,isGood:good}).then(data=>{
this.setState({
loading:false
});
if(data.message){
xnToast(data.message);
return;
}
if(data.errors.length > 0) {
xnToast(data.errors[0].message);
}else{
this.setState({
list:data.result,
});
}
});
};
/* 渲染列表*/
keyExtractor = (item,index) => index;
/*首页列表*/
renderItem = ({item,index}) => (
<TouchableOpacity activeOpacity={0.8} style={styles.listItem} onPress={() => this.toDetail(item.id)}>
<View style={styles.itemTop}>
{item.isForumTop && <Image source={isTop} style={styles.isTopIcon} resizeMode="contain" />}
<Text numberOfLines={1} style={[styles.itemTitle,{width:item.isForumTop ? (305/zoomW):(345/zoomW)}]}>{item.title}</Text>
</View>
<View style={styles.itemContent}>
{item.imgeAttachmentCount == 1 && item.vedioAttachmentCount == 0 && <Image source={{uri:item.attachmentList[0].filePath+'?x-oss-process=image/resize,w_1000'}} style={styles.coverImg} resizeMode="cover" />}
{item.imgeAttachmentCount > 1 && item.vedioAttachmentCount == 0 && item.attachmentList.map((item,index) => this.renderImg(item,index))}
{item.vedioAttachmentCount == 1 && item.attachmentList.map((item,index) => this.renderVideo(item,index))}
{item.contentText != null && item.contentText.length != 0 && !item.attachmentList && <Text numberOfLines={2} style={styles.contentText}>{item.contentText}</Text>}
</View>
<View style={styles.itemBottom}>
<Text style={{fontSize:14,color:'#999'}}>{numChange(item.postCount)}回复</Text>
<View style={{display:'flex',flexDirection:'row',alignItems:'center'}}>
{item.threadUserAvatarUrl && <Image source={{uri:item.threadUserAvatarUrl+'?x-oss-process=image/resize,w_1000'}} style={styles.avatar} resizeMode="cover" />}
{!item.threadUserAvatarUrl && <Image source={defaultIcon} style={styles.avatar} resizeMode="cover" />}
<Text style={{fontSize:14,color:'#999'}}>{item.threadUserName}·{item.boardName}</Text>
</View>
</View>
</TouchableOpacity>
);
/*渲染图片*/
renderImg(item,index){
return (
<View key={index}>
{index == 0 && <Image source={{uri:item.filePath+'?x-oss-process=image/resize,w_1000'}} style={styles.moreImg} resizeMode="cover" />}
{index == 1 && <Image source={{uri:item.filePath+'?x-oss-process=image/resize,w_1000'}} style={[styles.moreImg,{marginLeft:(6/zoomW),marginRight:(6/zoomW)}]} resizeMode="cover" />}
{index == 2 && <Image source={{uri:item.filePath+'?x-oss-process=image/resize,w_1000'}} style={styles.moreImg} resizeMode="cover" />}
</View>
)
};
/*渲染视频*/
renderVideo(item,index){
return (
item.businessCategory == 'VEDIO' ? <View key={index} style={{width:(345/zoomW),height:(193/zoomW)}}>
<VideoPlayer paused={true} showOnStart={true} disableFullscreen={true} disablePlayPause={true} disableSeekbar={true} disableVolume={true} disableTimer={true} disableBack={true} style={{width:(345/zoomW),height:(193/zoomW)}} videoStyle={{width:(345/zoomW),height:(193/zoomW)}} source={{uri:item.filePath}}/>
<View style={{width:'100%',height:'100%',position:'absolute',top:0}} />
</View>:null
)
};
/*获取论坛列表*/
getPlate(){
AppService.findBoardList({forumId:global.forumId}).then(data=>{
if(data.message){
xnToast(data.message);
return;
}
if(data.errors.length > 0) {
xnToast(data.errors[0].message);
}else{
this.setState({
plateList:data.result
});
}
})
};
renderPlate(item,index){
return(
<TouchableOpacity key={index} activeOpacity={0.5} style={styles.plateItem} onPress={() => this.toPlate(item.name,item.id)}>
<Text style={{fontSize:16,color:this.state.title == item.name?'#39f':'#000'}}>{item.name}</Text>
{this.state.title == item.name && <Image source={selected} resizeMode="contain" />}
</TouchableOpacity>
)
};
/*右侧菜单栏关闭*/
closeRight(){
this.setState({
right:new Animated.Value(-(228/zoomW)),
},function(){
this.setState({
showModal:false,
})
});
};
/*跳转到发帖*/
toPost(){
this.props.navigation.navigate('Post',{name:this.state.title,id:this.state.id});
this.closeRight();
};
/*跳转到板块*/
toPlate(name,id){
this.props.navigation.navigate('PlateList',{name:name,id:id});
this.closeRight();
};
/*全部与精华切换*/
select(type){
if(type == 'All'){
this.setState({
all:true
});
this.getList('IS_BOARD_TOP',null)
}else if(type == 'Good'){
this.setState({
all:false
});
this.getList('IS_BOARD_TOP',true)
}
};
/*跳转到详情*/
toDetail(id){
// AppService.updateView({id:id}).then((data) => {
// if(!data.message && data.errors.length == 0){
this.props.navigation.navigate('Detail',{id:id})
// }
// })
};
/*跳转到首页*/
toHome(){
this.props.navigation.goBack(global.go_back_key);
this.closeRight();
}
render() {
return (
<View style={styles.background}>
<StatusBar barStyle="default" />
<View style={styles.topTab}>
<TouchableOpacity style={[styles.barItem,{borderBottomWidth:this.state.all ? 2:0}]} onPress={() => this.select('All')}>
<Text style={{fontSize:16,color:this.state.all ? '#000':'#666'}}>全部</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.barItem,{borderBottomWidth:this.state.all ? 0:2}]} onPress={() => this.select('Good')}>
<Text style={{fontSize:16,color:this.state.all ? '#666':'#000'}}>精华</Text>
</TouchableOpacity>
</View>
<FlatList keyExtractor={this.keyExtractor} data={this.state.list} renderItem={this.renderItem} />
{/*右侧更多*/}
<Modal animationType={'none'} transparent={true} visible={this.state.showModal} onRequestClose={() => {}}>
<View style={styles.modalBg}>
<TouchableOpacity style={{flex:1}} onPress={() => this.closeRight()}>
<Animated.View style={[styles.rightMenu,{right:this.state.right}]}>
{/*onPress={() => {this.toPost()}}*/}
{/*<TouchableOpacity activeOpacity={1} style={styles.post} onPress={() => {this.toPost()}}>*/}
{/*<View style={{flex:1}}>*/}
{/*<Image source={post} style={styles.menuTip} resizeMode="contain" />*/}
{/*</View>*/}
{/*<View style={{flex:5}}>*/}
{/*<Text style={{color:'#000',fontSize:16}}>发帖</Text>*/}
{/*</View>*/}
{/*</TouchableOpacity>*/}
<View style={[styles.platBox,{ paddingTop: getHeaderPadding() + 15 / zoomH }]}>
<View style={{ flexDirection: 'row', alignItems: 'center', paddingBottom: 14 / zoomH }}>
<View style={{flex:1}}>
<Image source={plate} style={styles.menuTip} resizeMode="contain" />
</View>
<View style={{flex:5}}>
<Text style={{color:'#000',fontSize:16}}>板块</Text>
</View>
</View>
<View style={{ flexDirection: 'row' }}>
<View style={{flex:1}}></View>
<View style={{flex:5}}>
<TouchableOpacity activeOpacity={0.5} style={styles.plateItem} onPress={() => this.toHome()}>
<Text style={{fontSize:16,color:'#000'}}>首页</Text>
</TouchableOpacity>
{this.state.plateList && this.state.plateList.map((item,index) => this.renderPlate(item,index))}
</View>
</View>
</View>
</Animated.View>
</TouchableOpacity>
</View>
</Modal>
{this.state.loading && <View style={styles.loadingBg}>
<ActivityIndicator size="large" />
</View>}
</View>
);
}
}
const styles = StyleSheet.create({
backWrap: {
justifyContent: 'center',
paddingLeft: 15 / zoomW,
paddingRight: 15 / zoomW,
height: 44 / zoomH,
},
leftIcon:{
width:(50/zoomW),
height:'100%',
display:'flex',
flexDirection:'row',
alignItems:'center'
},
backIcon:{
width:(16/zoomW),
height:(16/zoomH),
marginLeft:(10/zoomW)
},
closeIcon:{
width:(16/zoomW),
height:(16/zoomH)
},
rightTop:{
flex:1,
display:'flex',
flexDirection:'row',
justifyContent:'center',
alignItems:'center',
paddingRight:(12/zoomW)
},
rightIcon:{
height:'100%',
width:(40/zoomW),
display:'flex',
justifyContent:'center',
alignItems:'center'
},
searchIcon:{
width:(20/zoomW),
height:(20/zoomW)
},
moreIcon:{
width:(20/zoomW),
height:(20/zoomW)
},
background:{
width:'100%',
height:'100%',
backgroundColor:'#f2f2f2'
},
topTab:{
width:'100%',
height:(44/zoomH),
borderBottomWidth:xnBorderWidth(),
borderBottomColor:'#eee',
borderStyle:'solid',
backgroundColor:'#fff',
paddingLeft:(22/zoomW),
display:'flex',
flexDirection:'row'
},
barItem:{
width:(68/zoomW),
height:(44/zoomH),
display:'flex',
justifyContent:'center',
alignItems:'center',
borderBottomColor:'#333',
borderStyle:'solid',
},
listItem:{
minHeight:(110/zoomH),
maxHeight:(318/zoomH),
backgroundColor:'#fff',
marginBottom:(8/zoomH),
padding:(15/zoomH),
},
itemTop:{
width:(345/zoomW),
display:'flex',
flexDirection:'row',
alignItems:'center'
},
itemTitle:{
color:'#000',
fontSize:16,
fontWeight:'600'
},
isTopIcon:{
width:(40/zoomW),
},
topNumIcon:{
width:(40/zoomW),
marginRight:10,
marginTop:(2/zoomH)
},
coverImg:{
width:(345/zoomW),
height:(193/zoomH)
},
moreImg:{
width:(112/zoomW),
height:(112/zoomW)
},
itemContent:{
display:'flex',
flexDirection:'row',
marginTop:(15/zoomH),
marginBottom:(15/zoomH)
},
contentText:{
fontSize:14,
color:'#666'
},
itemBottom:{
display:'flex',
flexDirection:'row',
justifyContent:'space-between'
},
avatar:{
width:(20/zoomW),
height:(20/zoomW),
borderRadius:(10/zoomW),
marginRight:(6/zoomW)
},
modalBg:{
width:'100%',
height:'100%',
backgroundColor:'rgba(0,0,0,.5)'
},
rightMenu:{
width:(228/zoomW),
height:height,
backgroundColor:'#fff',
position:'absolute',
right:0,
paddingLeft:(20/zoomW)
},
post:{
width:'100%',
height:(90/zoomH),
borderBottomWidth:xnBorderWidth(),
borderBottomColor:'#eee',
borderStyle:'solid',
display:'flex',
flexDirection:'row',
alignItems:'center'
},
menuTip:{
width:(20/zoomW),
height:(20/zoomW),
marginRight:(10/zoomW),
},
platBox:{
width:'100%',
display:'flex',
},
plateItem:{
width:'100%',
paddingTop:(14/zoomH),
paddingBottom:(14/zoomH),
display:'flex',
flexDirection:'row',
alignItems:'center',
justifyContent:'space-between',
paddingRight:(22/zoomW)
},
loadingBg:{
width:'100%',
height:'100%',
position:'absolute',
display:'flex',
alignItems:'center',
justifyContent:'center'
}
});