news.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <script setup>
  2. import { ref, onMounted,computed } from 'vue'
  3. import Layout from '@/components/common/Layout.vue'
  4. import { useRouter } from 'vue-router'
  5. import { useI18n } from 'vue-i18n'
  6. // 模拟新闻数据(后期可替换为接口调用)
  7. const { t, locale, messages } = useI18n()
  8. // 从 i18n messages 中按当前 locale 读取 newsList(可能不存在时返回空数组)
  9. const list = computed(() => (messages.value[locale.value] && messages.value[locale.value].message && messages.value[locale.value].message.newsList) ? messages.value[locale.value].message.newsList : [])
  10. const router = useRouter()
  11. // 解析日期,便于模板使用
  12. // formatList 随 list(即 locale)变化自动更新
  13. const formatList = computed(() => list.value.map((item) => {
  14. const { year, month, day } = parseDate(item.date)
  15. return { ...item, year, month, day }
  16. }))
  17. const parseDate = (d) => {
  18. const [year, month, day] = d.split('-')
  19. return { year, month, day }
  20. }
  21. const handleClick = (item) => {
  22. console.log('点击新闻项:', item)
  23. // 这里可以添加跳转到新闻详情页的逻辑
  24. router.push(`/newsDetail/${item.id}`);
  25. }
  26. // 仅用于调试输出,实际列表和格式化由 computed 管理
  27. onMounted(() => {
  28. console.log('新闻列表:', list.value);
  29. })
  30. // 根据当前语言返回字体类,绑定到根元素以改变整页字体样式
  31. const fontClass = computed(() => {
  32. if (locale.value === 'zh-TW') return 'font-zh-tw'
  33. if (locale.value === 'en') return 'font-en'
  34. return 'font-zh-cn'
  35. })
  36. </script>
  37. <template>
  38. <Layout>
  39. <div class="news-container" :class="fontClass">
  40. <!-- 顶部横幅图 -->
  41. <div class="index-page">
  42. <div class="page-header-sub">
  43. <!-- <img src="../assets/images/news.png" alt="news banner" class="responsive-img" /> -->
  44. <img src="../assets/images/banner.png" alt="" srcset="">
  45. </div>
  46. </div>
  47. <!-- 主体区域 -->
  48. <div class="news-wrapper container">
  49. <!-- 左侧标题栏 -->
  50. <aside class="news-sidebar">
  51. <div class="sidebar-box">
  52. <div class="sidebar-title">{{ $t('message.t3') }}</div>
  53. </div>
  54. </aside>
  55. <!-- 右侧新闻列表 -->
  56. <section class="news-list">
  57. <article v-for="item in formatList" :key="item.id" class="news-item" @click=handleClick(item)>
  58. <div class="news-date">
  59. <div>
  60. <span class="news-month"><span>{{ item.month }}</span><span>月</span></span>
  61. <span class="news-day"><span>{{ item.day }}</span><span>日</span></span>
  62. </div>
  63. <div class="news-year">{{ item.year }}</div>
  64. </div>
  65. <div class="news-content">
  66. <div class="news-title">{{ item.title }}</div>
  67. <p class="news-desc">{{ item.desc }}</p>
  68. </div>
  69. </article>
  70. <!-- <div class="load-more">
  71. <div>查看更多</div>
  72. </div> -->
  73. </section>
  74. </div>
  75. </div>
  76. </Layout>
  77. </template>
  78. <style lang="scss" scoped>
  79. .news-container {
  80. width: 100%;
  81. overflow: hidden;
  82. }
  83. /* 顶部横幅 */
  84. .news-banner {
  85. img {
  86. width: 100%;
  87. height: 100%;
  88. }
  89. @media screen and (max-width: 1023px) {
  90. height: 30rem;
  91. }
  92. @media screen and (max-width: 767px) {
  93. height: 20rem;
  94. margin-top: 4rem;
  95. }
  96. }
  97. /* 主体布局 */
  98. .news-wrapper {
  99. display: flex;
  100. gap: 3rem;
  101. padding: 4rem 0;
  102. width: 65%;
  103. @media screen and (max-width: 767px) {
  104. width: 80%;
  105. }
  106. }
  107. /* 侧边栏 */
  108. .news-sidebar {
  109. height: 19rem;
  110. width: 14%;
  111. .sidebar-box {
  112. width: 100%;
  113. height: 100%;
  114. background: url('../assets/images/pic.png') no-repeat;
  115. background-size: 100% 100%;
  116. // padding: 4rem 2rem;
  117. padding: 0rem 1.5rem;
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. .sidebar-title {
  122. color: #000;
  123. font-size: 2rem;
  124. font-weight: bold;
  125. }
  126. }
  127. @media screen and (max-width: 767px) {
  128. display: none;
  129. }
  130. }
  131. /* 新闻列表 */
  132. .news-list {
  133. flex: 1;
  134. display: flex;
  135. flex-direction: column;
  136. margin-left: 6%;
  137. >article:nth-child(1) {
  138. padding-top: 0;
  139. }
  140. @media screen and (max-width: 767px) {
  141. margin-left: 0;
  142. }
  143. .news-item {
  144. display: flex;
  145. gap: 1.5rem;
  146. border-bottom: 1px solid #e9e9e9;
  147. padding: 1rem 0rem;
  148. @media screen and (max-width: 767px) {
  149. padding-bottom: 1.5rem;
  150. }
  151. .news-date {
  152. width: 5rem;
  153. height: 4.6rem;
  154. background: #f2f2f2;
  155. padding: 0.5rem 0.5rem;
  156. text-align: center;
  157. border-radius: 5px;
  158. >div {
  159. >span {
  160. font-size: 1rem;
  161. >span:nth-child(2) {
  162. font-size: 0.7rem !important;
  163. color: #777;
  164. }
  165. }
  166. }
  167. }
  168. .news-content {
  169. flex: 1;
  170. .news-title {
  171. font-size: 1.3rem;
  172. // font-weight: 600;
  173. // margin-bottom: 0.5rem;
  174. margin: 0rem;
  175. color: #333;
  176. }
  177. .news-desc {
  178. font-size: 0.9rem;
  179. color: #666;
  180. line-height: 1.6;
  181. // 超过两行用省略号
  182. display: -webkit-box;
  183. -webkit-line-clamp: 2;
  184. line-clamp: 2;
  185. -webkit-box-orient: vertical;
  186. overflow: hidden;
  187. text-overflow: ellipsis;
  188. }
  189. }
  190. }
  191. .news-year {
  192. margin-top: 0.5rem;
  193. font-size: 1rem !important;
  194. color: #777;
  195. }
  196. .load-more {
  197. display: flex;
  198. justify-content: center;
  199. width: 15%;
  200. margin-top: 1rem;
  201. margin-bottom: 2rem;
  202. padding: 1rem 2rem;
  203. background-color: #F7B334;
  204. color: #fff;
  205. }
  206. }
  207. /* per-locale font classes */
  208. .font-zh-cn { font-family: 'Noto Sans SC', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif; }
  209. .font-zh-tw { font-family: 'Noto Sans TC', 'PingFang TC', 'Helvetica Neue', Arial, sans-serif; }
  210. .font-en { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
  211. </style>