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>
<script>
import { getNewsDetail, addFavorite, cancelFavorite } from '@/common/server/news';
import { sleep } from '@/common/utils';
export default {
data() {
return {
title: "",
content: "",
publish_time: "",
author_name: "",
follow: false,
showNotData: false,
options: {},
next_data: null,
prev_data: null,
recommend_news: []
}
},
computed: {
follow_image() {
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);
import {
getNewsDetail,
addFavorite,
cancelFavorite
} from '@/common/server/news';
import {
sleep
} from '@/common/utils';
export default {
data() {
return {
title: "",
content: "",
publish_time: "",
author_name: "",
follow: false,
showNotData: false,
options: {},
next_data: null,
prev_data: null,
recommend_news: []
}
},
computed: {
follow_image() {
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) {
console.log("onRefreshonRefreshonRefreshonRefresh");
await this.getNewsDetail(this.options.id, this.options.current);
await sleep(500);
paging.complete();
},
async goToNews(item) {
this.options.id = item.id;
await this.getNewsDetail(item.id, this.options.current);
this.$refs.pageContainer.getPaging().scrollToTop();
},
getTitle(title) {
return title.length > 10 ? title.slice(0, 10) + "..." : title;
},
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;
}
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) {
console.log("onRefreshonRefreshonRefreshonRefresh");
await this.getNewsDetail(this.options.id, this.options.current);
await sleep(500);
paging.complete();
},
async goToNews(item) {
this.options.id = item.id;
await this.getNewsDetail(item.id, this.options.current);
this.$refs.pageContainer.getPaging().scrollToTop();
},
getTitle(title) {
return title.length > 10 ? title.slice(0, 10) + "..." : title;
},
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>
<style lang="scss" scoped>
.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 {
.news-details {
padding: 30rpx 10rpx;
min-height: 70vh;
}
&__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 {
&__title {
text-align: center;
font-size: 32rpx;
font-weight: bold;
margin-bottom: 20rpx;
color: #333;
}
&-list {
&__time {
margin-top: 20rpx;
display: flex;
flex-direction: column;
gap: 20rpx;
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;
}
}
&-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;
flex-direction: row;
align-items: center;
padding: 16rpx;
background-color: #f9f9f9;
border-radius: 12rpx;
gap: 8rpx;
}
&-image {
width: 160rpx;
height: 120rpx;
margin-right: 20rpx;
//
::v-deep rich-text img {
max-width: 95% !important;
border-radius: 10rpx;
height: auto !important;
display: block !important;
margin: 0 auto;
}
image {
width: 100%;
height: 100%;
border-radius: 8rpx;
}
}
//
::v-deep rich-text p {
margin: 20rpx 10rpx;
}
&-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;
}
}
::v-deep rich-text div {
margin: 20rpx 10rpx;
}
}
.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>