Files
frontend-app/pages/login_package/news_info/news_info.vue
T

136 lines
3.3 KiB
Vue
Raw Normal View History

2025-08-06 20:25:41 +08:00
<template>
<view class="news_info_warp">
<Header leftTitle="" left-path-type="navigateTo" left-path="/pages/login_package/news/news"
style="background-color: #FFFFFF;" />
<view class="news_info_header_warp">
<view class="title_">{{ newsDetail.title }}</view>
<view class="avatar_">
<view>
2026-09-10 09:42:27 +08:00
<up-image :src="newsDetail.avatar_url" width="40" height="40" bgColor="#f1f6ff00"
shape="circle"></up-image>
2025-08-06 20:25:41 +08:00
</view>
<view style="margin-left: 12rpx;">{{ newsDetail.name }}</view>
</view>
<view class="time_">
<view>{{ formatDate(newsDetail.ctdate) }}</view>
<view class="browses_">
<view>
2026-09-10 09:42:27 +08:00
<up-image src="/pages/login_package/static/login/show.png" width="20" height="20"
bgColor="#f1f6ff00"></up-image>
2025-08-06 20:25:41 +08:00
</view>
<view style="margin-left: 8rpx;">{{ newsDetail.browses }}</view>
</view>
</view>
</view>
<view class="news_info_fg_warp"></view>
2026-09-10 09:42:27 +08:00
<view class="news_info_content_warp">
<up-parse :content="formattedContent" :tagStyle="{ img: 'max-width:100% !important;height:auto !important;display:block;margin:10rpx auto;' }"></up-parse>
</view>
2025-08-06 20:25:41 +08:00
</view>
</template>
<script>
import Header from '@/components/header.vue';
import { getNewsDetail } from '@/api/news.js';
import { formatDate } from '@/utils/index.js';
export default {
components: { Header },
data() {
return {
id: 0,
newsDetail: {}
}
},
2026-09-10 09:42:27 +08:00
computed: {
formattedContent() {
if (!this.newsDetail || !this.newsDetail.content) return '';
let content = this.newsDetail.content;
// 兼容小程序富文本:给所有 img 注入自适应宽度样式,避免原图过大导致横向滚动
content = content.replace(/<img[^>]*>/gi, (match) => {
if (/style\s*=\s*["'][^"']*["']/i.test(match)) {
return match.replace(/style\s*=\s*(["'])([^"']*)\1/i, (m, quote, val) => {
return `style=${quote}${val};max-width:100% !important;height:auto !important;display:block;margin:10rpx auto;${quote}`;
});
} else {
return match.replace(/<img/i, '<img style="max-width:100% !important;height:auto !important;display:block;margin:10rpx auto;"');
}
});
return content;
}
},
2025-08-06 20:25:41 +08:00
onLoad(option) {
const id = option.id;
if (id && id !== "null") {
this.id = id;
this.fetchData();
}
},
methods: {
formatDate,
async fetchData() {
const id = this.id;
const params = {
id,
}
const resp = await getNewsDetail(params);
if (resp && resp.bizcode === 100) {
this.newsDetail = resp.data || {};
}
},
}
}
</script>
<style lang="scss" scoped>
.news_info_warp {
overflow: hidden;
}
.news_info_header_warp {
padding: 30rpx;
.title_ {
font-weight: bold;
font-size: 32rpx;
color: #333333;
}
.avatar_ {
display: flex;
align-items: center;
margin-top: 20rpx;
}
.time_ {
display: flex;
justify-content: space-between;
font-weight: 500;
font-size: 28rpx;
color: #666666;
margin-top: 10rpx;
.browses_ {
display: flex;
}
}
}
.news_info_fg_warp {
height: 10rpx;
background-color: $app-bj;
width: 100%;
}
.news_info_content_warp {
padding: 30rpx;
height: calc(100vh - 524rpx);
2026-09-10 09:42:27 +08:00
overflow-y: auto;
overflow-x: hidden;
box-sizing: border-box;
word-break: break-all;
2025-08-06 20:25:41 +08:00
font-size: 28rpx;
color: #333333;
}
</style>