dynamicDetail.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="announcement-details">
  3. <text class="title">{{ announcement.title }}</text>
  4. <text class="date">{{ announcement.date }}</text>
  5. <view class="content">
  6. <u-parse :html="announcement.content" :selectable="true" :show-with-animation="true" style="width: 100%;"></u-parse>
  7. </view>
  8. </view>
  9. </template>
  10. <script setup>
  11. import {
  12. ref
  13. } from 'vue'
  14. import {
  15. onLoad
  16. } from '@dcloudio/uni-app'
  17. import {
  18. getDynamicDetail
  19. } from '@/api/notice.js'
  20. const announcement = ref({
  21. title: "",
  22. content: "", // 假设这是后端返回的内容
  23. date: "" // ISO格式日期
  24. })
  25. function formatDate(dateString) {
  26. const options = {
  27. year: 'numeric',
  28. month: 'long',
  29. day: 'numeric'
  30. };
  31. return new Date(dateString).toLocaleDateString('zh-CN', options);
  32. }
  33. function init(id) {
  34. getDynamicDetail(id).then(res => {
  35. if (res?.data) {
  36. announcement.value = res.data
  37. }
  38. })
  39. }
  40. onLoad((option) => {
  41. const {
  42. id
  43. } = option
  44. init(id)
  45. })
  46. </script>
  47. <style scoped>
  48. .announcement-details {
  49. padding: 20px;
  50. background-color: #ffffff;
  51. display: flex;
  52. flex-direction: column;
  53. justify-content: space-between;
  54. /* height: 100vh; */
  55. /* 让页面高度撑满 */
  56. margin-bottom: env(safe-area-inset-bottom, 0);
  57. }
  58. .title {
  59. font-size: 24px;
  60. font-weight: bold;
  61. color: #333;
  62. text-align: center;
  63. /* 标题居中 */
  64. margin-bottom: 15px;
  65. }
  66. .content {
  67. flex: 1;
  68. /* 占据剩余空间 */
  69. display: flex;
  70. flex-direction: column;
  71. align-items: flex-start;
  72. /* 内容左对齐 */
  73. }
  74. .body {
  75. font-size: 16px;
  76. color: #555;
  77. text-align: left;
  78. /* 内容左对齐 */
  79. }
  80. .body img {
  81. width: 50%;
  82. height: auto;
  83. }
  84. .date {
  85. font-size: 14px;
  86. color: #999;
  87. text-align: right;
  88. /* 时间右对齐 */
  89. margin-top: 10px;
  90. /* 与内容分离 */
  91. }
  92. /* 全局样式穿透 */
  93. </style>