Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor Pagination component #575

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
744a2df
refactor(Pagination): add layout parse tools
Lydanne Feb 25, 2021
23e6451
refactor(Pagination): core finish
Lydanne Feb 28, 2021
661a450
refactor(Pagination): layout Pager component show page number ok
Lydanne Feb 28, 2021
085adbb
refactor(Pagination): make array tools
Lydanne Feb 28, 2021
2c60d10
refactor(Pagination): add hover class
Lydanne Feb 28, 2021
d214ccb
refactor(Pagination): add prev/next btn
Lydanne Feb 28, 2021
bc025ca
refactor(Pagination): Modify the Pager incoming parameters
Lydanne Mar 1, 2021
263184f
refactor(Pagination): add Total Part
Lydanne Mar 1, 2021
833937c
refactor(Pagination): Complete page number display(hug-sun#567)
Lydanne Mar 1, 2021
961f1ae
refactor(Pagination): To optimize the Code
Lydanne Mar 1, 2021
31b6fc1
refactor(Pagination): test coverage 100%
Lydanne Mar 1, 2021
df10646
Merge pull request #7 from hug-sun-1/refactor/pagination-1
Lydanne Mar 1, 2021
4171fab
refactor(Pagination): add props type
Lydanne Mar 4, 2021
2d649ee
refactor(Pagination): Complete the previous page to the next page switch
Lydanne Mar 4, 2021
a9b055b
refactor(Pagination): size change
Lydanne Mar 4, 2021
34d6103
refactor(Pagination): Implement pager paging
Lydanne Mar 4, 2021
fdc830b
refactor(Pagination): change hideOnSinglePage code
Lydanne Mar 4, 2021
6409c54
Merge pull request #8 from hug-sun-1/refactor/pagination-2
Lydanne Mar 4, 2021
a3b1f61
refactor(Pagination): optimized code
Lydanne Mar 5, 2021
183c227
refactor(Pagination): Realize the control of the drop-down selection box
Lydanne Mar 5, 2021
cddb878
refactor(Pagination): Based on popper-class to achieve drop-down styl…
Lydanne Mar 6, 2021
89152fb
Merge branch 'refactor/pagination' into refactor/pagination-3
Lydanne Mar 6, 2021
10fe4da
Merge pull request #9 from hug-sun-1:refactor/pagination-3
Lydanne Mar 6, 2021
6be64b5
refactor(Pagination): change el-select size
Lydanne Mar 6, 2021
44ca957
Merge branch 'master' into refactor/pagination
Lydanne Mar 9, 2021
a8c183b
refactor(Pagination): Based on layout-> to achieve custom layout alig…
Lydanne Mar 9, 2021
878128a
refactor(Pagination): Customize slots based on #default
Lydanne Mar 9, 2021
5bd3857
refactor(Pagination): finish Customize Prev and Next content
Lydanne Mar 10, 2021
1fb0acd
Merge pull request #10 from hug-sun-1:refactor/pagination-4
Lydanne Mar 10, 2021
5008194
refactor(Pagination): finish jumper part
Lydanne Mar 10, 2021
83db7d8
refactor(Pagination): finish disabled effect
Lydanne Mar 10, 2021
7215e69
refactor(Pagination): finish disabled effect
Lydanne Mar 10, 2021
50c48b2
refactor(Pagination): finish small style
Lydanne Mar 10, 2021
b9dd922
refactor(Pagination): finish background effect
Lydanne Mar 10, 2021
18af074
Merge pull request #11 from hug-sun-1:refactor/pagination-5
Lydanne Mar 10, 2021
f754a79
refactor(Pagination): export component
Lydanne Mar 10, 2021
9c7ad34
refactor(Pagination): fix jumper not update
Lydanne Mar 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/element3/src/components/Pagination/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ElPagination from './src/Pagination.vue'

ElPagination.install = function (app) {
app.component(ElPagination.name, ElPagination)
}

export { ElPagination }
49 changes: 49 additions & 0 deletions packages/element3/src/components/Pagination/src/Layout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<template v-for="(part, index) in layoutParts">
<template v-if="typeof part === 'string'">
<component :key="index" :is="part" :pager="pager"></component>
</template>
<template v-else>
<div class="el-pagination__rightwrapper" :key="index">
<layout :layout-parts="part"></layout>
</div>
</template>
</template>
</template>

<script lang="ts">
import { inject } from 'vue'

import Pager from './parts/Pager.vue'
import Prev from './parts/Prev.vue'
import Next from './parts/Next.vue'
import Total from './parts/Total.vue'
import Sizes from './parts/Sizes.vue'
import Slot from './parts/Slot.vue'
import Jumper from './parts/Jumper.vue'

import { Pager as PagerCore } from './entity/Pager'

export default {
name: 'Layout',
props: {
layoutParts: Array
},
components: {
Pager,
Total,
Next,
Prev,
Sizes,
Slot,
Jumper
},
setup() {
const pager = inject<PagerCore>('pagination/pager')

return {
pager
}
}
}
</script>
205 changes: 205 additions & 0 deletions packages/element3/src/components/Pagination/src/Pagination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<template>
<div
v-if="!(hideOnSinglePage && pager.count <= 1)"
class="el-pagination"
:class="{
'el-pagination--small': small,
'is-background': background
}"
>
<layout-part :layout-parts="layoutParts"></layout-part>
</div>
</template>

