瑶都万能墙
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.

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