SOURCE


// 此方法保证了当前页码在中间
function getPagenavtion(index = 0, pages = 5, pagesize = 20) {


    let arr = Array(pages).fill(0).map((item, idx) => {
        if (index < pages - 3) {
            return idx
        } else if (index > pagesize - pages + 2) {
            return pagesize - pages + idx
        }
        else {
            return idx + index - 2
        }
    })
    return arr
}

for (let i = 0; i < 20; i++) {
    console.log(`page:${i}`, getPagenavtion(i))
}



console 命令行工具 X clear

                    
>
console