我的收藏列表+富文本处理
This commit is contained in:
parent
ea6ad65b86
commit
753c9932aa
|
|
@ -72,7 +72,7 @@
|
||||||
<view class="intro-section" v-if="info.name">
|
<view class="intro-section" v-if="info.name">
|
||||||
<view class="section-title">品牌介绍</view>
|
<view class="section-title">品牌介绍</view>
|
||||||
<view class="intro-content" :class="{ 'is-expanded': isExpanded }">
|
<view class="intro-content" :class="{ 'is-expanded': isExpanded }">
|
||||||
<text class="intro-text">{{ info.detail || '暂无品牌介绍' }}</text>
|
<text v-html="info.detail || '暂无品牌介绍'" class="intro-text"></text>
|
||||||
</view>
|
</view>
|
||||||
<view class="expand-btn" @click="toggleExpand" v-if="info.detail && info.detail.length > 100">
|
<view class="expand-btn" @click="toggleExpand" v-if="info.detail && info.detail.length > 100">
|
||||||
<text class="expand-text">{{ isExpanded ? '收起查看' : '展开查看' }}</text>
|
<text class="expand-text">{{ isExpanded ? '收起查看' : '展开查看' }}</text>
|
||||||
|
|
|
||||||
|
|
@ -332,13 +332,15 @@ export default {
|
||||||
// ============ 真实接口调用 ============
|
// ============ 真实接口调用 ============
|
||||||
async fetchRealBrandList() {
|
async fetchRealBrandList() {
|
||||||
try {
|
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) {
|
if ((res.code === 200 || res.state === 1) && res.data && res.data.list) {
|
||||||
const collectedBrands = res.data.list.filter(item => item.collect_state === 1)
|
// 2. 不需要前端再做 filter(item => item.collect_state === 1) 了,直接用!
|
||||||
this.rawBrandList = collectedBrands.map(item => {
|
this.rawBrandList = res.data.list.map(item => {
|
||||||
let tags = []
|
let tags = []
|
||||||
if (item.franchise_state === 1) tags.push('franchise')
|
if (item.franchise_state == 1) tags.push('franchise')
|
||||||
if (item.student_state === 1) tags.push('recruit')
|
if (item.student_state == 1) tags.push('recruit')
|
||||||
if (tags.length === 0) tags.push('more')
|
if (tags.length === 0) tags.push('more')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -347,33 +349,39 @@ export default {
|
||||||
bgSrc: item.cover_img || 'https://mrrplus.oss-cn-beijing.aliyuncs.com/photo/system/default.jpg',
|
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',
|
avatar: item.logo_img || 'https://dummyimage.com/100x100/ccc/fff.png&text=Avatar',
|
||||||
tagKeys: tags,
|
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 {
|
} else {
|
||||||
this.rawBrandList = []
|
this.rawBrandList = []
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取品牌收藏失败', error)
|
console.error('获取品牌收藏失败详情:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async fetchRealCourseList() {
|
async fetchRealCourseList() {
|
||||||
try {
|
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) {
|
if ((res.code === 200 || res.state === 1) && res.data && res.data.list) {
|
||||||
const collectedCourses = res.data.list.filter(item => item.collect_state === 1)
|
// 2. 同样不需要 filter,直接 map 映射数据
|
||||||
this.rawCourseList = collectedCourses.map(item => {
|
this.rawCourseList = res.data.list.map(item => {
|
||||||
return {
|
return {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
title: item.name,
|
title: item.name,
|
||||||
coverSrc: item.cover_img,
|
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,
|
link_type: item.link_type,
|
||||||
views: item.browse_num || 0,
|
views: item.browse_num || 0,
|
||||||
|
// 3. 使用安全的时间格式化
|
||||||
time: item.create_time ? this.formatTimeAgo(item.create_time) : '',
|
time: item.create_time ? this.formatTimeAgo(item.create_time) : '',
|
||||||
typeIcon: item.link_logo || ''
|
typeIcon: item.link_logo || ''
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.log('成功获取课程收藏列表:', this.rawCourseList)
|
||||||
} else {
|
} else {
|
||||||
this.rawCourseList = []
|
this.rawCourseList = []
|
||||||
}
|
}
|
||||||
|
|
@ -383,13 +391,15 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
formatTimeAgo(timeStr) {
|
formatTimeAgo(timeStr) {
|
||||||
|
if (!timeStr) return '';
|
||||||
|
const timeStrSafe = String(timeStr);
|
||||||
const now = new Date()
|
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)
|
const diff = Math.floor((now - time) / 1000)
|
||||||
if (diff < 3600) return Math.floor(diff / 60) + '分钟前'
|
if (diff < 3600) return Math.floor(diff / 60) + '分钟前'
|
||||||
if (diff < 86400) return Math.floor(diff / 3600) + '小时前'
|
if (diff < 86400) return Math.floor(diff / 3600) + '小时前'
|
||||||
if (diff < 604800) return Math.floor(diff / 86400) + '天前'
|
if (diff < 604800) return Math.floor(diff / 86400) + '天前'
|
||||||
return timeStr.split(' ')[0]
|
return timeStrSafe.split(' ')[0]
|
||||||
},
|
},
|
||||||
goToBrandDetail(item) {
|
goToBrandDetail(item) {
|
||||||
if (item.id) {
|
if (item.id) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue