detail.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="story-detail-container">
  3. <image :src="detail.titleImg" class="detail-img" mode="widthFix"/>
  4. <view class="detail-content">
  5. <view class="detail-title">{{ detail.title }}</view>
  6. <view class="detail-user">
  7. <image :src="detail.userAvatar" class="avatar"/>
  8. <text class="username">{{ detail.userName }}</text>
  9. <view class="likes" @click="toggleLike">
  10. <text class="icon-heart">{{ detail.liked ? '❤️' : '♡' }}</text>
  11. <text class="like-number">{{ detail.likes }}</text>
  12. </view>
  13. </view>
  14. <view class="detail-desc">{{ detail.content }}</view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import {getStoryDetail, likeStory} from '@/api/home/index.js'
  20. export default {
  21. data() {
  22. return {
  23. detail: {
  24. title: '',
  25. content: '',
  26. titleImg: '',
  27. userAvatar: '',
  28. userName: '',
  29. likes: 0,
  30. liked: false
  31. }
  32. }
  33. },
  34. onLoad(options) {
  35. const {id} = options;
  36. if (id) {
  37. this.fetchDetail(decodeURIComponent(id));
  38. }
  39. },
  40. methods: {
  41. toggleLike() {
  42. this.detail.liked = !this.detail.liked
  43. likeStory(this.detail.id, (this.detail.liked ? 1 : 0));
  44. },
  45. async fetchDetail(id) {
  46. try {
  47. const res = await getStoryDetail(id);
  48. this.detail = res.data || {};
  49. } catch (err) {
  50. uni.showToast({title: '加载失败', icon: 'none'});
  51. setTimeout(() => uni.navigateBack(), 1500);
  52. }
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .story-detail-container {
  59. padding: 20rpx;
  60. background-color: #fff;
  61. }
  62. .detail-img {
  63. width: 100%;
  64. border-radius: 10rpx;
  65. margin-bottom: 20rpx;
  66. }
  67. .detail-content {
  68. padding: 0 10rpx;
  69. }
  70. .detail-title {
  71. font-size: 36rpx;
  72. font-weight: bold;
  73. color: #03803B;
  74. margin-bottom: 20rpx;
  75. }
  76. .detail-user {
  77. display: flex;
  78. align-items: center;
  79. margin-bottom: 30rpx;
  80. }
  81. .avatar {
  82. width: 50rpx;
  83. height: 50rpx;
  84. border-radius: 50%;
  85. margin-right: 16rpx;
  86. }
  87. .username {
  88. font-size: 28rpx;
  89. color: #666;
  90. }
  91. .likes {
  92. display: flex;
  93. align-items: center;
  94. gap: 6rpx;
  95. font-size: 28rpx;
  96. color: #999;
  97. margin-left: auto;
  98. }
  99. .icon-heart {
  100. font-size: 36rpx;
  101. color: #ff4c4c;
  102. line-height: 1;
  103. }
  104. .like-number {
  105. font-size: 28rpx;
  106. color: #999;
  107. }
  108. .detail-desc {
  109. font-size: 28rpx;
  110. line-height: 1.6;
  111. color: #333;
  112. white-space: pre-wrap; /* 保留换行 */
  113. }
  114. </style>