| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <template>
- <view class="rec-section">
- <view class="rec-header">
- <view class="rec-header-left">
- <text class="rec-icon">📖</text>
- <text class="rec-title">推荐阅读</text>
- </view>
- <text class="rec-more" @click="$emit('moreArticles')">更多 ›</text>
- </view>
- <!-- 无数据 -->
- <view v-if="!displayArticles || displayArticles.length === 0" class="rec-empty">
- <text class="rec-empty-text">{{ isLoggedIn ? '暂无阅读推荐' : '登录后查看更多文章' }}</text>
- </view>
- <!-- 卡片列表 -->
- <view v-else class="rec-list">
- <view
- class="rec-card"
- v-for="(article, idx) in displayArticles"
- :key="article.id || idx"
- @click="$emit('articleClick', article)"
- >
- <!-- 封面图(可选) -->
- <view class="rec-card-cover" v-if="article.coverImage">
- <image class="rec-cover-img" :src="article.coverImage" mode="aspectFill" />
- <view class="rec-cover-dim" :style="{ background: article.categoryColor || gradient(idx) }">{{ article.category || '推荐文章' }}</view>
- </view>
- <!-- 文字区 -->
- <view class="rec-card-body" :class="{ 'rec-card-body-no-cover': !article.coverImage }">
- <view class="rec-category-row" v-if="!article.coverImage">
- <text class="rec-category-tag" :style="{ background: article.categoryColor || gradient(idx) }">{{ article.category || '推荐文章' }}</text>
- </view>
- <text class="rec-card-title">{{ article.title }}</text>
- <text class="rec-card-desc" v-if="article.summary">{{ article.summary }}</text>
- <view class="rec-card-foot">
- <text class="rec-card-date" v-if="article.date">{{ article.date }}</text>
- <view class="rec-card-stats">
- <text class="rec-stat">👁 {{ article.views || '0' }}</text>
- <text class="rec-stat">❤ {{ article.likes || '0' }}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- var defaultGradients = [
- 'linear-gradient(135deg, #10B981, #34D399)',
- 'linear-gradient(135deg, #059669, #10B981)',
- 'linear-gradient(135deg, #047857, #059669)',
- 'linear-gradient(135deg, #34D399, #6EE7B7)',
- 'linear-gradient(135deg, #10B981, #A7F3D0)'
- ]
- export default {
- name: 'ActionArticleRecommend',
- props: {
- articles: { type: Array, default: function() { return [] } },
- isLoggedIn: { type: Boolean, default: false }
- },
- computed: {
- displayArticles: function() {
- return this.articles && this.articles.length ? this.articles : []
- }
- },
- methods: {
- gradient: function(idx) {
- return defaultGradients[idx % defaultGradients.length]
- }
- }
- }
- </script>
- <style scoped>
- .rec-section {
- margin: 20rpx 20rpx 12rpx;
- }
- .rec-header {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 16rpx;
- padding: 0 4rpx;
- }
- .rec-header-left {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .rec-icon {
- font-size: 34rpx;
- margin-right: 10rpx;
- }
- .rec-title {
- font-size: 32rpx;
- font-weight: 700;
- color: #065F46;
- letter-spacing: 1rpx;
- }
- .rec-more {
- font-size: 24rpx;
- color: #10B981;
- font-weight: 500;
- }
- /* 空状态 */
- .rec-empty {
- display: flex;
- justify-content: center;
- padding: 60rpx 0;
- }
- .rec-empty-text {
- font-size: 24rpx;
- color: #9CA3AF;
- }
- /* 卡片列表 */
- .rec-list {
- display: flex;
- flex-direction: column;
- }
- .rec-card {
- background: #FFFFFF;
- border-radius: 24rpx;
- overflow: hidden;
- box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.08);
- margin-bottom: 20rpx;
- }
- .rec-card:active {
- opacity: 0.92;
- transform: scale(0.985);
- }
- /* 封面图 */
- .rec-card-cover {
- position: relative;
- width: 100%;
- height: 260rpx;
- background: #f0f0f0;
- }
- .rec-cover-img {
- width: 100%;
- height: 100%;
- }
- .rec-cover-dim {
- position: absolute;
- bottom: 0;
- left: 0;
- right: 0;
- padding: 10rpx 20rpx;
- background: rgba(0,0,0,0.45);
- }
- .rec-cover-dim text {
- font-size: 20rpx;
- color: #fff;
- font-weight: 500;
- }
- /* 文字内容区 */
- .rec-card-body {
- padding: 24rpx 24rpx 20rpx;
- }
- .rec-card-body-no-cover {
- padding-top: 28rpx;
- }
- .rec-category-row {
- margin-bottom: 12rpx;
- }
- .rec-category-tag {
- display: inline-block;
- font-size: 20rpx;
- color: #FFFFFF;
- font-weight: 500;
- padding: 4rpx 20rpx;
- border-radius: 20rpx;
- }
- .rec-card-title {
- font-size: 28rpx;
- font-weight: 700;
- color: #1F2937;
- line-height: 1.45;
- display: block;
- margin-bottom: 8rpx;
- }
- .rec-card-desc {
- font-size: 24rpx;
- color: #6B7280;
- line-height: 1.55;
- display: block;
- margin-bottom: 16rpx;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .rec-card-foot {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- }
- .rec-card-date {
- font-size: 22rpx;
- color: #9CA3AF;
- }
- .rec-card-stats {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .rec-stat {
- font-size: 22rpx;
- color: #9CA3AF;
- margin-left: 20rpx;
- }
- </style>
|