|
@@ -32,57 +32,101 @@ import MySwiper from "./Swiper";
|
|
|
import Dimensions from '../utils/dimensions';
|
|
|
import TopicTitle from './TopicTitle';
|
|
|
import ScrollRow from "./ScrollRow";
|
|
|
-// import console from 'console';
|
|
|
+import LibraryUrl from '../services/library'
|
|
|
+import { ScrollView } from "react-native-gesture-handler";
|
|
|
|
|
|
export default class MainPage extends BasePage {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
}
|
|
|
|
|
|
+ componentDidMount() {
|
|
|
+ LibraryUrl.getIndex('PRESCHOOL').success(res => {
|
|
|
+ console.log(res)
|
|
|
+ const monthTopicTitle = res.data.monthTopic.zone.title;
|
|
|
+ const monthTopicScroll = res.data.monthTopic.zoneCourseVOList;
|
|
|
+ const schedule = res.data.schedule;
|
|
|
+ const hotCourse = res.data.hotCourse;
|
|
|
+ const recommend = res.data.recommend; //全部课程
|
|
|
+ const banner = res.data.banner; //轮播图
|
|
|
+ // const listData = [];
|
|
|
+ // for(let item in res.data){
|
|
|
+ // console.log(item)
|
|
|
+ // listData.push(1)
|
|
|
+ // }
|
|
|
+ // console.log(typeof listData)
|
|
|
+ // console.log(listData)
|
|
|
+ // console.log(listData.length)
|
|
|
+ this.setState({
|
|
|
+ // listData: listData.length? listData : [],
|
|
|
+ hotCourse,
|
|
|
+ monthTopicTitle,
|
|
|
+ monthTopicScroll,
|
|
|
+ schedule,
|
|
|
+ recommend,
|
|
|
+ banner
|
|
|
+ })
|
|
|
+ console.log(this.state.banner)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
state = {
|
|
|
grade: '大学',
|
|
|
text: '小伙子',
|
|
|
ifGradeMenuShow: false,
|
|
|
fadeAnim: new Animated.Value(0),
|
|
|
+ schedule: [],
|
|
|
+ recommend: [],
|
|
|
+ listData: [],
|
|
|
+ banner:[]
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
+ // const abc =Object.keys(this.state.data).map((k)=>this.state.data[k])
|
|
|
return (
|
|
|
- <View style={{ flex: 1 }} onPress={this.hideGradeMenu}>
|
|
|
- {/* 尝试切换为sectionList 分组显示 */}
|
|
|
- <SectionList
|
|
|
- sections={sectionData}
|
|
|
- renderItem={({ item }) => {
|
|
|
- return this.loadFlatItem(item);
|
|
|
- }}
|
|
|
- keyExtractor={(item, index) => item.key.toString()}
|
|
|
- ListHeaderComponent={() => this.headerorfooterComponent()}
|
|
|
- renderSectionHeader={this.sectionTitle}
|
|
|
- onScroll={this.hideGradeMenu}
|
|
|
- />
|
|
|
- {
|
|
|
- this.state.ifGradeMenuShow ? (
|
|
|
- <Animated.View
|
|
|
- style={{
|
|
|
- ...styles.callUpGrade,
|
|
|
- opacity: this.state.fadeAnim
|
|
|
- }}>
|
|
|
- <View style={styles.gradeItem}>
|
|
|
- <Text style={styles.gradeText}>小学</Text>
|
|
|
- </View>
|
|
|
- <View style={styles.gradeItemMid}>
|
|
|
- <Text style={styles.gradeText}>学前</Text>
|
|
|
- </View>
|
|
|
- <View style={styles.gradeItem}>
|
|
|
- <Text style={styles.gradeText}>中学</Text>
|
|
|
- </View>
|
|
|
- </Animated.View>
|
|
|
- ) : (
|
|
|
- null
|
|
|
- )
|
|
|
+ <View style={{ flex: 1 }} onPress={this.hideGradeMenu}>
|
|
|
+ {/* <SectionList sectionList组件 性能好 但是针对当前布局是否有要用的必要,以后可能迭代
|
|
|
+ sections={this.state.listData}
|
|
|
+ renderItem={({ item }) => {
|
|
|
+ return this.loadFlatItem(item);
|
|
|
+ }}
|
|
|
+ keyExtractor={(item, index) => item.key.toString()}
|
|
|
+ ListHeaderComponent={() => this.headerorfooterComponent()}
|
|
|
+ renderSectionHeader={this.sectionTitle}
|
|
|
+ onScroll={this.hideGradeMenu}
|
|
|
+ /> */}
|
|
|
+ <ScrollView style={{ height: Dimensions.height }} >
|
|
|
+ {this.headerorfooterComponent()}
|
|
|
+ {this.getSwiperElement()}
|
|
|
+ {this.getScheduleElement()}
|
|
|
+ {this.getMonthTopic()}
|
|
|
+ {this.getHotCourse()}
|
|
|
+ {this.getAllCourses()}
|
|
|
+ </ScrollView>
|
|
|
|
|
|
- }
|
|
|
- </View>
|
|
|
+ {
|
|
|
+ this.state.ifGradeMenuShow ? (
|
|
|
+ <Animated.View
|
|
|
+ style={{
|
|
|
+ ...styles.callUpGrade,
|
|
|
+ opacity: this.state.fadeAnim
|
|
|
+ }}>
|
|
|
+ <View style={styles.gradeItem}>
|
|
|
+ <Text style={styles.gradeText}>小学</Text>
|
|
|
+ </View>
|
|
|
+ <View style={styles.gradeItemMid}>
|
|
|
+ <Text style={styles.gradeText}>学前</Text>
|
|
|
+ </View>
|
|
|
+ <View style={styles.gradeItem}>
|
|
|
+ <Text style={styles.gradeText}>中学</Text>
|
|
|
+ </View>
|
|
|
+ </Animated.View>
|
|
|
+ ) : (
|
|
|
+ null
|
|
|
+ )
|
|
|
+
|
|
|
+ }
|
|
|
+ </View>
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -128,7 +172,6 @@ export default class MainPage extends BasePage {
|
|
|
}
|
|
|
// 渲染轮播图
|
|
|
getSwiperElement() {
|
|
|
- console.log('进入swiper')
|
|
|
return (
|
|
|
<View
|
|
|
style={{
|
|
@@ -137,12 +180,10 @@ export default class MainPage extends BasePage {
|
|
|
justifyContent: "center",
|
|
|
alignItems: "center",
|
|
|
flexDirection: "row",
|
|
|
- // backgroundColor: 'red'
|
|
|
}}
|
|
|
>
|
|
|
<View
|
|
|
style={{
|
|
|
- // width: Dimensions.width,
|
|
|
width: Dimensions.getWidth(358),
|
|
|
height: Dimensions.getDp(153),
|
|
|
justifyContent: "center",
|
|
@@ -153,17 +194,16 @@ export default class MainPage extends BasePage {
|
|
|
autoplay={true}
|
|
|
loop={true}
|
|
|
ifShowMiddle={true}
|
|
|
+ data={this.state.banner}
|
|
|
/>
|
|
|
</View>
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
// 渲染课程表
|
|
|
- getScheduleElement(data) {
|
|
|
- let arr = [];
|
|
|
- let index = 0;
|
|
|
- for (let item of data.item.icon_item) {
|
|
|
- arr.push(
|
|
|
+ getScheduleElement() {
|
|
|
+ let renderScheduleItem = (item, index) => {
|
|
|
+ return (
|
|
|
<TouchableOpacity
|
|
|
style={{ width: 172, height: 86, marginRight: 12 }}
|
|
|
onPress={() => {
|
|
@@ -174,7 +214,7 @@ export default class MainPage extends BasePage {
|
|
|
>
|
|
|
<Image
|
|
|
source={{
|
|
|
- uri: item.icon
|
|
|
+ uri: item.boothContent
|
|
|
}}
|
|
|
key={index}
|
|
|
style={{
|
|
@@ -186,18 +226,7 @@ export default class MainPage extends BasePage {
|
|
|
}}
|
|
|
/>
|
|
|
</TouchableOpacity>
|
|
|
- );
|
|
|
- if (index < data.item.icon_item.length - 1) {
|
|
|
- arr.push(
|
|
|
- <View
|
|
|
- key={item.name}
|
|
|
- style={{
|
|
|
- flex: 0.1
|
|
|
- }}
|
|
|
- />
|
|
|
- );
|
|
|
- }
|
|
|
- index++;
|
|
|
+ )
|
|
|
}
|
|
|
return (
|
|
|
<View
|
|
@@ -205,7 +234,6 @@ export default class MainPage extends BasePage {
|
|
|
flex: 1,
|
|
|
flexDirection: "column",
|
|
|
height: 160,
|
|
|
- // backgroundColor: 'blue'
|
|
|
}}
|
|
|
>
|
|
|
<TopicTitle title={'课程表:第一周'} ifTubeShow={true} />
|
|
@@ -213,78 +241,101 @@ export default class MainPage extends BasePage {
|
|
|
style={{
|
|
|
flex: 2,
|
|
|
flexDirection: "row",
|
|
|
- // backgroundColor: 'green',
|
|
|
alignItems: 'center',
|
|
|
paddingLeft: 10
|
|
|
}}
|
|
|
>
|
|
|
- {arr}
|
|
|
+ {this.state.schedule.map((item, index) => renderScheduleItem(item, index))}
|
|
|
</View>
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
- // 渲染每一个块儿
|
|
|
+ // 渲染月主题
|
|
|
+ getMonthTopic() {
|
|
|
+ return (
|
|
|
+ <View style={{
|
|
|
+ flex: 1,
|
|
|
+ height: 225,
|
|
|
+ }}>
|
|
|
+ <TopicTitle title={this.state.monthTopicTitle} summary={'每天30分钟'} ifTubeShow={true} />
|
|
|
+ <ScrollRow itemWidth={352} itemHeight={153} data={this.state.monthTopicScroll} />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // 渲染热门课程
|
|
|
+ getHotCourse() {
|
|
|
+ return (
|
|
|
+ <View style={{
|
|
|
+ flex: 1,
|
|
|
+ height: 220,
|
|
|
+ }}>
|
|
|
+ <TopicTitle title={'热门课程'} ifTubeShow={true} />
|
|
|
+ <ScrollRow itemWidth={106} itemHeight={150} data={this.state.hotCourse} />
|
|
|
+ </View>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ // 渲染全部课程
|
|
|
+ getAllCourses() {
|
|
|
+ return (
|
|
|
+ <View>
|
|
|
+ {this.state.recommend.map((item, index) => {
|
|
|
+ return (
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flex: 1,
|
|
|
+ height: 240,
|
|
|
+ }}
|
|
|
+ key={index}
|
|
|
+ >
|
|
|
+ {index === 0
|
|
|
+ ?
|
|
|
+ null
|
|
|
+ :
|
|
|
+ <View style={{ width: Dimensions.width, height: 4, backgroundColor: '#f0f1f5' }}></View>
|
|
|
+ }
|
|
|
+ <TopicTitle title={item.zone.title} />
|
|
|
+ <ScrollRow itemWidth={106} itemHeight={150} data={item.zoneCourseVOList} />
|
|
|
+ </View>
|
|
|
+ )
|
|
|
+ })}
|
|
|
+ </View>
|
|
|
+
|
|
|
+
|
|
|
+ )
|
|
|
+ }
|
|
|
+ // 渲染每一个块儿 sectionList组件的data,没有用到,以后可能会用
|
|
|
loadFlatItem(data) {
|
|
|
- console.log(data)
|
|
|
- console.log(data.typea)
|
|
|
- switch (data.typea) {
|
|
|
+
|
|
|
+
|
|
|
+ switch (data.title) {
|
|
|
// 轮播图
|
|
|
- case 1:
|
|
|
- console.log(1)
|
|
|
+ case 'banner':
|
|
|
return this.getSwiperElement();
|
|
|
break;
|
|
|
// 课程表
|
|
|
- case 2:
|
|
|
- console.log(2)
|
|
|
- return this.getScheduleElement(data);
|
|
|
+ case 'schedule':
|
|
|
+ return this.getScheduleElement();
|
|
|
break;
|
|
|
// 大图主题
|
|
|
- case 3:
|
|
|
- console.log(3)
|
|
|
- return (
|
|
|
- <View style={{
|
|
|
- flex: 1,
|
|
|
- height: 225,
|
|
|
- }}>
|
|
|
- <TopicTitle title={'五月主题:五月主题,去看看不同的世界'} summary={'每天30分钟'} ifTubeShow={true} />
|
|
|
- <ScrollRow itemWidth={352} itemHeight={153} />
|
|
|
- </View>
|
|
|
-
|
|
|
- );
|
|
|
+ case 'monthTopic':
|
|
|
+ return this.getMonthTopic();
|
|
|
break;
|
|
|
// 热门课程
|
|
|
- case 4:
|
|
|
- return (
|
|
|
- <View style={{
|
|
|
- flex: 1,
|
|
|
- height: 220,
|
|
|
- }}>
|
|
|
- <TopicTitle title={'热门广场'} ifTubeShow={true} />
|
|
|
- <ScrollRow itemWidth={106} itemHeight={150} />
|
|
|
- </View>
|
|
|
- )
|
|
|
+ case 'hotCourse':
|
|
|
+ return this.getHotCourse();
|
|
|
break;
|
|
|
- case 5:
|
|
|
- return (
|
|
|
- <View style={{
|
|
|
- flex: 1,
|
|
|
- height: 240,
|
|
|
- }}>
|
|
|
- <TopicTitle title={'生活好榜样'} summary={'死数据不是动态渲染'} />
|
|
|
- <ScrollRow itemWidth={106} itemHeight={150} />
|
|
|
- </View>
|
|
|
- )
|
|
|
+ case 'recommend':
|
|
|
+ return this.getAllCourses();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- // 渲染每一个section的title
|
|
|
+ // 渲染每一个section的title sectionList组件的data,没有用到,以后可能会用
|
|
|
sectionTitle = (info) => {
|
|
|
- console.log(info)
|
|
|
switch (info.section.title) {
|
|
|
case 'operation':
|
|
|
- console.log('进入运营区头部', info.section.title)
|
|
|
return (
|
|
|
<View
|
|
|
style={{
|