fix(培训页面优化):1.请检查所有企业培训相关页面带有列表展示都要进行分页,使用分页共用组件默认每页15条!
deploy-hxtesting / build-and-deploy (push) Successful in 1m8s
deploy-hxtesting / build-and-deploy (push) Successful in 1m8s
2.课程管理页面右侧固定太宽如图二所示收缩够用就可以,可参考培训计划页面 3.月培训计划数据默认显示计划培训和授课培训是当月数据,可筛选其他月份支持多选或全部数据 4.月培训计划只需要保留一个【创建月度计划】按钮,无法创建月度计划请核实根因!
This commit is contained in:
1 parent
2483dd933a
commit
102d94e6c8
10 files changed
+387
-50
No files matched your search
@@ -38,7 +38,7 @@
|
||||
|
||||
<!-- 我的考试:与我相关的考试记录列表(000154) -->
|
||||
<t-loading v-if="filter === 'exam'" :loading="loading" class="catalog-grid-wrap">
|
||||
<t-table :data="examRows" :columns="examColumns" row-key="id" size="small">
|
||||
<t-table :data="pagedExamRows" :columns="examColumns" row-key="id" size="small">
|
||||
<template #course_name="{ row }">{{ row.course_name || row.paper_name || '-' }}</template>
|
||||
<template #score="{ row }">
|
||||
<span :class="row.passed ? 'exam-score is-good' : 'exam-score is-bad'">{{ row.score ?? '—' }}</span>
|
||||
@@ -46,6 +46,7 @@
|
||||
<template #pass_line="{ row }">{{ row.pass_score || '-' }} / {{ row.total_score || '-' }}</template>
|
||||
<template #submitted_at="{ row }">{{ fmtExamTime(row.submitted_at) }}</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="examPage" v-model:page-size="examPageSize" :total="examTotal" />
|
||||
<t-empty v-if="!loading && !examRows.length" class="catalog-empty" description="暂无考试记录,参加随堂考试后此处展示成绩" />
|
||||
</t-loading>
|
||||
|
||||
@@ -53,7 +54,7 @@
|
||||
<t-loading v-else :loading="loading" class="catalog-grid-wrap">
|
||||
<div class="catalog-grid">
|
||||
<article
|
||||
v-for="card in visibleCards"
|
||||
v-for="card in pagedCards"
|
||||
:key="card.id"
|
||||
class="course-card"
|
||||
role="link"
|
||||
@@ -100,6 +101,8 @@
|
||||
class="catalog-empty"
|
||||
:description="filter === 'mine' ? '暂无与我相关的课程' : '暂无已发布课程(课程管理发布后在此展示)'"
|
||||
/>
|
||||
<!-- 共用分页(000163):课程卡片默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="cardPage" v-model:page-size="cardPageSize" :total="cardTotal" />
|
||||
</t-loading>
|
||||
|
||||
<!-- 课程学习抽屉(000160):和信课程卡片点开即学 —— 课件在线预览 + 下载 -->
|
||||
@@ -146,10 +149,12 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import DocumentPreview from '@/components/document-preview.vue'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
import {
|
||||
downloadCourseLibraryMaterial,
|
||||
getMyProfile,
|
||||
@@ -558,6 +563,27 @@ const visibleCards = computed<CatalogCard[]>(() => {
|
||||
})
|
||||
})
|
||||
|
||||
// 共用分页(000163):我的考试记录与课程卡片默认每页 15 条;搜索/页签切换后回到第 1 页
|
||||
const {
|
||||
page: examPage,
|
||||
pageSize: examPageSize,
|
||||
total: examTotal,
|
||||
paged: pagedExamRows,
|
||||
reset: resetExamPage,
|
||||
} = useTrainingPager(examRows)
|
||||
const {
|
||||
page: cardPage,
|
||||
pageSize: cardPageSize,
|
||||
total: cardTotal,
|
||||
paged: pagedCards,
|
||||
reset: resetCardPage,
|
||||
} = useTrainingPager(visibleCards)
|
||||
|
||||
watch([examRows, visibleCards, filter], () => {
|
||||
resetExamPage()
|
||||
resetCardPage()
|
||||
})
|
||||
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
</div>
|
||||
|
||||
<t-table
|
||||
:data="filteredRows"
|
||||
:data="pagedRows"
|
||||
:columns="learnColumns"
|
||||
row-key="id"
|
||||
size="small"
|
||||
@@ -74,6 +74,8 @@
|
||||
<t-tag :theme="taskTheme(row.status)" variant="light" size="small">{{ taskText(row.status) }}</t-tag>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="rowPage" v-model:page-size="rowPageSize" :total="rowTotal" />
|
||||
<t-empty v-if="!courseId" description="选择课程后查看该课程全员学习进度" />
|
||||
<t-empty v-else-if="!taskLoading && !rows.length" description="该课程暂无学习任务" />
|
||||
<t-empty v-else-if="rows.length && !filteredRows.length" description="没有符合查询条件的记录" />
|
||||
@@ -92,6 +94,8 @@ import {
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
|
||||
// 课程学习情况(管理端):列表按课程+学员唯一(后端 tr_learning_tasks
|
||||
// 以 tenant+course+member 唯一索引约束),上方为各状态汇总,支持条件查询。
|
||||
@@ -151,6 +155,17 @@ const filteredRows = computed(() => {
|
||||
})
|
||||
})
|
||||
|
||||
// 共用分页(000163):学习情况列表默认每页 15 条;条件查询/切换课程后回到第 1 页
|
||||
const {
|
||||
page: rowPage,
|
||||
pageSize: rowPageSize,
|
||||
total: rowTotal,
|
||||
paged: pagedRows,
|
||||
reset: resetRowPage,
|
||||
} = useTrainingPager(filteredRows)
|
||||
|
||||
watch(filteredRows, resetRowPage)
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.dept = ''
|
||||
filters.keyword = ''
|
||||
|
||||
@@ -4,26 +4,31 @@
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">月度培训计划</span>
|
||||
<div class="panel-box__actions">
|
||||
<t-button theme="primary" @click="openCreate('offline')">创建线下计划</t-button>
|
||||
<t-button variant="outline" @click="openCreate('online')">创建线上计划</t-button>
|
||||
<!-- 000163:线上线下经弹窗内「形式」切换,只保留一个创建入口 -->
|
||||
<t-button theme="primary" @click="openCreate('offline')">创建月度计划</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 查询条件:名称/讲师/培训时间范围/状态。计划列表全量加载(page_size=100),
|
||||
企业内部数据量小,过滤在前端本地完成,不新增后端查询参数。 -->
|
||||
<!-- 查询条件:名称/讲师/培训月份/状态。计划列表全量加载(page_size=100),
|
||||
企业内部数据量小,过滤在前端本地完成,不新增后端查询参数。
|
||||
000163:默认只看当月(计划培训/授课时间任一命中),月份可多选,清空=全部数据。 -->
|
||||
<div class="course-filters">
|
||||
<t-input v-model="filters.keyword" placeholder="按计划名称查询" clearable style="width: 200px" />
|
||||
<t-select v-if="!isLecturerOnly" v-model="filters.lecturerId" placeholder="按讲师查询" clearable style="width: 150px">
|
||||
<t-option v-for="l in lecturers" :key="l.id" :value="l.id" :label="l.name" />
|
||||
</t-select>
|
||||
<t-date-range-picker
|
||||
v-model="filters.teachRange"
|
||||
format="YYYY-MM-DD"
|
||||
separator="至"
|
||||
<t-select
|
||||
v-model="filters.months"
|
||||
multiple
|
||||
clearable
|
||||
:placeholder="['按开始日期', '按结束日期']"
|
||||
style="width: 260px"
|
||||
/>
|
||||
filterable
|
||||
collapse-tags
|
||||
:min-collapsed-num="2"
|
||||
placeholder="按培训月份筛选(可多选,清空为全部)"
|
||||
style="width: 280px"
|
||||
>
|
||||
<t-option v-for="m in monthOptions" :key="m" :value="m" :label="monthLabel(m)" />
|
||||
</t-select>
|
||||
<t-select v-model="filters.status" placeholder="按状态查询" clearable style="width: 130px">
|
||||
<t-option v-for="opt in STATUS_OPTIONS" :key="opt.value" :value="opt.value" :label="opt.label" />
|
||||
</t-select>
|
||||
@@ -31,7 +36,7 @@
|
||||
<span class="course-filter-count">共 {{ filteredCourses.length }} 门</span>
|
||||
</div>
|
||||
|
||||
<t-table :data="filteredCourses" :columns="courseColumns" row-key="id" size="small" :loading="loading">
|
||||
<t-table :data="pagedCourses" :columns="courseColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #plan_code="{ row }">{{ row.plan_code || '-' }}</template>
|
||||
<template #name="{ row }">
|
||||
<span class="course-name-link clamp-2" title="点击前往培训签到" @click="goSignTab(row)">{{ row.name }}</span>
|
||||
@@ -76,10 +81,12 @@
|
||||
<t-button v-if="canManage" variant="text" theme="danger" size="small" @click="onDelete(row)">删除</t-button>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="coursePage" v-model:page-size="coursePageSize" :total="courseTotal" />
|
||||
</div>
|
||||
|
||||
<!-- 创建计划:课程名称从课程管理选择(带出并锁定课程信息),仅维护授课安排六字段 -->
|
||||
<t-dialog v-model:visible="formVisible" :header="form.mode === 'online' ? '创建线上计划' : '创建线下计划'" width="720">
|
||||
<t-dialog v-model:visible="formVisible" header="创建月度计划" width="720">
|
||||
<t-form label-width="100">
|
||||
<t-form-item label="计划编号">
|
||||
<t-input value="保存后自动生成" disabled />
|
||||
@@ -438,7 +445,7 @@
|
||||
|
||||
<!-- 计划修改记录:每次保存的版本与字段级变更明细 -->
|
||||
<t-dialog v-model:visible="changeLogsVisible" :header="`计划修改记录 · ${changeLogCourse?.name || ''}`" width="640" :footer="false">
|
||||
<t-table :data="changeLogs" :columns="changeLogColumns" row-key="id" size="small" :loading="changeLogsLoading">
|
||||
<t-table :data="pagedChangeLogs" :columns="changeLogColumns" row-key="id" size="small" :loading="changeLogsLoading">
|
||||
<template #changes="{ row }">
|
||||
<div v-for="(c, idx) in row.changes || []" :key="idx" class="change-line">
|
||||
{{ c.label }}:{{ c.old || '—' }} → {{ c.new || '—' }}
|
||||
@@ -447,6 +454,7 @@
|
||||
<template #operator="{ row }">{{ operatorName(row.operator_id) }}</template>
|
||||
<template #created_at="{ row }">{{ fmtTime(row.created_at) }}</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="changeLogPage" v-model:page-size="changeLogPageSize" :total="changeLogTotal" />
|
||||
<t-empty v-if="!changeLogsLoading && !changeLogs.length" description="暂无修改记录;计划信息每次保存后自动留痕" />
|
||||
</t-dialog>
|
||||
</div>
|
||||
@@ -491,6 +499,8 @@ import {
|
||||
} from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import { apiErrorMessage, get } from '@/utils/request'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
// 课程维护:人事/课长/讲师(roles 已按权限组展开,经理经课长继承自动命中);
|
||||
@@ -858,6 +868,7 @@ const openChangeLogs = async (row: TrainingCourse) => {
|
||||
changeLogCourse.value = row
|
||||
changeLogsVisible.value = true
|
||||
changeLogsLoading.value = true
|
||||
resetChangeLogPage()
|
||||
try {
|
||||
const res = await listCourseChangeLogs(row.id)
|
||||
changeLogs.value = unwrap(res) || []
|
||||
@@ -974,7 +985,7 @@ const courseColumns = [
|
||||
{ colKey: 'op', title: '操作', width: 180, fixed: 'right' },
|
||||
]
|
||||
|
||||
// ---- 查询条件(名称/讲师/培训时间/状态;列表全量加载,本地过滤) ----
|
||||
// ---- 查询条件(名称/讲师/培训月份/状态;列表全量加载,本地过滤) ----
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: 'draft', label: '草稿' },
|
||||
{ value: 'pending', label: '待审' },
|
||||
@@ -982,17 +993,50 @@ const STATUS_OPTIONS = [
|
||||
{ value: 'archived', label: '已归档' },
|
||||
]
|
||||
|
||||
// 当月(YYYY-MM,000163):默认只展示计划培训/授课时间任一命中当月的计划
|
||||
const now = new Date()
|
||||
const currentMonthKey = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`
|
||||
|
||||
const filters = ref({
|
||||
keyword: '',
|
||||
lecturerId: '' as string | '',
|
||||
status: '',
|
||||
teachRange: [] as string[],
|
||||
// 培训月份多选(000163):默认当月;清空 = 全部数据
|
||||
months: [currentMonthKey] as string[],
|
||||
})
|
||||
|
||||
const resetFilters = () => {
|
||||
filters.value = { keyword: '', lecturerId: '', status: '', teachRange: [] }
|
||||
filters.value = { keyword: '', lecturerId: '', status: '', months: [currentMonthKey] }
|
||||
resetCoursePage()
|
||||
}
|
||||
|
||||
// 月份归一:「YYYY-M」/「YYYY-MM-DD HH:mm」等统一取 YYYY-MM;无法解析返回空
|
||||
const monthKeyOf = (value: string | null | undefined): string => {
|
||||
const m = (value || '').trim().match(/^(\d{4})-(\d{1,2})/)
|
||||
return m ? `${m[1]}-${String(Number(m[2])).padStart(2, '0')}` : ''
|
||||
}
|
||||
|
||||
// 月份下拉展示:2026-11 → 2026年11月
|
||||
const monthLabel = (key: string) => {
|
||||
const m = key.match(/^(\d{4})-(\d{2})$/)
|
||||
return m ? `${m[1]}年${Number(m[2])}月` : key
|
||||
}
|
||||
|
||||
// 计划的培训月份集合(000163):计划培训时间 + 授课时间(含最近场次回退)任一命中即算
|
||||
const courseMonthKeys = (row: TrainingCourse): string[] => {
|
||||
const keys = [monthKeyOf(row.planned_time), monthKeyOf(row.teach_time), monthKeyOf(teachDateValue(row))]
|
||||
return [...new Set(keys.filter(Boolean))]
|
||||
}
|
||||
|
||||
// 月份筛选选项:当月 + 计划数据中实际出现的月份,倒序展示
|
||||
const monthOptions = computed(() => {
|
||||
const set = new Set<string>([currentMonthKey])
|
||||
for (const row of courses.value) {
|
||||
for (const k of courseMonthKeys(row)) set.add(k)
|
||||
}
|
||||
return [...set].sort().reverse()
|
||||
})
|
||||
|
||||
// 授课时间过滤口径与列展示一致:teach_time(具体时间/期望月份)优先,否则最近场次开始时间,
|
||||
// 统一归一为 YYYY-MM-DD 后做字符串范围比较。
|
||||
const teachDateValue = (row: TrainingCourse): string | null => {
|
||||
@@ -1010,23 +1054,38 @@ const teachDateValue = (row: TrainingCourse): string | null => {
|
||||
|
||||
const filteredCourses = computed(() => {
|
||||
const kw = filters.value.keyword.trim().toLowerCase()
|
||||
const range = filters.value.teachRange || []
|
||||
const from = range[0] ? String(range[0]).slice(0, 10) : ''
|
||||
const to = range[1] ? String(range[1]).slice(0, 10) : ''
|
||||
const months = filters.value.months || []
|
||||
return courses.value.filter((row) => {
|
||||
if (kw && !(row.name || '').toLowerCase().includes(kw)) return false
|
||||
if (filters.value.lecturerId && row.lecturer_id !== filters.value.lecturerId) return false
|
||||
if (filters.value.status && row.status !== filters.value.status) return false
|
||||
if (from || to) {
|
||||
const v = teachDateValue(row)
|
||||
if (!v) return false
|
||||
if (from && v < from) return false
|
||||
if (to && v > to) return false
|
||||
// 000163 月份筛选:计划培训时间/授课时间任一命中所选月份即可;清空 = 全部数据
|
||||
if (months.length) {
|
||||
const keys = courseMonthKeys(row)
|
||||
if (!months.some((m) => keys.includes(m))) return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
// 共用分页(000163):计划列表默认每页 15 条
|
||||
const {
|
||||
page: coursePage,
|
||||
pageSize: coursePageSize,
|
||||
total: courseTotal,
|
||||
paged: pagedCourses,
|
||||
reset: resetCoursePage,
|
||||
} = useTrainingPager(filteredCourses)
|
||||
|
||||
// 计划修改记录弹窗分页(000163)
|
||||
const {
|
||||
page: changeLogPage,
|
||||
pageSize: changeLogPageSize,
|
||||
total: changeLogTotal,
|
||||
paged: pagedChangeLogs,
|
||||
reset: resetChangeLogPage,
|
||||
} = useTrainingPager(changeLogs)
|
||||
|
||||
const statusText = (s: string) => ({ draft: '草稿', pending: '待审', published: '已发布', archived: '已归档' }[s] || s)
|
||||
const statusTheme = (s: string) => ({ draft: 'default', pending: 'warning', published: 'success', archived: 'default' }[s] || 'default')
|
||||
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '待定'
|
||||
@@ -1111,15 +1170,46 @@ const onSave = async () => {
|
||||
MessagePlugin.warning('请从课程管理选择课程(课程名称必选)')
|
||||
return
|
||||
}
|
||||
// 000163 根因修复:此前「保存并发布」直接调发布接口,后端校验不过时前端只
|
||||
// 报笼统的「保存失败」且不刷新列表(草稿其实已落库),表现为“无法创建月度计划”。
|
||||
// 现与后端 PublishCourse 同口径,在提交前逐项拦截并给出明确提示。
|
||||
const selectedLib = libraryCourses.value.find((c) => c.id === form.value.library_course_id)
|
||||
// 课程须已完成签核(000157/000158):未核验时发布被后端拦截,这里提前提示
|
||||
if (selectedLib && selectedLib.verify_status !== 'confirmed') {
|
||||
MessagePlugin.warning(
|
||||
`课程「${selectedLib.name}」尚未完成签核,请先联系所属部门课长/经理在「课程管理」中核验确认后再创建发布`,
|
||||
)
|
||||
return
|
||||
}
|
||||
// 讲师随课程管理锁定:线下计划缺讲师时提示先在课程管理维护
|
||||
if (form.value.mode === 'offline' && !form.value.lecturer_id) {
|
||||
MessagePlugin.warning('当前课程未指定讲师,请先前往「课程管理」维护讲师后再创建线下计划')
|
||||
return
|
||||
}
|
||||
// 线下计划另需授课时间/授课地点(后端发布校验同口径)
|
||||
if (form.value.mode === 'offline') {
|
||||
if (!form.value.start_at) {
|
||||
MessagePlugin.warning('线下计划请先设置授课时间')
|
||||
return
|
||||
}
|
||||
if (!form.value.location.trim()) {
|
||||
MessagePlugin.warning('线下计划请先设置授课地点')
|
||||
return
|
||||
}
|
||||
}
|
||||
// 线上计划须已登记课件(名称登记/文件/知识库文档任一,随课程管理带出)
|
||||
if (form.value.mode === 'online' && !(selectedLib?.material_name || selectedLib?.file_name || selectedLib?.knowledge_id)) {
|
||||
MessagePlugin.warning('线上计划发布前需先在「课程管理」为该课程登记课件资料(上传课件/从知识库选择)')
|
||||
return
|
||||
}
|
||||
// 参加人员必填(后端发布校验:post_scope 与场次名单任一非空)
|
||||
const selectedMembers = resolvedFormMembers.value
|
||||
if (!selectedMembers.length) {
|
||||
MessagePlugin.warning('请先选择参加人员(推送与应培人员以「参加人员」名单为准)')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
// 参加人员(与详情弹窗同构):选中员工写 post_scope,落库后同步为场次学员名单
|
||||
const selectedMembers = resolvedFormMembers.value
|
||||
const postScope = selectedMembers.map((m) => m.user_name || m.employee_no).join('、')
|
||||
const res = await saveCourse({
|
||||
name: form.value.name,
|
||||
@@ -1168,7 +1258,19 @@ const onSave = async () => {
|
||||
const session = rosterSession || await ensureCourseSession(course.id, sessionOpts)
|
||||
if (session) await setEnrollments(session.id, selectedMembers.map((m) => m.id))
|
||||
}
|
||||
await publishCourse(course.id)
|
||||
// 000163 根因修复:发布与保存拆开处理 —— 发布校验不过时草稿已落库,
|
||||
// 透出真实原因并刷新列表,草稿可在列表「调整」完善后再点「发布」。
|
||||
try {
|
||||
await publishCourse(course.id)
|
||||
} catch (e: any) {
|
||||
MessagePlugin.warning(
|
||||
`计划已保存为草稿(计划编号 ${course.plan_code || '自动生成'}),发布失败:${apiErrorMessage(e, '请完善计划信息后再发布')};可在列表「调整」完善后点击「发布」`,
|
||||
)
|
||||
formVisible.value = false
|
||||
resetFormParticipants()
|
||||
loadAll()
|
||||
return
|
||||
}
|
||||
MessagePlugin.success(
|
||||
course.plan_code
|
||||
? `计划 ${course.plan_code} 已保存并发布,讲师与学员通知已生成`
|
||||
@@ -1177,8 +1279,8 @@ const onSave = async () => {
|
||||
formVisible.value = false
|
||||
resetFormParticipants()
|
||||
loadAll()
|
||||
} catch {
|
||||
MessagePlugin.error('保存失败,请稍后重试')
|
||||
} catch (e: any) {
|
||||
MessagePlugin.error(apiErrorMessage(e, '保存失败,请稍后重试'))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<span class="records-header__title">试卷</span>
|
||||
<span class="muted">学员可在企微内答题;此处支持本人在线答题与监考代录</span>
|
||||
</div>
|
||||
<t-table :data="papers" :columns="paperColumns" row-key="id" size="small" :loading="papersLoading">
|
||||
<t-table :data="pagedPapers" :columns="paperColumns" row-key="id" size="small" :loading="papersLoading">
|
||||
<template #course="{ row }">{{ paperCourseName(row) }}</template>
|
||||
<template #op="{ row }">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onTakeExam(row)">答题</t-button>
|
||||
@@ -52,6 +52,7 @@
|
||||
<t-button variant="text" size="small" @click="recordPaperId = row.id">考试情况</t-button>
|
||||
</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="paperPage" v-model:page-size="paperPageSize" :total="paperTotal" />
|
||||
<t-empty v-if="!papersLoading && !papers.length" description="该课程暂无试卷(组卷/AI 生成/答题后自动生成)" />
|
||||
</template>
|
||||
|
||||
@@ -93,7 +94,7 @@
|
||||
<span class="query-bar__hit">共 {{ filteredRecords.length }} 条</span>
|
||||
</div>
|
||||
|
||||
<t-table :data="filteredRecords" :columns="recordColumns" row-key="id" size="small" class="records-table" :loading="recordLoading">
|
||||
<t-table :data="pagedRecords" :columns="recordColumns" row-key="id" size="small" class="records-table" :loading="recordLoading">
|
||||
<template #member="{ row }">{{ memberLabel(row.member_id) }}</template>
|
||||
<template #dept="{ row }">{{ memberDept(row.member_id) }}</template>
|
||||
<template #score="{ row }">
|
||||
@@ -101,6 +102,7 @@
|
||||
</template>
|
||||
<template #submitted_at="{ row }">{{ fmtTime(row.submitted_at) }}</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="recordPage" v-model:page-size="recordPageSize" :total="recordTotal" />
|
||||
<t-empty v-if="!recordPaperId" description="选择课程与试卷后查看考试情况与答题记录" />
|
||||
<t-empty v-else-if="!recordLoading && !records.length" description="该试卷暂无答题记录" />
|
||||
<t-empty v-else-if="records.length && !filteredRecords.length" description="没有符合查询条件的记录" />
|
||||
@@ -171,6 +173,8 @@ import {
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import { apiErrorMessage } from '@/utils/request'
|
||||
import QuestionExamDialog from './QuestionExamDialog.vue'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean; initialCourseId?: string }>()
|
||||
// 监考/代交卷:人事/课长/讲师(roles 已按权限组展开,经理自动命中)
|
||||
@@ -311,6 +315,19 @@ const filteredRecords = computed(() => {
|
||||
})
|
||||
})
|
||||
|
||||
// 共用分页(000163):试卷/考试成绩列表默认每页 15 条
|
||||
const { page: paperPage, pageSize: paperPageSize, total: paperTotal, paged: pagedPapers } = useTrainingPager(papers)
|
||||
const {
|
||||
page: recordPage,
|
||||
pageSize: recordPageSize,
|
||||
total: recordTotal,
|
||||
paged: pagedRecords,
|
||||
reset: resetRecordPage,
|
||||
} = useTrainingPager(filteredRecords)
|
||||
|
||||
// 条件查询/切换试卷后考试成绩回到第 1 页
|
||||
watch(filteredRecords, resetRecordPage)
|
||||
|
||||
const loadAll = async () => {
|
||||
const [s, m, c, d] = await Promise.all([
|
||||
listSessions({ page_size: 200 }),
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
<t-table
|
||||
v-model:selected-row-keys="selectedKeys"
|
||||
:data="filteredItems" :columns="columns" row-key="id" size="small" :loading="loading"
|
||||
:data="pagedItems" :columns="columns" row-key="id" size="small" :loading="loading"
|
||||
>
|
||||
<template #code="{ row }">{{ row.code || '-' }}</template>
|
||||
<template #name="{ row }"><span class="clamp-2">{{ row.name }}</span></template>
|
||||
@@ -135,6 +135,8 @@
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="itemPage" v-model:page-size="itemPageSize" :total="itemTotal" />
|
||||
</div>
|
||||
|
||||
<!-- 新增/编辑课程弹窗:分类/讲师支持下拉选择或手动输入(输入即保存为新分类/外部讲师) -->
|
||||
@@ -322,7 +324,7 @@
|
||||
同名题库重新导入会整体替换;解析 Excel 题目自动建题库并挂到本课程(月培训计划选课后自动具备随堂考试能力);Excel 原件同步知识库「企业培训(题库)」;课件已上传时文档同步知识库「企业培训(课件)」,支持 AI 出题与对话问答。
|
||||
</div>
|
||||
|
||||
<t-table :data="banks" :columns="bankColumns" row-key="id" size="small" :loading="banksLoading">
|
||||
<t-table :data="pagedBanks" :columns="bankColumns" row-key="id" size="small" :loading="banksLoading">
|
||||
<template #op="{ row }">
|
||||
<t-button variant="text" theme="primary" size="small" @click="selectBank(row)">查看试题</t-button>
|
||||
<t-popconfirm content="删除题库将连带删除全部题目与试卷,确定?" theme="danger" @confirm="onDeleteBank(row)">
|
||||
@@ -330,6 +332,7 @@
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="bankPage" v-model:page-size="bankPageSize" :total="bankTotal" />
|
||||
<t-empty v-if="!banksLoading && !banks.length" description="暂无题库,可在上方上传 Excel / 从知识库导入 / AI 生成" />
|
||||
|
||||
<template v-if="activeBank">
|
||||
@@ -337,7 +340,7 @@
|
||||
题库「{{ activeBank.name }}」({{ activeBank.question_count }}题)
|
||||
<t-button theme="primary" variant="outline" size="small" class="bank-section-add" @click="openQuestionForm()">+ 新增试题</t-button>
|
||||
</div>
|
||||
<t-table :data="questions" :columns="questionColumns" row-key="id" size="small" :loading="questionsLoading">
|
||||
<t-table :data="pagedQuestions" :columns="questionColumns" row-key="id" size="small" :loading="questionsLoading">
|
||||
<template #type="{ row }">{{ questionTypeText(row.type) }}</template>
|
||||
<template #stem="{ row }">
|
||||
<t-tooltip v-if="row.stem" :content="row.stem">
|
||||
@@ -353,6 +356,7 @@
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="questionPage" v-model:page-size="questionPageSize" :total="questionTotal" />
|
||||
<t-empty v-if="!questionsLoading && !questions.length" description="该题库暂无试题,可新增或重新导入" />
|
||||
</template>
|
||||
</t-drawer>
|
||||
@@ -501,6 +505,8 @@ import * as XLSX from 'xlsx'
|
||||
import { COURSE_LIBRARY_TEMPLATE_KEY, QUESTION_TEMPLATE_KEY, downloadTrainingTemplate } from '../trainingTemplates'
|
||||
import { apiErrorMessage, get } from '@/utils/request'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
import {
|
||||
attachCourseLibraryMaterialFromKb,
|
||||
deleteCourseLibraryItem,
|
||||
@@ -628,6 +634,18 @@ const filteredItems = computed(() => {
|
||||
})
|
||||
})
|
||||
|
||||
// 共用分页(000163):课程列表默认每页 15 条;查询条件变化后回到第 1 页
|
||||
const {
|
||||
page: itemPage,
|
||||
pageSize: itemPageSize,
|
||||
total: itemTotal,
|
||||
paged: pagedItems,
|
||||
reset: resetItemPage,
|
||||
} = useTrainingPager(filteredItems)
|
||||
|
||||
// 查询条件变化(重置/筛选)后列表回到第 1 页
|
||||
watch(filteredItems, resetItemPage)
|
||||
|
||||
const columns = [
|
||||
// 批量勾选列(000157):配合批量核验/批量删除
|
||||
{ colKey: 'row-select', type: 'multiple', width: 44 },
|
||||
@@ -650,9 +668,10 @@ const columns = [
|
||||
{ colKey: 'created_at', title: '创建时间', width: 140 },
|
||||
// 创建人(联查 users):记录课程录入人员
|
||||
{ colKey: 'creator_name', title: '创建人', width: 96 },
|
||||
// 核验状态(000157):固定右侧置于操作列前
|
||||
{ colKey: 'verify_status', title: '状态', width: 90, fixed: 'right' },
|
||||
{ colKey: 'op', title: '操作', width: 340, fixed: 'right' },
|
||||
// 000163 右侧固定区收缩(参考年培训计划页):状态 84,操作收窄至够用,
|
||||
// 按钮紧凑排布(见下方样式),消除固定区的空白浪费
|
||||
{ colKey: 'verify_status', title: '状态', width: 84, fixed: 'right' },
|
||||
{ colKey: 'op', title: '操作', width: 260, fixed: 'right', className: 'op-cell' },
|
||||
]
|
||||
|
||||
const lecturerText = (row: TrainingLibraryCourse) =>
|
||||
@@ -1266,6 +1285,21 @@ const activeBank = ref<TrainingQuestionBank | null>(null)
|
||||
const questions = ref<TrainingQuestion[]>([])
|
||||
const questionsLoading = ref(false)
|
||||
|
||||
// 题库/试题列表分页(000163):默认每页 15 条;切换题库后试题回到第 1 页
|
||||
const {
|
||||
page: bankPage,
|
||||
pageSize: bankPageSize,
|
||||
total: bankTotal,
|
||||
paged: pagedBanks,
|
||||
} = useTrainingPager(banks)
|
||||
const {
|
||||
page: questionPage,
|
||||
pageSize: questionPageSize,
|
||||
total: questionTotal,
|
||||
paged: pagedQuestions,
|
||||
reset: resetQuestionPage,
|
||||
} = useTrainingPager(questions)
|
||||
|
||||
const bankColumns = [
|
||||
{ colKey: 'code', title: '题库编号', width: 105 },
|
||||
{ colKey: 'name', title: '题库名称', minWidth: 180 },
|
||||
@@ -1318,6 +1352,7 @@ const loadBanks = async () => {
|
||||
const selectBank = async (bank: TrainingQuestionBank) => {
|
||||
activeBank.value = bank
|
||||
questionsLoading.value = true
|
||||
resetQuestionPage()
|
||||
try {
|
||||
const res = await listQuestions(bank.id)
|
||||
questions.value = unwrap(res) || []
|
||||
@@ -1700,6 +1735,16 @@ onMounted(loadAll)
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
// 000163 操作列按钮紧凑排布:缩小左右内边距并固定按钮间距,
|
||||
// 使右侧固定区(状态 84 + 操作 260)收窄至够用,不再出现大片空白
|
||||
.library-panel :deep(.op-cell .t-button) {
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
.library-panel :deep(.op-cell .t-button + .t-button) {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
// 批量导入弹窗:模板下载 + Excel 上传一行排布(与培训计划导入同款)
|
||||
.import-row {
|
||||
display: flex;
|
||||
|
||||
@@ -36,9 +36,9 @@
|
||||
clearable
|
||||
placeholder="课程名称模糊搜索"
|
||||
style="width: 200px"
|
||||
@enter="loadDemands"
|
||||
@enter="onSearchDemands"
|
||||
/>
|
||||
<t-button variant="outline" @click="loadDemands">查询</t-button>
|
||||
<t-button variant="outline" @click="onSearchDemands">查询</t-button>
|
||||
<t-button variant="outline" @click="onResetDemandSearch">重置</t-button>
|
||||
<t-button v-if="canConfirm" theme="primary" variant="outline" :disabled="!selectedDemandKeys.length" :loading="batchSaving" @click="onBatchConfirm">批量确认</t-button>
|
||||
<t-button v-if="canManage" theme="danger" variant="outline" :disabled="!selectedDemandKeys.length" :loading="batchSaving" @click="onBatchDelete">批量删除</t-button>
|
||||
@@ -46,7 +46,7 @@
|
||||
</div>
|
||||
<t-table
|
||||
v-model:selected-row-keys="selectedDemandKeys"
|
||||
:data="demands"
|
||||
:data="pagedDemands"
|
||||
:columns="demandColumns"
|
||||
row-key="id"
|
||||
size="small"
|
||||
@@ -99,6 +99,8 @@
|
||||
</template>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="demandPage" v-model:page-size="demandPageSize" :total="demandTotal" />
|
||||
</div>
|
||||
|
||||
<!-- 提报需求弹窗(编辑态复用:部门按提报人自动获取) -->
|
||||
@@ -250,6 +252,8 @@ import * as XLSX from 'xlsx'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import { DEMAND_TEMPLATE_KEY, downloadTrainingTemplate } from '../trainingTemplates'
|
||||
import { apiErrorMessage } from '@/utils/request'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
import {
|
||||
broadcastTrainingNotification,
|
||||
confirmDemand,
|
||||
@@ -291,7 +295,10 @@ const currentYear = now.getFullYear()
|
||||
// 年度需求收集:年份下拉为需求库实际年份(降序),默认展示最新一年(无数据回退当前年)
|
||||
const selectedYear = ref(currentYear)
|
||||
const yearOptions = ref<number[]>([])
|
||||
const onYearChange = () => loadDemands()
|
||||
const onYearChange = () => {
|
||||
resetDemandPage()
|
||||
loadDemands()
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
@@ -515,6 +522,15 @@ const loadDemands = async () => {
|
||||
demands.value = unwrap(d)?.items || []
|
||||
}
|
||||
|
||||
// 共用分页(000163):需求列表默认每页 15 条;查询条件/年度切换后回到第 1 页
|
||||
const {
|
||||
page: demandPage,
|
||||
pageSize: demandPageSize,
|
||||
total: demandTotal,
|
||||
paged: pagedDemands,
|
||||
reset: resetDemandPage,
|
||||
} = useTrainingPager(demands)
|
||||
|
||||
// 年份下拉数据源:需求库实际年份(降序)。resetSelection=true 时默认选中最新一年
|
||||
// (首次进入);后续刷新仅在当前选中年份已无数据时回退最新,避免打断用户选择。
|
||||
const loadDemandYears = async (resetSelection = false) => {
|
||||
@@ -531,6 +547,13 @@ const loadDemandYears = async (resetSelection = false) => {
|
||||
|
||||
const onResetDemandSearch = () => {
|
||||
demandSearch.value = { state: '', dept_id: '', keyword: '' }
|
||||
resetDemandPage()
|
||||
loadDemands()
|
||||
}
|
||||
|
||||
// 查询/年度切换:过滤条件变化后需求列表回到第 1 页
|
||||
const onSearchDemands = () => {
|
||||
resetDemandPage()
|
||||
loadDemands()
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
<span class="records-header__title">签到明细</span>
|
||||
<t-button v-if="canReview && signCode" variant="outline" size="small" @click="proxyVisible = true">代扫码 / 补录</t-button>
|
||||
</div>
|
||||
<t-table :data="records" :columns="recordColumns" row-key="id" size="small" :loading="loading">
|
||||
<t-table :data="pagedRecords" :columns="recordColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #member="{ row }">{{ memberLabel(row.member_id) }}</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag :theme="statusTheme(row.status)" variant="light" size="small">{{ statusText(row.status) }}</t-tag>
|
||||
@@ -125,6 +125,8 @@
|
||||
</template>
|
||||
</template>
|
||||
</t-table>
|
||||
<!-- 共用分页(000163):默认每页 15 条 -->
|
||||
<TrainingPagination v-model:current="recordPage" v-model:page-size="recordPageSize" :total="recordTotal" />
|
||||
|
||||
<!-- 代扫码 / 补录:走同一防伪规则引擎,proxy 标记留痕 -->
|
||||
<t-dialog v-model:visible="proxyVisible" header="代扫码 / 现场补录" width="460">
|
||||
@@ -199,6 +201,8 @@ import {
|
||||
unwrap,
|
||||
} from '@/api/training'
|
||||
import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
const route = useRoute()
|
||||
@@ -231,6 +235,15 @@ const signCode = ref<TrainingSignCode | null>(null)
|
||||
const summary = ref<SignSummary | null>(null)
|
||||
const records = ref<TrainingSignRecord[]>([])
|
||||
|
||||
// 签到明细分页(000163):默认每页 15 条;切换场次后回到第 1 页
|
||||
const {
|
||||
page: recordPage,
|
||||
pageSize: recordPageSize,
|
||||
total: recordTotal,
|
||||
paged: pagedRecords,
|
||||
reset: resetRecordPage,
|
||||
} = useTrainingPager(records)
|
||||
|
||||
const recordColumns = [
|
||||
{ colKey: 'member', title: '学员', width: 220 },
|
||||
{ colKey: 'signed_at', title: '签到时间', width: 170 },
|
||||
@@ -382,6 +395,7 @@ const loadAll = async () => {
|
||||
const loadSessionData = async () => {
|
||||
if (!selectedSessionId.value) return
|
||||
const sid = selectedSessionId.value
|
||||
resetRecordPage()
|
||||
try {
|
||||
const [code, sum, recs, evs] = await Promise.all([
|
||||
getSignCode(sid).catch(() => null),
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<span class="panel-box__title">我的学习任务</span>
|
||||
<span class="panel-box__sub">点击课程名进入学习,进度 ≥95% 自动完成</span>
|
||||
</div>
|
||||
<t-table :data="tasks" :columns="taskColumns" row-key="id" size="small">
|
||||
<t-table :data="pagedTasks" :columns="taskColumns" row-key="id" size="small">
|
||||
<template #course_name="{ row }">
|
||||
<a class="task-course-link" @click="goCourse(row.course_id)">{{ row.course_name }}</a>
|
||||
</template>
|
||||
@@ -31,6 +31,7 @@
|
||||
<t-tag :theme="taskTheme(row.status)" variant="light" size="small">{{ taskText(row.status) }}</t-tag>
|
||||
</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="taskPage" v-model:page-size="taskPageSize" :total="taskTotal" />
|
||||
<t-empty v-if="!tasks.length" description="暂无学习任务,课程发布后将自动生成" />
|
||||
</div>
|
||||
|
||||
@@ -38,7 +39,7 @@
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的考试成绩</span>
|
||||
</div>
|
||||
<t-table :data="myRecords" :columns="myRecordColumns" row-key="id" size="small" :loading="loading">
|
||||
<t-table :data="pagedMyRecords" :columns="myRecordColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #course_name="{ row }">{{ row.course_name || row.paper_name || '-' }}</template>
|
||||
<template #score="{ row }">
|
||||
<span :class="passClass(row)">{{ row.score ?? '—' }}</span>
|
||||
@@ -46,6 +47,7 @@
|
||||
<template #pass_line="{ row }">{{ row.pass_score || '-' }} / {{ row.total_score || '-' }}</template>
|
||||
<template #submitted_at="{ row }">{{ fmtTime(row.submitted_at) }}</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="myRecordPage" v-model:page-size="myRecordPageSize" :total="myRecordTotal" />
|
||||
<t-empty v-if="!myRecords.length" description="暂无考试记录,参加随堂考试后此处展示成绩" />
|
||||
</div>
|
||||
|
||||
@@ -53,7 +55,7 @@
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">我的错题本</span>
|
||||
</div>
|
||||
<t-table :data="wrongBook" :columns="wrongColumns" row-key="id" size="small">
|
||||
<t-table :data="pagedWrongBook" :columns="wrongColumns" row-key="id" size="small">
|
||||
<template #knowledge_point="{ row }">
|
||||
<t-tag v-if="row.knowledge_point" variant="light" size="small">{{ row.knowledge_point }}</t-tag>
|
||||
<span v-else>—</span>
|
||||
@@ -64,6 +66,7 @@
|
||||
</t-tag>
|
||||
</template>
|
||||
</t-table>
|
||||
<TrainingPagination v-model:current="wrongPage" v-model:page-size="wrongPageSize" :total="wrongTotal" />
|
||||
<t-empty v-if="!wrongBook.length" description="错题本为空,继续保持" />
|
||||
</div>
|
||||
|
||||
@@ -144,6 +147,8 @@ import { fmtBeijingTime } from '@/utils/datetime'
|
||||
import CourseLearningStatus from './CourseLearningStatus.vue'
|
||||
import ExamPanel from './ExamPanel.vue'
|
||||
import CourseAIAnalysis from './CourseAIAnalysis.vue'
|
||||
import TrainingPagination from './TrainingPagination.vue'
|
||||
import { useTrainingPager } from './useTrainingPager'
|
||||
|
||||
const props = defineProps<{ roles: string[]; admin?: boolean }>()
|
||||
// 课程学习/考试情况管理端:人事/课长/讲师(roles 已按权限组展开,经理自动命中)
|
||||
@@ -228,6 +233,11 @@ const taskText = (s: string) => ({ pending: '待学习', doing: '学习中', don
|
||||
const taskTheme = (s: string) => ({ pending: 'default', doing: 'primary', done: 'success', overdue: 'danger' }[s] || 'default')
|
||||
const fmtTime = (raw: string | null) => fmtBeijingTime(raw) || '—'
|
||||
|
||||
// 四宫格列表分页(000163):学习任务/考试成绩/错题本默认每页 15 条
|
||||
const { page: taskPage, pageSize: taskPageSize, total: taskTotal, paged: pagedTasks } = useTrainingPager(tasks)
|
||||
const { page: myRecordPage, pageSize: myRecordPageSize, total: myRecordTotal, paged: pagedMyRecords } = useTrainingPager(myRecords)
|
||||
const { page: wrongPage, pageSize: wrongPageSize, total: wrongTotal, paged: pagedWrongBook } = useTrainingPager(wrongBook)
|
||||
|
||||
const passClass = (row: MyExamRecord) => {
|
||||
if (row.score == null) return ''
|
||||
return row.pass_score ? (row.score >= row.pass_score ? 'tone-good' : 'tone-bad') : ''
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<!-- 企业培训共用分页条:所有列表页统一挂载,默认每页 15 条 -->
|
||||
<div v-if="total > 0" class="training-pagination">
|
||||
<span class="training-pagination__total">共 {{ total }} 条</span>
|
||||
<t-pagination
|
||||
v-model="current"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
size="small"
|
||||
:show-jumper="false"
|
||||
show-page-number
|
||||
:show-page-size="total > TRAINING_PAGE_SIZE"
|
||||
:page-size-options="TRAINING_PAGE_SIZE_OPTIONS"
|
||||
:disabled="disabled"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { TRAINING_PAGE_SIZE, TRAINING_PAGE_SIZE_OPTIONS } from './useTrainingPager'
|
||||
|
||||
// 共用分页组件(000163):企业培训各列表页统一口径 —— 默认每页 15 条,
|
||||
// 页码/每页条数由父组件经 useTrainingPager 提供并做客户端切片。
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
total: number
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{ disabled: false },
|
||||
)
|
||||
|
||||
const current = defineModel<number>('current', { default: 1 })
|
||||
const pageSize = defineModel<number>('pageSize', { default: TRAINING_PAGE_SIZE })
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.training-pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
margin-top: 12px;
|
||||
|
||||
&__total {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -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<T>(source: Ref<T[]> | (() => T[])) {
|
||||
const page = ref(1)
|
||||
const pageSize = ref(TRAINING_PAGE_SIZE)
|
||||
|
||||
const list = computed<T[]>(() => (typeof source === 'function' ? source() : source.value))
|
||||
const total = computed(() => list.value.length)
|
||||
const paged = computed<T[]>(() => {
|
||||
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 }
|
||||
}
|
||||
Reference in new issue
Block a user