detail.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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" v-if="detailObj.userNickName">
  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 v-if="detailObj.userNickName">
  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="举报" v-if="detailObj.userNickName">
  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. if (route.query.postId) {
  119. getDetail(true)
  120. } else {
  121. submitFormGetChapter(true)
  122. }
  123. }
  124. function resetGetList() {
  125. pagination.value.size = 10
  126. pagination.value.current = 1
  127. moreType.value = true
  128. if (route.query.postId) {
  129. getDetail()
  130. } else {
  131. submitFormGetChapter()
  132. }
  133. }
  134. const submitFormGetChapter = (p) => {
  135. forumApi
  136. .submitFormGetChapter({
  137. courseId: route.query.courseId,
  138. chapterId: route.query.chapterId,
  139. courseName: route.query.courseName,
  140. chapterName: route.query.chapterName,
  141. ...pagination.value
  142. })
  143. .then((data) => {
  144. if (p) {
  145. if (data.replyList.records.length > 0) {
  146. detailObj.value.replyList.records = detailObj.value.replyList.records.concat(data.replyList.records)
  147. } else {
  148. pagination.value.current -= 1
  149. moreType.value = false
  150. }
  151. } else {
  152. detailObj.value = data
  153. }
  154. })
  155. }
  156. onMounted(() => {
  157. if (route.query.postId) {
  158. getDetail()
  159. } else {
  160. submitFormGetChapter()
  161. }
  162. })
  163. </script>
  164. <style scoped>
  165. :deep(.htmlContent img) {
  166. max-width: 100% !important;
  167. }
  168. .snowy-index-card-left-one-username {
  169. margin-left: 8px;
  170. display: flex;
  171. flex-direction: column;
  172. justify-content: center;
  173. }
  174. .forum-list-title {
  175. font-size: 30px;
  176. font-weight: bold;
  177. }
  178. .forum-list-content {
  179. font-size: 14px;
  180. color: #696969;
  181. }
  182. </style>