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

184 lines
4.0 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">
2026-02-03 15:42:32 +08:00
<view class="module-title">健康宣教</view>
<view v-if="total > 3" class="flex items-center" @click="toMorePage()">
2026-02-03 09:59:49 +08:00
<view class="mr-5 text-base text-gray">更多</view>
2026-02-03 15:42:32 +08:00
<image class="arrow-icon" src="/static/home/arrow-right-gray.png" mode="aspectFit"></image>
2026-02-03 09:59:49 +08:00
</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"
2026-02-03 15:42:32 +08:00
class="article-card flex"
:class="{ 'mb-15': index < articles.length - 1 }"
@click="goToDetail(article)"
>
<image
class="flex-shrink-0 cover"
:src="article.cover || '/static/home/health-education.png'"
mode="aspectFill"
/>
2026-01-20 19:36:49 +08:00
<view class="w-0 flex-grow">
2026-02-03 15:42:32 +08:00
<view class="article-title truncate mb-10">
2026-01-20 19:36:49 +08:00
{{ article.title }}
</view>
2026-02-03 15:42:32 +08:00
<view v-if="article.summary" class="article-summary line-clamp-2">
2026-01-20 19:36:49 +08:00
{{ article.summary }}
</view>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, watch } from "vue";
2026-01-20 19:36:49 +08:00
import api from '@/utils/api';
const props = defineProps({
team: {
type: Object,
default: () => ({})
}
})
const articles = ref([]);
const total = ref(0);
const page = ref(1);
const pageSize = ref(3);
const loading = ref(false);
2026-01-20 19:36:49 +08:00
function goToDetail(article) {
if (!article?._id) return;
uni.navigateTo({ url: `/pages/article/article-detail?id=${article._id}` });
2026-01-20 19:36:49 +08:00
}
const loadArticles = async (reset = false) => {
const corpId = props.team?.corpId || "";
if (!corpId || loading.value) return;
if (reset) {
page.value = 1;
articles.value = [];
total.value = 0;
}
loading.value = true;
try {
const params = {
corpId,
page: page.value,
pageSize: pageSize.value,
enable: true,
};
const res = await api("getArticleList", params, false);
const list = res && Array.isArray(res.list) ? res.list : [];
total.value = Number(res?.total) || 0;
if (page.value === 1) articles.value = list;
else articles.value = [...articles.value, ...list];
} catch (err) {
console.error("loadArticles failed:", err);
} finally {
loading.value = false;
}
};
function toMorePage() {
const corpId = props.team?.corpId || "";
if (!corpId) return;
uni.navigateTo({ url: `/pages/article/article-cate-list?corpId=${corpId}` });
2026-01-20 19:36:49 +08:00
}
watch(
() => props.team?.corpId,
async (corpId) => {
if (!corpId) {
articles.value = [];
total.value = 0;
page.value = 1;
pageSize.value = 3;
return;
}
pageSize.value = 3;
await loadArticles(true);
},
{ immediate: true }
);
2026-01-20 19:36:49 +08:00
</script>
<style scoped>
2026-02-03 09:59:49 +08:00
.article-container {
margin: 0 30rpx;
margin-top: 24rpx;
padding-bottom: 40rpx;
width: calc(100% - 60rpx);
box-sizing: border-box;
2026-02-03 09:59:49 +08:00
}
.arrow-icon {
width: 32rpx;
height: 32rpx;
}
2026-02-03 15:42:32 +08:00
.module-title {
color: #000000;
font-size: 36rpx;
font-style: normal;
font-weight: 600;
line-height: normal;
}
2026-02-03 09:59:49 +08:00
.article-card {
background: white;
border-radius: 16rpx;
2026-02-03 15:42:32 +08:00
box-shadow: 0 8rpx 10rpx 0 rgba(60, 169, 145, 0.06);
2026-02-03 09:59:49 +08:00
transition: all 0.3s;
2026-02-03 15:42:32 +08:00
min-height: 188rpx;
padding: 20rpx;
align-items: flex-start;
width: 100%;
box-sizing: border-box;
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-02-03 15:42:32 +08:00
width: 272rpx;
height: 151rpx;
2026-02-03 09:59:49 +08:00
border-radius: 12rpx;
2026-02-03 15:42:32 +08:00
margin-right: 20rpx;
2026-02-03 09:59:49 +08:00
object-fit: cover;
}
.mb-15 {
margin-bottom: 20rpx;
}
2026-02-03 15:42:32 +08:00
.article-title {
color: #333333;
font-size: 32rpx;
font-weight: 500;
line-height: normal;
}
.article-summary {
max-width: 402rpx;
color: #666666;
text-align: justify;
font-size: 28rpx;
font-weight: 400;
line-height: normal;
}
2026-02-03 09:59:49 +08:00
.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>