detail.vue 4.0 KB

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