dynamicDetail.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. }
  42. })
  43. }
  44. onLoad((option) => {
  45. const {
  46. id, title
  47. } = option
  48. currentId.value = id
  49. currentTitle.value = title
  50. uni.setNavigationBarTitle({
  51. title: title
  52. });
  53. init(id)
  54. })
  55. onShareAppMessage(async (res) => {
  56. // console.log(announcement.value.title, 123)
  57. return {
  58. title: announcement.value.title,
  59. path: `/pages/dynamic/dynamicDetail/dynamicDetail?id=${currentId.value}&title=${currentTitle.value}`,
  60. imageUrl: announcement.value.cover
  61. };
  62. })
  63. onShareTimeline(async () => {
  64. // console.log(announcement.value.title, 1234)
  65. // console.log(imgurl.value)
  66. return {
  67. title: announcement.value.title,
  68. query: `id=${currentId.value}&title=${currentTitle.value}`,
  69. imageUrl: announcement.value.cover
  70. };
  71. })
  72. </script>
  73. <style scoped>
  74. .announcement-details {
  75. padding: 20px;
  76. background-color: #ffffff;
  77. display: flex;
  78. flex-direction: column;
  79. justify-content: space-between;
  80. /* height: 100vh; */
  81. /* 让页面高度撑满 */
  82. margin-bottom: env(safe-area-inset-bottom, 0);
  83. }
  84. .title {
  85. font-size: 24px;
  86. font-weight: bold;
  87. color: #333;
  88. text-align: center;
  89. /* 标题居中 */
  90. margin-bottom: 15px;
  91. }
  92. .content {
  93. flex: 1;
  94. /* 占据剩余空间 */
  95. display: flex;
  96. flex-direction: column;
  97. align-items: flex-start;
  98. /* 内容左对齐 */
  99. }
  100. .body {
  101. font-size: 16px;
  102. color: #555;
  103. text-align: left;
  104. /* 内容左对齐 */
  105. }
  106. .body img {
  107. width: 50%;
  108. height: auto;
  109. }
  110. .date {
  111. font-size: 14px;
  112. color: #999;
  113. text-align: center;
  114. /* 时间右对齐 */
  115. margin-top: 10px;
  116. /* 与内容分离 */
  117. }
  118. /* 全局样式穿透 */
  119. </style>