chore(pagination): dev checkpoint

This commit is contained in:
07akioni 2019-10-15 15:52:47 +08:00
parent bfed0ca49b
commit bed5f852f0
3 changed files with 18 additions and 19 deletions

View File

@ -2,7 +2,8 @@
<div
class="n-pagination"
:class="{
'n-pagination--transition-disabled': transitionDisabled
'n-pagination--transition-disabled': transitionDisabled,
[`n-${synthesizedTheme}-theme`]: synthesizedTheme
}"
>
<div
@ -83,6 +84,8 @@ import { pageItems } from './utils'
import Icon from './Icon'
import NSelect from '../../Select'
import NInput from '../../Input'
import withapp from '../../../mixins/withapp'
import themeable from '../../../mixins/themeable'
export default {
name: 'NPagination',
@ -91,6 +94,7 @@ export default {
NInput,
Icon
},
mixins: [withapp, themeable],
model: {
prop: 'page',
event: 'input'

View File

@ -3,26 +3,17 @@
* @param {number} currentPage
* @param {number} pageCount
*/
function pagesToShow (currentPage, pageCount) {
function pagesToShow (currentPage, pageCount, pageSlot = 9) {
if (pageCount === 1) return [1]
const firstPage = 1
const lastPage = pageCount
let middleStart = currentPage
let middleEnd = currentPage
if (firstPage === currentPage) {
middleEnd += 4
} else if (firstPage + 1 === currentPage) {
middleEnd += 3
} else {
middleEnd += 2
}
if (lastPage === currentPage) {
middleStart -= 4
} else if (lastPage - 1 === currentPage) {
middleStart -= 3
} else {
middleStart -= 2
}
const middleDelta = (pageSlot - 5) / 2
middleEnd += middleDelta
middleEnd = Math.min(Math.max(middleEnd, firstPage + pageSlot - 3), lastPage - 2)
middleStart -= middleStart
middleStart = Math.max(Math.min(middleStart, lastPage - pageSlot + 3), firstPage + 2)
let leftSplit = false
let rightSplit = false
if (middleStart > firstPage + 1) leftSplit = true
@ -31,14 +22,18 @@ function pagesToShow (currentPage, pageCount) {
items.push(firstPage)
if (leftSplit) {
items.push(-2)
} else if (pageCount >= firstPage + 1) {
items.push(firstPage + 1)
}
for (let i = Math.max(middleStart, firstPage + 1); i <= middleEnd && i < lastPage; ++i) {
for (let i = middleStart; i <= middleEnd && i < lastPage; ++i) {
items.push(i)
}
if (rightSplit) {
items.push(-1)
} else if (middleEnd === lastPage - 2) {
items.push(lastPage - 1)
}
items.push(lastPage)
if (firstPage !== lastPage) items.push(lastPage)
return items
}

View File

@ -6,5 +6,5 @@ import 'regenerator-runtime/runtime'
// packagesContext.keys().forEach(packagesContext)
// require all test files (files that ends with .spec.js)
const testsContext = require.context('./specs/packages/utils/data', true, /\.spec.js$/)
const testsContext = require.context('./specs/packages/common/Pagination', true, /\.spec.js$/)
testsContext.keys().forEach(testsContext)