noticeDetail.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. onShareAppMessage,
  17. onShareTimeline
  18. } from '@dcloudio/uni-app'
  19. import {
  20. getNoticeDetail
  21. } from '@/api/notice.js'
  22. const announcement = ref({
  23. title: "",
  24. content: "", // 假设这是后端返回的内容
  25. date: "" // ISO格式日期
  26. })
  27. const currentId = ref(null);
  28. function formatDate(dateString) {
  29. const options = {
  30. year: 'numeric',
  31. month: 'long',
  32. day: 'numeric'
  33. };
  34. return new Date(dateString).toLocaleDateString('zh-CN', options);
  35. }
  36. function init(id) {
  37. getNoticeDetail(id).then(res => {
  38. if (res?.data) {
  39. announcement.value = res.data
  40. }
  41. })
  42. }
  43. onLoad((option) => {
  44. const {
  45. id
  46. } = option
  47. currentId.value = id
  48. init(id)
  49. })
  50. onShareAppMessage(async (res) => {
  51. return {
  52. title: announcement.value.title,
  53. path: `/pages/notice/noticeDetail/noticeDetail?id=${currentId.value}`
  54. };
  55. })
  56. onShareTimeline(async () => {
  57. // console.log(imgurl.value)
  58. return {
  59. title: announcement.value.title,
  60. query: `id=${currentId.value}`
  61. };
  62. })
  63. </script>
  64. <style scoped>
  65. .announcement-details {
  66. padding: 20px;
  67. background-color: #ffffff;
  68. display: flex;
  69. flex-direction: column;
  70. justify-content: space-between;
  71. /* height: 100vh; */
  72. /* 让页面高度撑满 */
  73. margin-bottom: env(safe-area-inset-bottom, 0);
  74. }
  75. .title {
  76. font-size: 24px;
  77. font-weight: bold;
  78. color: #333;
  79. text-align: center;
  80. /* 标题居中 */
  81. margin-bottom: 15px;
  82. }
  83. .content {
  84. flex: 1;
  85. /* 占据剩余空间 */
  86. display: flex;
  87. flex-direction: column;
  88. align-items: flex-start;
  89. /* 内容左对齐 */
  90. }
  91. .body {
  92. font-size: 16px;
  93. color: #555;
  94. text-align: left;
  95. /* 内容左对齐 */
  96. }
  97. .body img {
  98. width: 50%;
  99. height: auto;
  100. }
  101. .date {
  102. font-size: 14px;
  103. color: #999;
  104. text-align: center;
  105. /* 时间右对齐 */
  106. margin-top: 10px;
  107. /* 与内容分离 */
  108. }
  109. /* 全局样式穿透 */
  110. </style>