fix: 修复课程库加载 - 后端限制每页最多100条
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -662,8 +662,27 @@ const loadPositions = async () => {
|
||||
const loadCourses = async () => {
|
||||
coursesLoading.value = true
|
||||
try {
|
||||
const res = await getManagerCourses({ page: 1, size: 500 })
|
||||
courses.value = res.data?.items || res.items || []
|
||||
// 后端限制每页最多100条,需要分页获取所有课程
|
||||
let allCourses: Course[] = []
|
||||
let page = 1
|
||||
const pageSize = 100
|
||||
let hasMore = true
|
||||
|
||||
while (hasMore) {
|
||||
const res = await getManagerCourses({ page, size: pageSize })
|
||||
const items = res.data?.items || res.items || []
|
||||
allCourses = [...allCourses, ...items]
|
||||
|
||||
// 检查是否还有更多数据
|
||||
const total = res.data?.total || res.total || 0
|
||||
hasMore = allCourses.length < total && items.length === pageSize
|
||||
page++
|
||||
|
||||
// 安全限制:最多获取10页(1000门课程)
|
||||
if (page > 10) break
|
||||
}
|
||||
|
||||
courses.value = allCourses
|
||||
} catch (error) {
|
||||
console.error('加载课程失败:', error)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user