index.js
2 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
import Taro, { Component } from '@tarojs/taro';
import { View } from '@tarojs/components';
import { common as commonModel } from '../../models';
import Focus from '../resource-focus';
import HotSeries from '../resource-hot-series';
import Category from '../resource-category';
import './index.scss';
import getPrivateKey from '../../libs/request/getPrivateKey.js'
export default class Resources extends Component {
constructor(props) {
super(props);
this.state = {
floors: []
};
}
static defaultProps = {
floor: [],
title: '热门系列',
isShow: false
}
async componentDidMount() {
const pk = await getPrivateKey();
Taro.setStorage({ key: 'verifyKey', data: pk });
commonModel.resource(this.props.code).then(res => {
if (res && res.code === 200) {
this.setState({
floors: res.data
});
}
});
}
render() {
let { isShow, floors } = this.props;
if (isShow) {
floors = this.state.floors;
}
return (
<View className="resources">
{
floors.map((floor, idx) => {
return (
<View
className={
floor.template_name === 'tfGoodsList' ? 'resource-item no-right-padding' : 'resource-item'
}
key={floor.template_id}>
{
floor.template_name === 'focus' &&
<Focus floor={floor.data}
floorIdx={idx + 1}
floorName={floor.template_name}
floorId={floor.template_id}></Focus>
}
{
floor.template_name === 'hotSeries' &&
<HotSeries isShow={isShow} floor={floor.data}
floorIdx={idx + 1}
floorName={floor.template_name}
floorId={floor.template_id}
title={floor.template_intro}></HotSeries>
}
{
floor.template_name === 'category' && floor.data.length > 0 &&
floor.data.map((item, index) => {
return (
<Category floor={item} key={index}></Category>
)
})
}
</View>
)
})
}
</View>
)
}
}