renderFooter (quantity) {
const _self = this;
let wordStyle = {
color: 'rgba(71,129,255,1)'
}
let numberFrameCommon = {
width: 40,
height: 40,
marginLeft: 10,
cursor:'pointer'
}
let numberFrame = {
...numberFrameCommon,
background: 'rgba(71, 129, 255, 1)',
color: 'rgba(255, 255, 255, 1)',
}
let numberFrame2 = {
...numberFrameCommon,
background: 'rgba(27, 29, 45, 1)',
color:'rgba(99, 107, 138, 1)'
}
let ellipsisStyle = {
width:40,
height:40,
background: 'rgba(27,29,45,1)',
marginLeft:10,
fontSize:'14px',
borderRadius: '2px',
fontFamily: 'MicrosoftYaHei',
color:'rgba(99,107,138,1)'
}
let data = [];
for(let di=1; di<=_self.state.pageQuantity; di++) {
data.push(di)
}
//console.log( 'pageQuantity = ', _self.state.pageQuantity )
if ( _self.state.pageQuantity <= 10 ) {
return (
data.map((item, index, arr) => {
//console.log('item = ', item);
//console.log('index = ', index);
return (<div
key = {index}
style = {
_self.state.footFlag === index ?
numberFrame: numberFrame2
}
className={'numberFrame flexCenter'}
onClick={() => this.showPageData(index)}
>
{index+1}
</div>)
})
)
} else if ( _self.state.pageQuantity >10 ) {
return (
data.map((item, index, arr) => {
//console.log('item = ', item);
//console.log('index = ', index);
if(index<9) {
return (<div
key = {index}
style = {
_self.state.footFlag === index ?
numberFrame: numberFrame2
}
className={'numberFrame flexCenter'}
onClick={() => this.showPageData(index)}
>
{index+1}
</div>)
} else if ( index === 9) {
return (<div
key = {index}
style = {ellipsisStyle}
className={'numberFrame'}
>
...
</div>)
} else if (item === _self.state.pageQuantity) {
return (<div
key = {index}
style = {numberFrame}
className={'numberFrame'}
onClick={() => this.showPageData(index)}
>
{item}
</div>)
}
})
)
}
}
逻辑应该不需要怎么优化,写法可以优化