fix: guard course list shape before filtering

Normalize find_all_courses response to an array and add page-level array fallback to prevent filter runtime errors when response payload is malformed.

Made-with: Cursor
This commit is contained in:
2026-04-28 00:12:09 +08:00
parent 9f2ba95b1f
commit 543cab9ea7
2 changed files with 10 additions and 2 deletions
+6 -1
View File
@@ -88,7 +88,12 @@ export default defineComponent({
};
const dataset = computed(() => {
return store.list.filter(x => (!x.created_by || x.created_by === usingUser.store.current.hty_id) && (!state.keyword || x.course_name.includes(state.keyword)));
const courseList = Array.isArray(store.list) ? store.list : [];
return courseList.filter(
(courseItem) =>
(!courseItem.created_by || courseItem.created_by === usingUser.store.current.hty_id) &&
(!state.keyword || courseItem.course_name.includes(state.keyword))
);
})
const add = () => {
+4 -1
View File
@@ -21,7 +21,10 @@ export default function useCourse() {
const {r, d, e} = await request({url: '/api/v1/ws/find_all_courses'});
load_done()
if (r) {
state.list = d;
state.list = Array.isArray(d) ? d : [];
if (!Array.isArray(d)) {
showFailToast('课程数据格式异常,已自动回退为空列表');
}
} else {
showFailToast(e);
}