我的收藏列表+富文本处理

This commit is contained in:
BAKEYi 2026-06-02 18:21:35 +08:00
parent ea6ad65b86
commit 753c9932aa
2 changed files with 24 additions and 14 deletions

View File

@ -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>

View File

@ -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) {