dynamicDetail.vue 2.7 KB

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