<script lang="ts">
import {
computed,
defineComponent,
reactive,
toRefs,
watch,
Ref,
getCurrentInstance,
PropType,
watchEffect,
provide
} from 'vue'
import { ElPaginationProps } from '../types'
import { Pager as PagerCore, PagerEventType } from './entity/Pager'
import { parseLayout } from './tools/parseLayout'

import LayoutPart from './Layout.vue'

export default defineComponent({
name: 'ElPagination',
props: {
layout: {
type: String,
default: 'prev, pager, next, jumper, ->, total'
},
pagerCount: {
type: Number,
default: 7
},
currentPage: {
type: Number,
default: 1
},
pageCount: {
type: Number
},
total: {
type: Number
},
pageSize: {
type: Number,
default: 10
},
hideOnSinglePage: {
type: Boolean,
default: false
},
pageSizes: {
type: Array as PropType<number[]>,
default: [10, 50, 100]
},
popperClass: {
type: String,
default: ''
},
nextText: {
type: String,
default: ''
},
prevText: {
type: String,
default: ''
},
disabled: Boolean,
small: Boolean,
background: Boolean
},
emits: [
'update:currentPage',
'prev-click',
'next-click',
'size-change',
'update:pageSize'
],
components: {
LayoutPart
},
setup(props: ElPaginationProps) {
const {
currentPage,
total,
pageSize,
pagerCount,
pageCount,
pageSizes,
popperClass,
layout,
nextText,
prevText,
disabled
} = toRefs(props)
const { layoutParts } = useLayout(layout)
const { pager } = usePager({
currentPage,
total,
pageSize,
pagerCount,
pageCount
})
useSises({ pager, pageSizes })
useStyle({ pager, popperClass, nextText, prevText, disabled })

return {
pager,
layoutParts
}
}
})

function usePager({ total, pageCount, pageSize, pagerCount, currentPage }) {
const pagerEventHandler = (pager) => {
pager.on(PagerEventType.CHANGE, (v) => {
emit('update:currentPage', v)
})
pager.on(PagerEventType.PREV, (v) => {
emit('prev-click', v)
})
pager.on(PagerEventType.NEXT, (v) => {
emit('next-click', v)
})
pager.on(PagerEventType.SIZE_CHANGE, (v) => {
emit('size-change', v)
emit('update:pageSize', v)
})
}
const bindVariableHandler = (pager) => {
if (total)
watch(total, (v: number) => {
pager.total = v
})
if (pageCount)
watch(pageCount, (v: number) => {
pager.total = v
pager.changeSize(1)
})
watch(pagerCount, (v: number) => {
pager.viewCount = v
})
watch(pageSize, (v: number) => {
pager.size = v
})
watch(currentPage, (v: number) => {
pager.current = v
})
}

const { emit } = getCurrentInstance()

const pager = reactive(
new PagerCore({
total: total?.value ?? pageCount.value,
size: total?.value ? pageSize.value : 1,
viewCount: pagerCount.value,
current: currentPage.value
})
)

pagerEventHandler(pager)
bindVariableHandler(pager)

provide('pagination/pager', pager)

return { pager }
}

function useStyle({ pager, popperClass, nextText, prevText, disabled }) {
watchEffect(() => {
pager.style = {
popperClass: popperClass.value,
nextText: nextText.value,
prevText: prevText.value,
disabled: disabled.value
}
})
}

function useSises({ pager, pageSizes }) {
watchEffect(() => {
pager.sizes = pageSizes.value
})
}

function useLayout(layout: Ref<string>) {
const instance = getCurrentInstance()
const layoutParts = computed(() => parseLayout(layout.value))
provide('pagination/slot/default', instance.slots.default)
return {
layoutParts
}
}
</script>
Loading