mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-14 20:04:46 +08:00
feat(frontend): 分页 pageSize 持久化到 localStorage,刷新后自动恢复
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ref, reactive, onUnmounted, toRaw } from 'vue'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
import type { BasePaginationResponse, FetchOptions } from '@/types'
|
||||
import { getPersistedPageSize, setPersistedPageSize } from './usePersistedPageSize'
|
||||
|
||||
interface PaginationState {
|
||||
page: number
|
||||
@@ -21,14 +22,14 @@ interface TableLoaderOptions<T, P> {
|
||||
* 统一处理分页、筛选、搜索防抖和请求取消
|
||||
*/
|
||||
export function useTableLoader<T, P extends Record<string, any>>(options: TableLoaderOptions<T, P>) {
|
||||
const { fetchFn, initialParams, pageSize = 20, debounceMs = 300 } = options
|
||||
const { fetchFn, initialParams, pageSize, debounceMs = 300 } = options
|
||||
|
||||
const items = ref<T[]>([])
|
||||
const loading = ref(false)
|
||||
const params = reactive<P>({ ...(initialParams || {}) } as P)
|
||||
const pagination = reactive<PaginationState>({
|
||||
page: 1,
|
||||
page_size: pageSize,
|
||||
page_size: pageSize ?? getPersistedPageSize(),
|
||||
total: 0,
|
||||
pages: 0
|
||||
})
|
||||
@@ -87,6 +88,7 @@ export function useTableLoader<T, P extends Record<string, any>>(options: TableL
|
||||
const handlePageSizeChange = (size: number) => {
|
||||
pagination.page_size = size
|
||||
pagination.page = 1
|
||||
setPersistedPageSize(size)
|
||||
load()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user