diff --git a/frontend/src/views/training/components/CourseCatalog.vue b/frontend/src/views/training/components/CourseCatalog.vue index 42ef0fd..7fffe73 100644 --- a/frontend/src/views/training/components/CourseCatalog.vue +++ b/frontend/src/views/training/components/CourseCatalog.vue @@ -38,7 +38,7 @@ - + + + diff --git a/frontend/src/views/training/components/useTrainingPager.ts b/frontend/src/views/training/components/useTrainingPager.ts new file mode 100644 index 0000000..f94bae8 --- /dev/null +++ b/frontend/src/views/training/components/useTrainingPager.ts @@ -0,0 +1,35 @@ +import { computed, ref, watch, type Ref } from 'vue' + +// 企业培训共用分页口径(000163):默认每页 15 条 +export const TRAINING_PAGE_SIZE = 15 +export const TRAINING_PAGE_SIZE_OPTIONS = [15, 30, 50, 100] + +/** + * 企业培训列表共用客户端分页(000163): + * 列表页均为全量加载 + 本地过滤,分页在前端切片完成。 + * 传入过滤后的全量列表,返回当前页切片与分页状态(供 TrainingPagination 绑定); + * 列表条数变化时自动夹紧页码,reset() 供「重置」按钮回到第 1 页。 + */ +export function useTrainingPager(source: Ref | (() => T[])) { + const page = ref(1) + const pageSize = ref(TRAINING_PAGE_SIZE) + + const list = computed(() => (typeof source === 'function' ? source() : source.value)) + const total = computed(() => list.value.length) + const paged = computed(() => { + const start = (page.value - 1) * pageSize.value + return list.value.slice(start, start + pageSize.value) + }) + + // 条数/每页条数变化后夹紧页码(过滤收紧或翻页超界时不出现空页) + watch([total, pageSize], () => { + const maxPage = Math.max(1, Math.ceil(total.value / pageSize.value)) + if (page.value > maxPage) page.value = maxPage + }) + + const reset = () => { + page.value = 1 + } + + return { page, pageSize, total, paged, reset } +}