瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
4.1 KiB

  1. <template>
  2. <view class="page">
  3. <navbar title="文章详情" />
  4. <view class="content">
  5. <!-- 加载状态 -->
  6. <view class="loading-container" v-if="loading">
  7. <text class="loading-text">加载中...</text>
  8. </view>
  9. <!-- 文章详情 -->
  10. <view class="article-detail" v-if="!loading && articleDetail">
  11. <!-- 创建时间 -->
  12. <view class="article-meta">
  13. <text class="create-time">{{ formatTime(articleDetail.createTime) }}</text>
  14. </view>
  15. <!-- 富文本内容 -->
  16. <view class="article-content">
  17. <rich-text :nodes="articleDetail.content"></rich-text>
  18. </view>
  19. </view>
  20. <!-- 错误状态 -->
  21. <view class="error-container" v-if="!loading && !articleDetail">
  22. <text class="error-text">文章不存在或已被删除</text>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. articleId: '',
  32. articleDetail: null,
  33. loading: false
  34. }
  35. },
  36. onLoad(options) {
  37. if (options.id) {
  38. this.articleId = options.id;
  39. this.loadArticleDetail();
  40. }
  41. },
  42. onShareAppMessage(res) {
  43. return {
  44. title: this.articleDetail ? this.articleDetail.title || '文章详情' : '文章详情',
  45. imageUrl: this.articleDetail ? this.articleDetail.image : '',
  46. path: '/pages_order/article/index?id=' + this.articleId
  47. }
  48. },
  49. methods: {
  50. // 加载文章详情
  51. loadArticleDetail() {
  52. if (!this.articleId) return;
  53. this.loading = true;
  54. const params = {
  55. id: this.articleId
  56. };
  57. this.$api('articleDetail', params, (res) => {
  58. this.loading = false;
  59. if (res.code === 200 && res.result) {
  60. this.articleDetail = res.result;
  61. } else {
  62. uni.showToast({
  63. title: res.message || '加载失败',
  64. icon: 'none'
  65. });
  66. }
  67. });
  68. },
  69. // 格式化时间
  70. formatTime(time) {
  71. if (!time) return '';
  72. const date = new Date(time);
  73. const year = date.getFullYear();
  74. const month = String(date.getMonth() + 1).padStart(2, '0');
  75. const day = String(date.getDate()).padStart(2, '0');
  76. const hours = String(date.getHours()).padStart(2, '0');
  77. const minutes = String(date.getMinutes()).padStart(2, '0');
  78. return `${year}-${month}-${day} ${hours}:${minutes}`;
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped lang="scss">
  84. .page {
  85. background-color: #f5f5f5;
  86. min-height: 100vh;
  87. }
  88. .content {
  89. padding: 20rpx;
  90. }
  91. .loading-container {
  92. display: flex;
  93. justify-content: center;
  94. align-items: center;
  95. padding: 200rpx 0;
  96. .loading-text {
  97. font-size: 28rpx;
  98. color: #999;
  99. }
  100. }
  101. .error-container {
  102. display: flex;
  103. justify-content: center;
  104. align-items: center;
  105. padding: 200rpx 0;
  106. .error-text {
  107. font-size: 28rpx;
  108. color: #999;
  109. }
  110. }
  111. .article-detail {
  112. background-color: #fff;
  113. border-radius: 16rpx;
  114. padding: 30rpx;
  115. margin-bottom: 20rpx;
  116. }
  117. .article-meta {
  118. padding-bottom: 20rpx;
  119. border-bottom: 1px solid #f0f0f0;
  120. margin-bottom: 30rpx;
  121. .create-time {
  122. font-size: 24rpx;
  123. color: #999;
  124. }
  125. }
  126. .article-content {
  127. line-height: 1.6;
  128. // 富文本内容样式
  129. :deep(rich-text) {
  130. font-size: 30rpx;
  131. color: #333;
  132. // 图片样式
  133. img {
  134. max-width: 100%;
  135. height: auto;
  136. border-radius: 8rpx;
  137. margin: 20rpx 0;
  138. }
  139. // 段落样式
  140. p {
  141. margin: 20rpx 0;
  142. line-height: 1.8;
  143. }
  144. // 标题样式
  145. h1, h2, h3, h4, h5, h6 {
  146. margin: 30rpx 0 20rpx 0;
  147. font-weight: bold;
  148. }
  149. h1 { font-size: 36rpx; }
  150. h2 { font-size: 34rpx; }
  151. h3 { font-size: 32rpx; }
  152. // 列表样式
  153. ul, ol {
  154. padding-left: 40rpx;
  155. margin: 20rpx 0;
  156. }
  157. li {
  158. margin: 10rpx 0;
  159. line-height: 1.6;
  160. }
  161. // 引用样式
  162. blockquote {
  163. border-left: 4rpx solid #ddd;
  164. padding-left: 20rpx;
  165. margin: 20rpx 0;
  166. color: #666;
  167. font-style: italic;
  168. }
  169. // 代码样式
  170. code {
  171. background-color: #f5f5f5;
  172. padding: 4rpx 8rpx;
  173. border-radius: 4rpx;
  174. font-family: monospace;
  175. font-size: 26rpx;
  176. }
  177. pre {
  178. background-color: #f5f5f5;
  179. padding: 20rpx;
  180. border-radius: 8rpx;
  181. overflow-x: auto;
  182. margin: 20rpx 0;
  183. code {
  184. background: none;
  185. padding: 0;
  186. }
  187. }
  188. }
  189. }
  190. </style>