|
|
import Taro, {Component} from '@tarojs/taro';
|
|
|
import {Swiper, SwiperItem, Navigator, Image, Button} from '@tarojs/components';
|
|
|
import {getImgUrl} from '../../utils';
|
|
|
import { Swiper, SwiperItem, Navigator, Image, Button, ScrollView } from '@tarojs/components';
|
|
|
import {getImgUrl, debounce} from '../../utils';
|
|
|
const _ = require('lodash');
|
|
|
import './index.scss';
|
|
|
import router from '../../router/index';
|
|
|
|
...
|
...
|
@@ -8,7 +9,9 @@ export default class Focus extends Component { |
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
|
|
|
this.state = {};
|
|
|
this.state = {
|
|
|
focusID: 'focus0'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
static defaultProps = {
|
...
|
...
|
@@ -17,11 +20,15 @@ export default class Focus extends Component { |
|
|
|
|
|
componentWillMount() {}
|
|
|
|
|
|
componentDidMount() {}
|
|
|
componentDidMount() {
|
|
|
|
|
|
}
|
|
|
|
|
|
componentWillUnmount() {}
|
|
|
|
|
|
componentDidShow() {}
|
|
|
componentDidShow() {
|
|
|
|
|
|
}
|
|
|
|
|
|
componentDidHide() {}
|
|
|
|
...
|
...
|
@@ -29,23 +36,49 @@ export default class Focus extends Component { |
|
|
router.goUrl(item.url);
|
|
|
}
|
|
|
|
|
|
onScroll(e) {
|
|
|
console.log(e.detail);
|
|
|
console.log(e);
|
|
|
console.log((e.detail.scrollLeft / 335).toFixed(0));
|
|
|
let index = (e.detail.scrollLeft / 335).toFixed(0);
|
|
|
_.debounce(this.changeIndex.bind(this), 1, { index });
|
|
|
}
|
|
|
|
|
|
changeIndex(index) {
|
|
|
this.setState({
|
|
|
focusID: `focus${index}`
|
|
|
})
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
let {floor} = this.props;
|
|
|
let { focusID } = this.state;
|
|
|
|
|
|
return (
|
|
|
<Swiper
|
|
|
className='index-swiper'
|
|
|
>
|
|
|
{
|
|
|
floor.map((item, index) => {
|
|
|
return (
|
|
|
<SwiperItem key={index}>
|
|
|
<Image onClick={this.goToResource.bind(this, item)} src={getImgUrl(item.src, 670, 280)} mode="aspectFill" />
|
|
|
</SwiperItem>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
|
</Swiper>
|
|
|
<View className='swiper-bg'>
|
|
|
<ScrollView
|
|
|
scrollX
|
|
|
className='index-swiper'
|
|
|
scrollIntoView = { focusID }
|
|
|
onScroll={this.onScroll}
|
|
|
scrollWithAnimation
|
|
|
>
|
|
|
{
|
|
|
floor.map((item, index) => {
|
|
|
return (
|
|
|
<Image
|
|
|
key={ index }
|
|
|
id={ 'focus' + index }
|
|
|
onClick={ this.goToResource.bind(this, item) }
|
|
|
src={ getImgUrl(item.src, 670, 280) }
|
|
|
mode="aspectFill"
|
|
|
/>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
|
<View className="noneView"></View>
|
|
|
</ScrollView>
|
|
|
</View>
|
|
|
)
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|