better-staridc-MNBT
1<template>
2 <div class="site-news-detail">
3 <section class="site-page-header" :style="{ backgroundImage: `url(${headerImage})` }">
4 <div class="hd-container">
5 <h1>新闻资讯</h1>
6 <p>了解平台最新动态与行业资讯</p>
7 </div>
8 </section>
9
10 <section class="site-sec">
11 <div class="hd-container">
12 <article v-if="news.id" class="site-article">
13 <header class="site-article-head">
14 <h1>{{ news.title }}</h1>
15 <div class="site-article-meta">
16 <span class="site-meta-chip"><i class="mdi mdi-calendar-month-outline"></i>{{ formatDate(news.created_at) }}</span>
17 <span v-if="news.category" class="site-meta-chip"><i class="mdi mdi-tag-outline"></i>{{ news.category }}</span>
18 <span class="site-meta-chip"><i class="mdi mdi-eye-outline"></i>{{ news.views }} 浏览</span>
19 </div>
20 </header>
21
22 <div class="site-article-content" v-html="renderedContent"></div>
23
24 <div class="site-article-foot">
25 <t-button theme="primary" @click="$router.push('/site/news')">
26 <template #prefix><i class="mdi mdi-arrow-left"></i></template>
27 返回新闻列表
28 </t-button>
29 </div>
30 </article>
31
32 <div v-else-if="loading" class="site-empty">
33 <i class="mdi mdi-loading mdi-spin"></i>
34 <p>正在加载新闻内容...</p>
35 </div>
36
37 <div v-else-if="error" class="site-empty">
38 <i class="mdi mdi-alert-circle-outline"></i>
39 <p>{{ error }}</p>
40 <t-button theme="primary" style="margin-top:12px" @click="$router.push('/site/news')">返回新闻列表</t-button>
41 </div>
42 </div>
43 </section>
44 </div>
45</template>
46
47<script setup>
48import { ref, computed, onMounted } from 'vue'
49import { useRoute } from 'vue-router'
50import bg2 from '@/shared/assets/bg2.jpg'
51import { getSiteNewsDetail } from '@/home/api/site'
52import { formatDate } from '@/home/utils/format'
53
54const headerImage = bg2
55const route = useRoute()
56
57const news = ref({})
58const loading = ref(true)
59const error = ref('')
60
61// 将内容按空行分段渲染;单换行转 <br>,保留管理员录入的简单 HTML
62const renderedContent = computed(() => {
63 const raw = String(news.value.content || '')
64 const paragraphs = raw.split(/\n{2,}/).map((p) => p.replace(/\n/g, '<br>').trim()).filter((p) => p !== '')
65 return paragraphs.map((p) => `<p>${p}</p>`).join('')
66})
67
68onMounted(async () => {
69 const res = await getSiteNewsDetail(route.params.id)
70 if (res.ok && res.data?.news) {
71 news.value = res.data.news
72 } else {
73 error.value = res.message === '新闻不存在' ? '新闻不存在或已下架' : '获取新闻内容失败'
74 }
75 loading.value = false
76})
77</script>
78
79<style scoped>
80.site-news-detail {
81 background: var(--hd-bg);
82}
83
84.site-page-header {
85 background-size: cover;
86 background-position: center;
87 padding: 72px 0;
88 text-align: center;
89}
90
91.site-page-header h1 {
92 margin: 0 0 10px;
93 font-size: 2.2rem;
94 font-weight: 800;
95 letter-spacing: -0.02em;
96 color: #181818;
97 text-shadow: 0 0 10px rgba(255, 255, 255, 0.75);
98}
99
100.site-page-header p {
101 margin: 0;
102 font-size: 1.05rem;
103 color: #444;
104 text-shadow: 0 0 10px rgba(255, 255, 255, 0.75);
105}
106
107.site-sec {
108 padding: 48px 0;
109}
110
111.site-article {
112 max-width: 820px;
113 margin: 0 auto;
114 background: var(--hd-surface);
115 border: 1px solid var(--hd-border);
116 border-radius: var(--hd-radius-xl);
117 padding: 36px 40px;
118 box-shadow: var(--hd-shadow);
119}
120
121.site-article-head h1 {
122 position: relative;
123 margin: 0 0 18px;
124 font-size: 1.7rem;
125 font-weight: 800;
126 color: var(--hd-text);
127 line-height: 1.35;
128 padding-bottom: 16px;
129}
130
131.site-article-head h1::after {
132 content: '';
133 position: absolute;
134 bottom: 0;
135 left: 0;
136 width: 44px;
137 height: 3px;
138 border-radius: 3px;
139 background: var(--hd-brand);
140}
141
142.site-article-meta {
143 display: flex;
144 flex-wrap: wrap;
145 gap: 8px;
146 margin-bottom: 28px;
147 padding-bottom: 20px;
148 border-bottom: 1px solid var(--hd-border);
149}
150
151.site-meta-chip {
152 display: inline-flex;
153 align-items: center;
154 gap: 5px;
155 padding: 4px 12px;
156 border-radius: 999px;
157 background: var(--hd-bg);
158 border: 1px solid var(--hd-border);
159 color: var(--hd-text-2);
160 font-size: 13px;
161}
162
163.site-article-content {
164 font-size: 15px;
165 line-height: 2;
166 color: var(--hd-text-2);
167}
168
169.site-article-content p {
170 margin: 0 0 18px;
171}
172
173.site-article-foot {
174 margin-top: 32px;
175 padding-top: 20px;
176 border-top: 1px solid var(--hd-border);
177 text-align: center;
178}
179
180.site-empty {
181 text-align: center;
182 padding: 60px 16px;
183 color: var(--hd-text-3);
184}
185
186.site-empty i {
187 font-size: 40px;
188 display: block;
189 margin-bottom: 10px;
190 color: #cbd5e1;
191}
192
193.site-empty p {
194 font-size: 15px;
195}
196
197@media (max-width: 640px) {
198 .site-article { padding: 24px 20px; }
199 .site-article-head h1 { font-size: 1.4rem; }
200}
201</style>