guideDetail.vue 2.4 KB

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