This commit is contained in:
zpc 2025-06-25 13:15:38 +08:00
parent db374522f7
commit cb66a1b7d4

View File

@ -57,207 +57,222 @@
</template> </template>
<script> <script>
import { getNewsDetail, addFavorite, cancelFavorite } from '@/common/server/news'; import {
import { sleep } from '@/common/utils'; getNewsDetail,
export default { addFavorite,
data() { cancelFavorite
return { } from '@/common/server/news';
title: "", import {
content: "", sleep
publish_time: "", } from '@/common/utils';
author_name: "", export default {
follow: false, data() {
showNotData: false, return {
options: {}, title: "",
next_data: null, content: "",
prev_data: null, publish_time: "",
recommend_news: [] author_name: "",
} follow: false,
}, showNotData: false,
computed: { options: {},
follow_image() { next_data: null,
return this.follow ? "/static/app-plus/news/guanzhu.png" : "/static/app-plus/news/no-guanzhu.png"; prev_data: null,
} recommend_news: []
}, }
async onLoad(options) { },
this.options = options; computed: {
this.title = ""; follow_image() {
this.getNewsDetail(options.id, options.current); return this.follow ? "/static/app-plus/news/guanzhu.png" : "/static/app-plus/news/no-guanzhu.png";
}
},
async onLoad(options) {
this.options = options;
this.title = "";
this.getNewsDetail(options.id, options.current);
},
methods: {
async onFollow() {
if (!yds.userInfo.isAccountLogin()) {
yds.showToast("请登录后在收藏!");
return;
}
this.follow = !this.follow;
if (this.follow) {
await addFavorite(this.options.id);
} else {
await cancelFavorite(this.options.id);
}
}, },
async onRefresh(paging) { methods: {
console.log("onRefreshonRefreshonRefreshonRefresh"); async onFollow() {
await this.getNewsDetail(this.options.id, this.options.current); if (!yds.userInfo.isAccountLogin()) {
await sleep(500); yds.showToast("请登录后在收藏!");
paging.complete(); return;
}, }
async goToNews(item) { this.follow = !this.follow;
this.options.id = item.id; if (this.follow) {
await this.getNewsDetail(item.id, this.options.current); await addFavorite(this.options.id);
this.$refs.pageContainer.getPaging().scrollToTop(); } else {
}, await cancelFavorite(this.options.id);
getTitle(title) { }
return title.length > 10 ? title.slice(0, 10) + "..." : title; },
}, async onRefresh(paging) {
async getNewsDetail(id, current) { console.log("onRefreshonRefreshonRefreshonRefresh");
const res = await getNewsDetail(id, current); await this.getNewsDetail(this.options.id, this.options.current);
console.log("resresresres", res); await sleep(500);
if (res) { paging.complete();
this.title = res.title; },
this.content = res.content; async goToNews(item) {
this.publish_time = res.publish_time; this.options.id = item.id;
this.author_name = res.author_name; await this.getNewsDetail(item.id, this.options.current);
this.next_data = res.next_data; this.$refs.pageContainer.getPaging().scrollToTop();
this.prev_data = res.prev_data; },
this.recommend_news = res.recommend_news; getTitle(title) {
this.follow = res.user_follow; return title.length > 10 ? title.slice(0, 10) + "..." : title;
} else { },
this.showNotData = true; async getNewsDetail(id, current) {
} const res = await getNewsDetail(id, current);
console.log("resresresres", res);
if (res) {
this.title = res.title;
this.content = res.content;
this.publish_time = res.publish_time;
this.author_name = res.author_name;
this.next_data = res.next_data;
this.prev_data = res.prev_data;
this.recommend_news = res.recommend_news;
this.follow = res.user_follow;
} else {
this.showNotData = true;
}
}
} }
} }
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.news-details { .news-details {
padding: 30rpx 10rpx;
min-height: 70vh;
&__title {
text-align: center;
font-size: 32rpx;
font-weight: bold;
color: #333;
}
&__time {
margin-top: 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 10rpx;
&-left {
font-size: 24rpx;
color: #999;
}
&-right {
display: flex;
align-items: center;
padding-right: 20rpx;
}
}
&__content {
padding: 30rpx 10rpx; padding: 30rpx 10rpx;
min-height: 70vh;
} &__title {
text-align: center;
&__follow {
width: 90%;
text-align: right;
}
&__footer {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 10rpx;
&-item {
padding-left: 20rpx;
padding-right: 20rpx;
height: 70rpx;
display: flex;
align-items: center;
justify-content: center;
}
}
&__recommend_news {
margin-top: 30rpx;
padding: 0 20rpx;
&-title {
font-size: 32rpx; font-size: 32rpx;
font-weight: bold; font-weight: bold;
margin-bottom: 20rpx;
color: #333; color: #333;
} }
&-list { &__time {
margin-top: 20rpx;
display: flex; display: flex;
flex-direction: column; justify-content: space-between;
gap: 20rpx; align-items: center;
padding: 0 10rpx;
&-left {
font-size: 24rpx;
color: #999;
}
&-right {
display: flex;
align-items: center;
padding-right: 20rpx;
}
} }
&-item { &__content {
padding: 30rpx 10rpx;
}
&__follow {
width: 90%;
text-align: right;
}
&__footer {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 10rpx;
&-item {
padding-left: 20rpx;
padding-right: 20rpx;
height: 70rpx;
display: flex;
align-items: center;
justify-content: center;
}
}
&__recommend_news {
margin-top: 30rpx;
padding: 0 20rpx;
&-title {
font-size: 32rpx;
font-weight: bold;
margin-bottom: 20rpx;
color: #333;
}
&-list {
display: flex;
flex-direction: column;
gap: 20rpx;
}
&-item {
display: flex;
flex-direction: row;
align-items: center;
padding: 16rpx;
background-color: #f9f9f9;
border-radius: 12rpx;
&-image {
width: 160rpx;
height: 120rpx;
margin-right: 20rpx;
image {
width: 100%;
height: 100%;
border-radius: 8rpx;
}
}
&-content {
flex: 1;
text {
font-size: 28rpx;
color: #333;
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
}
}
}
.flex-row {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
padding: 16rpx; gap: 8rpx;
background-color: #f9f9f9; }
border-radius: 12rpx;
&-image { //
width: 160rpx; ::v-deep rich-text img {
height: 120rpx; max-width: 95% !important;
margin-right: 20rpx; border-radius: 10rpx;
height: auto !important;
display: block !important;
margin: 0 auto;
}
image { //
width: 100%; ::v-deep rich-text p {
height: 100%; margin: 20rpx 10rpx;
border-radius: 8rpx; }
}
}
&-content { ::v-deep rich-text div {
flex: 1; margin: 20rpx 10rpx;
text {
font-size: 28rpx;
color: #333;
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
}
} }
} }
.flex-row {
display: flex;
flex-direction: row;
align-items: center;
gap: 8rpx;
}
//
::v-deep rich-text img {
max-width: 95% !important;
border-radius: 10rpx;
height: auto !important;
display: block !important;
margin: 0 auto;
}
}
</style> </style>