guideDetail.vue 2.2 KB

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