cankao-h5/src/components/RankListMini.vue

259 lines
5.4 KiB
Vue
Raw Normal View History

2025-08-13 12:18:25 +08:00
<template>
<view class="news-rank-list">
<u-skeleton rows="5" title loading style="margin-bottom: 30rpx" v-if="loading"></u-skeleton>
<view class="list" v-else>
<view v-for="(item, index) in rankListLocal" :key="index" class="news-item" @click="goDetail(item, 0)">
<view class="rank-tag">
<text class="rank-text">{{ index + 1 }}</text>
</view>
<!-- :style="{ filter: Session.get('token') ? '' : 'blur(5px)' }" -->
<view class="news-content">
<text class="news-title">{{ item.title }}</text>
<text class="news-desc">{{ item.summary }}</text>
<view class="news-meta">
<view>
<text class="source">{{ item.source }}</text>
<text class="time">{{
dayjs(item.publish_time).format("YYYY-MM-DD HH:MM:ss")
}}</text>
</view>
<text class="score">
<text v-if="index < 3">资讯评分</text>
{{ item.news_score }}</text>
</view>
</view>
</view>
</view>
<view @click="isExp = !isExp" class="r_exp">
<text v-if="isExp">收起</text>
<text v-else>展开全部</text>
<img src="https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/up_icon.png" class="exp_up" v-if="isExp" />
<img src="https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/down_icon.png" class="exp_up" v-else />
</view>
<LoginPopup :show="LoginShow" @handlePopupClose="handlePopupClose"
@handlePopupSuccessCallback="handlePopupSuccessCallback" @handlePopupErrorCallback="handlePopupErrorCallback" />
</view>
</template>
<script setup lang="ts">
import { ref, watch } from "vue";
import dayjs from "dayjs/esm/index";
import LoginPopup from "@/components/loginPopup/index.vue";
import { Session } from "@/utils/storage";
const isExp = ref(false);
const rankListLocal = ref([]);
const loading = ref(true);
watch(
() => isExp.value,
(newValue, oldValue) => {
rankListLocal.value = [];
props.newsList.forEach((item, index) => {
if (!isExp.value && index > 9) {
return;
}
rankListLocal.value.push(item);
});
loading.value = false;
}
);
watch(
() => props.newsList,
(newValue, oldValue) => {
rankListLocal.value = [];
props.newsList.forEach((item, index) => {
if (!isExp.value && index > 9) {
return;
}
rankListLocal.value.push(item);
});
loading.value = false;
}
);
// 接收父组件传入的新闻列表
const props = defineProps({
newsList: {
type: Array,
required: true,
default: () => [],
},
});
const clickItem = ref({});
function goDetail(item) {
if (Session.get("token")) {
clickItem.value = item;
uni.navigateTo({
url: `/pages/detail/indexNewsInfo?id=${item.news_id}`,
});
} else {
LoginShow.value = true;
}
}
const LoginShow = ref(false);
const isLoginStatus = ref();
// 关闭弹框
const handlePopupClose = () => {
LoginShow.value = false;
};
// 登录成功之后的回调
const handlePopupSuccessCallback = () => {
isLoginStatus.value = true;
// uni.navigateTo({
// url: `/pages/detail/indexNewsInfo?id=${clickItem.value.news_id}`,
// });
};
// 登录失败之后的回调
const handlePopupErrorCallback = () => {
console.log("登录失败");
};
</script>
<style scoped lang="scss">
.news-rank-list {
padding: 10px;
}
.list {
min-height: 700rpx;
}
.news-item {
display: flex;
align-items: flex-start;
margin-bottom: 15px;
border-bottom: 1px solid #f2f2f2;
padding-bottom: 10px;
}
.rank-tag {
width: 30px;
height: 30px;
border-radius: 4px;
display: flex;
justify-content: center;
align-items: center;
margin-right: 10px;
}
.rank-text-top3 {
font-family: PingFangSC, PingFang SC;
font-weight: 500;
font-size: 24rpx;
color: #ffffff;
line-height: 33rpx;
text-shadow: 0px 0px 2px #deb72b;
text-align: left;
font-style: normal;
img {
width: 33rpx;
height: 41rpx;
margin-top: -10rpx;
}
}
.rank-text {
font-family: PingFangSC, PingFang SC;
font-weight: bold;
font-size: 28rpx;
color: #e98254;
margin-top: -20rpx;
}
.news-content {
flex: 1;
display: flex;
flex-direction: column;
}
.news-title {
font-size: 16px;
font-weight: bold;
color: #333;
margin-bottom: 5px;
line-height: 1.2;
}
.news-desc {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 24rpx;
color: #333333;
text-align: left;
font-style: normal;
display: -webkit-box;
/* 设置为WebKit内核的弹性盒子模型 */
-webkit-box-orient: vertical;
/* 垂直排列 */
-webkit-line-clamp: 2;
/* 限制显示三行 */
overflow: hidden;
/* 隐藏超出范围的内容 */
text-overflow: ellipsis;
/* 使用省略号 */
}
.news-meta {
display: flex;
justify-content: space-between;
font-size: 12px;
color: #999;
margin-top: 10rpx;
}
.source,
.time,
.score {
// opacity: 0.8;
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 22rpx;
color: #999999;
line-height: 30rpx;
text-align: left;
font-style: normal;
}
.time {
margin-left: 10rpx;
}
.score {
font-family: PingFangSC, PingFang SC;
font-weight: 500;
font-size: 22rpx;
color: #ffa800;
line-height: 30rpx;
text-align: center;
font-style: normal;
}
.exp_up {
width: 21rpx;
height: 20rpx;
}
.r_exp {
display: flex;
text-align: center;
justify-content: center;
align-items: center;
gap: 10rpx;
}
</style>