From 753c9932aae0b0cc8c98dc61b8a92cc85e5bc6f6 Mon Sep 17 00:00:00 2001 From: BAKEYi <16298417+bakeyi@user.noreply.gitee.com> Date: Tue, 2 Jun 2026 18:21:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E6=94=B6=E8=97=8F=E5=88=97?= =?UTF-8?q?=E8=A1=A8+=E5=AF=8C=E6=96=87=E6=9C=AC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/jingxuan/brand-detail.vue | 2 +- pages/my/myFavorite.vue | 36 +++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/pages/jingxuan/brand-detail.vue b/pages/jingxuan/brand-detail.vue index e972eac..2fc93d5 100644 --- a/pages/jingxuan/brand-detail.vue +++ b/pages/jingxuan/brand-detail.vue @@ -72,7 +72,7 @@ 品牌介绍 - {{ info.detail || '暂无品牌介绍' }} + {{ isExpanded ? '收起查看' : '展开查看' }} diff --git a/pages/my/myFavorite.vue b/pages/my/myFavorite.vue index d6274da..094dbde 100644 --- a/pages/my/myFavorite.vue +++ b/pages/my/myFavorite.vue @@ -332,13 +332,15 @@ export default { // ============ 真实接口调用 ============ async fetchRealBrandList() { try { - const res = await request.post('/sj/brand/list', { page: 1, limit: 100 }) + // 1. 接口路径换成真实的品牌收藏列表 + const res = await request.post('/sj/brand/collectList', { page: 1, limit: 100 }) + if ((res.code === 200 || res.state === 1) && res.data && res.data.list) { - const collectedBrands = res.data.list.filter(item => item.collect_state === 1) - this.rawBrandList = collectedBrands.map(item => { + // 2. 不需要前端再做 filter(item => item.collect_state === 1) 了,直接用! + this.rawBrandList = res.data.list.map(item => { let tags = [] - if (item.franchise_state === 1) tags.push('franchise') - if (item.student_state === 1) tags.push('recruit') + if (item.franchise_state == 1) tags.push('franchise') + if (item.student_state == 1) tags.push('recruit') if (tags.length === 0) tags.push('more') return { @@ -347,33 +349,39 @@ export default { bgSrc: item.cover_img || 'https://mrrplus.oss-cn-beijing.aliyuncs.com/photo/system/default.jpg', avatar: item.logo_img || 'https://dummyimage.com/100x100/ccc/fff.png&text=Avatar', tagKeys: tags, - secondClassIds: item.second_class_ids ? item.second_class_ids.split(',').map(Number) : [] + // 3. 强制转字符串,防止后端返回纯数字导致 split 报错,同时兼容后端没返回此字段的情况 + secondClassIds: item.second_class_ids ? String(item.second_class_ids).split(',').map(Number) : [] } }) + console.log('成功获取品牌收藏列表:', this.rawBrandList) } else { this.rawBrandList = [] } } catch (error) { - console.error('获取品牌收藏失败', error) + console.error('获取品牌收藏失败详情:', error) } }, async fetchRealCourseList() { try { - const res = await request.post('/sj/skill/list', { page: 1, limit: 100 }) + // 1. 接口路径换成真实的技能收藏列表 + const res = await request.post('/sj/skill/collectList', { page: 1, limit: 100 }) + if ((res.code === 200 || res.state === 1) && res.data && res.data.list) { - const collectedCourses = res.data.list.filter(item => item.collect_state === 1) - this.rawCourseList = collectedCourses.map(item => { + // 2. 同样不需要 filter,直接 map 映射数据 + this.rawCourseList = res.data.list.map(item => { return { id: item.id, title: item.name, coverSrc: item.cover_img, - type: item.link_name || (item.link_type === 1 ? '平台课程' : '品牌课程'), + type: item.link_name || (item.link_type == 1 ? '平台课程' : '品牌课程'), link_type: item.link_type, views: item.browse_num || 0, + // 3. 使用安全的时间格式化 time: item.create_time ? this.formatTimeAgo(item.create_time) : '', typeIcon: item.link_logo || '' } }) + console.log('成功获取课程收藏列表:', this.rawCourseList) } else { this.rawCourseList = [] } @@ -383,13 +391,15 @@ export default { }, formatTimeAgo(timeStr) { + if (!timeStr) return ''; + const timeStrSafe = String(timeStr); const now = new Date() - const time = new Date(timeStr.replace(/-/g, '/')) + const time = new Date(timeStrSafe.replace(/-/g, '/')) const diff = Math.floor((now - time) / 1000) if (diff < 3600) return Math.floor(diff / 60) + '分钟前' if (diff < 86400) return Math.floor(diff / 3600) + '小时前' if (diff < 604800) return Math.floor(diff / 86400) + '天前' - return timeStr.split(' ')[0] + return timeStrSafe.split(' ')[0] }, goToBrandDetail(item) { if (item.id) {