ykt-team-wxapp/pages/home/article-list.vue

111 lines
2.9 KiB
Vue
Raw Normal View History

2026-01-20 19:36:49 +08:00
<template>
2026-02-03 09:59:49 +08:00
<view v-if="articles.length" class="article-container">
<view class="flex items-center justify-between">
<view class="text-lg font-semibold text-dark">健康宣教</view>
<view class="flex items-center" @click="toList()">
<view class="mr-5 text-base text-gray">更多</view>
<image class="arrow-icon" src="/static/home/右箭头-灰色.png" mode="aspectFit"></image>
</view>
2026-01-20 19:36:49 +08:00
</view>
2026-02-03 09:59:49 +08:00
<view class="mt-10">
<view v-for="(article, index) in articles" :key="article._id"
class="article-card flex px-20 py-20"
:class="{'mb-15': index < articles.length - 1}">
2026-02-03 10:45:54 +08:00
<image class="flex-shrink-0 mr-15 cover" :src="article.cover || '/static/home/健康宣教.png'" mode="aspectFill" />
2026-01-20 19:36:49 +08:00
<view class="w-0 flex-grow">
2026-02-03 09:59:49 +08:00
<view class="text-base leading-normal font-semibold truncate mb-10 text-dark">
2026-01-20 19:36:49 +08:00
{{ article.title }}
</view>
2026-02-03 09:59:49 +08:00
<view v-if="article.summary" class="text-sm text-gray line-clamp-2">
2026-01-20 19:36:49 +08:00
{{ article.summary }}
</view>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { computed, ref, watch } from 'vue';
import api from '@/utils/api';
const props = defineProps({
team: {
type: Object,
default: () => ({})
}
})
const articles = ref([])
const qrcode = computed(() => {
const qrcodes = props.team && Array.isArray(props.team.qrcodes) ? props.team.qrcodes : [];
return qrcodes[0] || {}
})
const articleIds = computed(() => {
const articles = qrcode.value && Array.isArray(qrcode.value.articles) ? qrcode.value.articles : [];
const ids = articles.map(item => item._id).filter(i => typeof i === 'string' && i.trim());
return qrcode.value.enableAnnounce === 'YES' ? ids : [];
})
function toList() {
uni.navigateTo({ url: `/pages/article/article-list?corpId=${props.team.corpId}&ids=${articleIds.value.join()}` })
}
async function getArticles() {
const res = await api('getArticleByIds', { corpId: props.team.corpId, ids: articleIds.value.join() });
articles.value = res && Array.isArray(res.list) ? res.list : [];
}
watch(articleIds, n => {
if (n.length) {
getArticles()
} else {
articles.value = []
}
}, { immediate: true })
</script>
<style scoped>
2026-02-03 09:59:49 +08:00
.article-container {
margin: 0 30rpx;
margin-top: 24rpx;
padding-bottom: 40rpx;
}
.arrow-icon {
width: 32rpx;
height: 32rpx;
}
.article-card {
background: white;
border-radius: 16rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
transition: all 0.3s;
2026-02-03 10:45:54 +08:00
min-height: 168rpx;
align-items: center;
2026-01-20 19:36:49 +08:00
}
2026-02-03 09:59:49 +08:00
.article-card:active {
transform: translateY(-2rpx);
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
2026-01-20 19:36:49 +08:00
}
2026-02-03 09:59:49 +08:00
.cover {
2026-01-20 19:36:49 +08:00
width: 160rpx;
2026-02-03 10:45:54 +08:00
height: 128rpx;
2026-02-03 09:59:49 +08:00
border-radius: 12rpx;
object-fit: cover;
}
.mb-15 {
margin-bottom: 20rpx;
}
.line-clamp-2 {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp: 2;
overflow: hidden;
line-height: 1.5;
2026-01-20 19:36:49 +08:00
}
</style>