Files
guoxue-mp/pages/user/collect.vue
T
2026-03-25 15:59:24 +08:00

137 lines
2.8 KiB
Vue

<template>
<view class="collect-page">
<view v-if="loading" class="state-wrap">
<u-loading-icon mode="circle"></u-loading-icon>
</view>
<view v-else-if="articles.length" class="list-wrapper">
<view class="article-card" v-for="item in articles" :key="item.id" @click="goToDetail(item)">
<image class="cover" :src="item.article.image" mode="aspectFill"></image>
<view class="content">
<text class="title">{{ item.article.title }}</text>
<text class="desc">{{ item.article.source }}</text>
<!-- <view class="meta">-->
<!-- <text class="time">{{ item.time }}</text>-->
<!-- </view>-->
</view>
</view>
</view>
<view v-else class="state-wrap">
<u-empty mode="favor" text="暂无收藏"></u-empty>
</view>
</view>
</template>
<script>
import {listArticleCollectReq} from "@/api/common";
export default {
data() {
return {
articles: [],
loading: false,
defaultCover: '/static/icon/article_1.png'
}
},
onShow() {
this.fetchCollects()
},
onPullDownRefresh() {
this.fetchCollects()
},
methods: {
async fetchCollects() {
this.loading = true
try {
const {data} = await listArticleCollectReq()
const list = Array.isArray(data) ? data : []
this.articles = list
} catch (e) {
uni.showToast({title: '加载失败,请稍后重试', icon: 'none'})
} finally {
this.loading = false
uni.stopPullDownRefresh()
}
},
goToDetail(item) {
if (!item.articleId) {
uni.showToast({title: '文章信息缺失', icon: 'none'})
return
}
uni.navigateTo({
url: `/pages/index/detail?id=${item.articleId}`
})
}
}
}
</script>
<style lang="scss" scoped>
.collect-page {
min-height: 100vh;
padding: 30rpx;
box-sizing: border-box;
background: linear-gradient(180deg, #eef1ff 0%, #fdfdff 45%, #ffffff 100%);
}
.state-wrap {
min-height: 60vh;
display: flex;
align-items: center;
justify-content: center;
}
.list-wrapper {
display: flex;
flex-direction: column;
gap: 24rpx;
}
.article-card {
display: flex;
background: #ffffff;
border-radius: 30rpx;
padding: 24rpx;
box-shadow: 0 16rpx 40rpx rgba(79, 92, 190, 0.12);
}
.cover {
width: 200rpx;
height: 160rpx;
border-radius: 24rpx;
margin-right: 24rpx;
background: #f0f2ff;
}
.content {
flex: 1;
display: flex;
flex-direction: column;
}
.title {
font-size: 30rpx;
font-weight: 600;
color: #1f2140;
line-height: 1.4;
}
.desc {
margin-top: 10rpx;
font-size: 24rpx;
color: #7377a5;
line-height: 1.4;
max-height: 70rpx;
overflow: hidden;
}
.meta {
margin-top: auto;
font-size: 22rpx;
color: #a0a4c3;
display: flex;
justify-content: space-between;
}
</style>