优化:请求接口全局处理loading和错误提示

This commit is contained in:
2025-11-26 16:37:47 +08:00
24 changed files with 568 additions and 771 deletions

View File

@@ -52,30 +52,26 @@ const subCategoryList = ref<ICategory[]>([]) // 子级分类列表
* 获取分类下的子级分类
*/
const getSubCategoryList = async () => {
try {
let res: any = null
switch (subject.value) {
case '医学':
res = await courseSubjectClassificationApi.getCourseMedicalChildLabels(categoryId.value)
break
case '心理学':
res = await courseSubjectClassificationApi.getCourseSoulChildLabels(categoryId.value)
break
let res: any = null
switch (subject.value) {
case '医学':
res = await courseSubjectClassificationApi.getCourseMedicalChildLabels(categoryId.value)
break
case '心理学':
res = await courseSubjectClassificationApi.getCourseSoulChildLabels(categoryId.value)
break
}
if (res && res.code === 0) {
if (res.labels && res.labels.length > 0) {
subCategoryList.value = res.labels
// 默认选中第一个tab
tab_category_id.value = res.labels[0].id
radio_category_id.value = res.labels[0].children[0] && res.labels[0].children[0].id || 0
} else {
subCategoryList.value = []
tab_category_id.value = 0
radio_category_id.value = 0
}
if (res && res.code === 0) {
if (res.labels && res.labels.length > 0) {
subCategoryList.value = res.labels
// 默认选中第一个tab
tab_category_id.value = res.labels[0].id
radio_category_id.value = res.labels[0].children[0] && res.labels[0].children[0].id || 0
} else {
subCategoryList.value = []
tab_category_id.value = 0
radio_category_id.value = 0
}
}
} catch (error) {
console.error('获取分类下的子级分类失败:', error)
}
}