detail.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div style="display: flex; justify-content: center" class="main-content-wrapper">
  3. <div style="width: 1200px">
  4. <a-card>
  5. <div style="display: flex; justify-content: space-between">
  6. <div style="display: flex">
  7. <a-avatar
  8. style="width: 60px; height: 60px"
  9. :src="detailObj.userAvatar"
  10. :size="{ xs: 24, sm: 32, md: 40, lg: 64, xl: 80, xxl: 100 }"
  11. />
  12. <div class="snowy-index-card-left-one-username">
  13. <span style="font-weight: 600; margin: 2px; font-size: 18px">{{ detailObj.userNickName }}</span>
  14. <span style="color: #6d737b; margin: 2px">
  15. {{ detailObj.typeName }} | {{ formatDateTime(detailObj.lastReplyTime) }}
  16. </span>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="forum-list-title">{{ detailObj.postTitle }}</div>
  21. <div class="htmlContent" v-html="detailObj.postContent"></div>
  22. <div>
  23. <span>
  24. <a-tooltip title="点赞">
  25. <template v-if="detailObj.isLike == 1">
  26. <HeartOutlined :style="{ color: '#fa6c8d' }" @click="like(detailObj, 0)" />
  27. </template>
  28. <template v-else>
  29. <HeartOutlined @click="like(detailObj, 1)" />
  30. </template>
  31. </a-tooltip>
  32. <span style="padding-left: 8px">
  33. {{ detailObj.likeCount }}
  34. </span>
  35. </span>
  36. <a-tooltip title="编辑" v-if="detailObj.isSelf == 1">
  37. <EditOutlined class="ml-2" @click="formRef.onOpen(detailObj, detailObj.postId)" />
  38. </a-tooltip>
  39. <span class="ml-2" style="cursor: pointer" @click="replyFormRef.onOpen(detailObj, detailObj.postId)">
  40. <span>回复</span>
  41. <span style="padding-left: 8px">{{ detailObj.replyCount }}</span>
  42. </span>
  43. <a-tooltip title="举报">
  44. <WarningOutlined class="ml-2" @click="reportFormRef.onOpen(detailObj, detailObj.postId)" />
  45. </a-tooltip>
  46. </div>
  47. </a-card>
  48. <a-card class="mt-2">
  49. <Comment
  50. :commentList="detailObj.replyList?.records"
  51. :params="commentParams"
  52. @successful="resetGetList()"
  53. ></Comment>
  54. <div style="display: flex; justify-content: center" class="mt-8">
  55. <a-button type="primary" shape="round" @click="morePaging" v-if="moreType"> 加载更多 </a-button>
  56. <div v-else>全部加载完毕</div>
  57. </div>
  58. </a-card>
  59. <replyForm ref="replyFormRef" @successful="resetGetList()" />
  60. <Form ref="formRef" @successful="resetGetList()" />
  61. <reportForm ref="reportFormRef" @successful="resetGetList()"></reportForm>
  62. </div>
  63. </div>
  64. </template>
  65. <script setup name="forumDetail">
  66. import forumApi from '@/api/forum/forumApi'
  67. import { useRoute, useRouter } from 'vue-router'
  68. import { parseTime } from '@/utils/exam'
  69. import Comment from '@/components/Comment/index.vue'
  70. import replyForm from './replyForm.vue'
  71. import reportForm from './reportForm.vue'
  72. import Form from './form.vue'
  73. const reportFormRef = ref()
  74. const replyFormRef = ref()
  75. const formRef = ref()
  76. const route = useRoute()
  77. const detailObj = ref({})
  78. const moreType = ref(true)
  79. const commentParams = ref({
  80. likeType: 1,
  81. targetId: route.query.postId
  82. })
  83. const pagination = ref({
  84. current: 1,
  85. size: 10
  86. })
  87. function like(item, l) {
  88. forumApi.postlikeSubmit({ likeType: 0, targetId: route.query.postId }, item.isLike).then((data) => {
  89. item.isLike = l
  90. resetGetList()
  91. })
  92. }
  93. function formatDateTime(val) {
  94. if (!val) return ''
  95. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  96. }
  97. function getDetail(p) {
  98. forumApi
  99. .forumTypeDetail({
  100. postId: route.query.postId,
  101. ...pagination.value
  102. })
  103. .then((data) => {
  104. if (p) {
  105. if (data.replyList.records.length > 0) {
  106. detailObj.value.replyList.records = detailObj.value.replyList.records.concat(data.replyList.records)
  107. } else {
  108. pagination.value.current -= 1
  109. moreType.value = false
  110. }
  111. } else {
  112. detailObj.value = data
  113. }
  114. })
  115. }
  116. function morePaging() {
  117. pagination.value.current += 1
  118. getDetail(true)
  119. }
  120. function resetGetList() {
  121. pagination.value.size = 10
  122. pagination.value.current = 1
  123. moreType.value = true
  124. getDetail()
  125. }
  126. getDetail()
  127. </script>
  128. <style scoped>
  129. :deep(.htmlContent img) {
  130. max-width: 100% !important;
  131. }
  132. .snowy-index-card-left-one-username {
  133. margin-left: 8px;
  134. display: flex;
  135. flex-direction: column;
  136. justify-content: center;
  137. }
  138. .forum-list-title {
  139. font-size: 30px;
  140. font-weight: bold;
  141. }
  142. .forum-list-content {
  143. font-size: 14px;
  144. color: #696969;
  145. }
  146. </style>