swiperDetail.vue 2.3 KB

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