Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion packages/renderless/src/pager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,19 @@ export const watchCurrentPage =
}

export const watchInternalPageCount =
({ state, api }: Pick<IPagerRenderlessParams, 'api' | 'state'>) =>
({ state, api, props }: Pick<IPagerRenderlessParams, 'api' | 'state' | 'props'>) =>
(pageCount: number | null): void => {
const oldCurPage = state.internalCurrentPage
const validCurrentPage = api.getValidCurrentPage(props.currentPage)

if (pageCount && pageCount > 0 && oldCurPage === 0) {
state.internalCurrentPage = 1
} else if (oldCurPage > Number(pageCount)) {
state.internalCurrentPage = pageCount || 1
state.userChangePageSize && api.emitChange()
} else if (oldCurPage < validCurrentPage) {
// total 从 0 等非法值变为有效后,恢复此前被裁剪的 current-page
state.internalCurrentPage = validCurrentPage
Comment thread
wuyiping0628 marked this conversation as resolved.
}

state.userChangePageSize = false
Expand Down
2 changes: 1 addition & 1 deletion packages/renderless/src/pager/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const renderless = (
watchInternalCurrentPage: watchInternalCurrentPage({ state, emit, props }),
getInternalPageSize: getInternalPageSize({ state, props }),
watchCurrentPage: watchCurrentPage({ state, api }),
watchInternalPageCount: watchInternalPageCount({ state, api }),
watchInternalPageCount: watchInternalPageCount({ state, api, props }),
watchTotal: watchTotal({ state }),
watchShowSizes: watchShowSizes({ nextTick, vm }),
watchInternalPageSize: watchInternalPageSize({ emit, props })
Expand Down
3 changes: 3 additions & 0 deletions packages/vue/src/pager/src/mobile-first.vue
Original file line number Diff line number Diff line change
Expand Up @@ -708,12 +708,15 @@ export default defineComponent({

watch(internalPageCount, (pageCount) => {
const oldCurPage = state.internalCurrentPage
const validCurrentPage = getValidCurrentPage(Number(props.currentPage))

if (pageCount && pageCount > 0 && oldCurPage === 0) {
state.internalCurrentPage = 1
} else if (pageCount && oldCurPage > pageCount) {
state.internalCurrentPage = pageCount === 0 ? 1 : pageCount
state.userChangePageSize && emitChange()
} else if (oldCurPage < validCurrentPage) {
state.internalCurrentPage = validCurrentPage
Comment thread
wuyiping0628 marked this conversation as resolved.
}

state.userChangePageSize = false
Expand Down
Loading