TallList.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <div style="display: flex" class="mt-3">
  3. <a-card class="flex-3 mr-3">
  4. <div class="tallList">
  5. <div>
  6. <span style="font-weight: bold;">发表评论</span>
  7. <span class="tallListInfo ml-3">文明上网理性发言,请遵守评论服务协议</span>
  8. </div>
  9. <div class="mt-3">
  10. <div style="display: flex">
  11. <div style="display: flex; flex-direction: column; margin-left: 10px; margin-right: 10px">
  12. <div style="margin-right: 15px">
  13. <a-avatar :src="userInfo.avatar">
  14. <template #icon><UserOutlined /></template>
  15. </a-avatar>
  16. </div>
  17. <span style="display: block; font-size: 12px">{{ userInfo.name }}</span>
  18. </div>
  19. <div style="width: 100%; height: 100%; display: flex; position: relative">
  20. <a-textarea placeholder="" :rows="4" v-model:value="talk" style="margin-top: 5px" :maxlength="500" />
  21. </div>
  22. </div>
  23. <div style="display: flex; justify-content: flex-end; margin-top: 10px">
  24. <a-button style="width: 100px" @click="handerPublish">发布</a-button>
  25. </div>
  26. </div>
  27. <a-divider />
  28. <div style="display: flex; justify-content: flex-end">
  29. <TabSwitcher @selectTab="handelrSelectTab"></TabSwitcher>
  30. </div>
  31. <div>
  32. <TallItem v-for="(item, index) in talkList" :key="index" :item="item" :id="id" @publish="publish"></TallItem>
  33. </div>
  34. </div>
  35. </a-card>
  36. <a-card class="flex-1">
  37. <div class="equalList">
  38. <div style="display: flex; align-items: center">
  39. <span style="font-size: 20px; font-weight: bold">同类型资源</span>
  40. </div>
  41. <div style="display: flex; flex-direction: column; padding: 10px">
  42. <EqualItem
  43. v-for="(item, index) in equalList"
  44. :key="index"
  45. :item="item"
  46. :class="equalList.length == index + 1 ? '' : 'mb-2'"
  47. ></EqualItem>
  48. </div>
  49. </div>
  50. </a-card>
  51. </div>
  52. </template>
  53. <script setup>
  54. import { ref } from 'vue'
  55. import TabSwitcher from './TabSwitcher.vue'
  56. import TallItem from './TallItem.vue'
  57. import EqualItem from './EqualItem.vue'
  58. import {
  59. addViewCount,
  60. detail,
  61. add,
  62. cancel,
  63. queryList,
  64. pageComment,
  65. list,
  66. addComment,
  67. getTalkPageList
  68. } from '@/api/portal'
  69. import { useRoute } from 'vue-router'
  70. import EventBus from '@/utils/EventBus'
  71. import { globalStore } from '@/store'
  72. const store = globalStore()
  73. const userInfo = computed(() => {
  74. return store.userInfo
  75. })
  76. const currentPage = reactive({
  77. funcType: 2,
  78. current: 1,
  79. size: 6
  80. })
  81. const emit = defineEmits(['selectTab'])
  82. const tabKey = ref(0)
  83. const total = ref(0)
  84. const route = useRoute()
  85. const id = route.query.id
  86. const talk = ref('')
  87. const pagers = reactive({
  88. pages: 1,
  89. size: 20
  90. })
  91. const equalList = ref([])
  92. const talkList = ref([])
  93. const getList = () => {
  94. list(currentPage)
  95. .then((res) => {
  96. console.log('下面列表获取', res)
  97. if (res.code == 200) {
  98. equalList.value = res.data.records
  99. currentPage.current = res.data.current
  100. }
  101. })
  102. .catch((err) => {
  103. console.log(err)
  104. })
  105. }
  106. const publish = (data) => {
  107. addComment({ pid: data.id, resourceId: data.resourceId, commentName: data.talk })
  108. .then((res) => {
  109. getPageComment()
  110. talk.value = ''
  111. })
  112. .catch((err) => {
  113. console.log(err)
  114. })
  115. }
  116. const handelrSelectTab = (data) => {
  117. if (data == 'latest') {
  118. tabKey.value = 0
  119. } else {
  120. tabKey.value = 1
  121. }
  122. pagers.pages = 1
  123. pagers.size = 20
  124. if (tabKey.value == 0) {
  125. getPageComment()
  126. } else {
  127. getHotPageComment()
  128. }
  129. }
  130. const handerPublish = () => {
  131. addComment({ resourceId: id, commentName: talk.value })
  132. .then((res) => {
  133. getPageComment()
  134. talk.value = ''
  135. EventBus.emit('upDataDetailsNum')
  136. })
  137. .catch((err) => {
  138. console.log(err)
  139. })
  140. }
  141. const getPageComment = () => {
  142. pageComment({ resourceId: id, ...pagers })
  143. .then((res) => {
  144. if (res.code == 200) {
  145. talkList.value = res.data.records
  146. pagers.pages = res.data.pages
  147. pagers.size = res.data.size
  148. total.value = res.data.total
  149. }
  150. })
  151. .catch((err) => {
  152. console.log(err)
  153. })
  154. }
  155. const getPageCommentNew = (data) => {
  156. list({ ...currentPage, ...data })
  157. .then((res) => {
  158. if (res.code == 200) {
  159. equalList.value = res.data.records
  160. currentPage.current = res.data.current
  161. }
  162. })
  163. .catch((err) => {
  164. console.log(err)
  165. })
  166. }
  167. const onGetPageCommentNew = (data) => {
  168. getPageCommentNew(data)
  169. }
  170. const getHotPageComment = () => {
  171. getTalkPageList({ resourceId: id, ...pagers })
  172. .then((res) => {
  173. if (res.code == 200) {
  174. talkList.value = res.data.records
  175. pagers.pages = res.data.pages
  176. pagers.size = res.data.size
  177. }
  178. })
  179. .catch((err) => {
  180. console.log(err)
  181. })
  182. }
  183. onMounted(() => {
  184. getPageComment()
  185. })
  186. EventBus.off('onGetPageComment', getPageComment)
  187. EventBus.on('onGetPageComment', getPageComment)
  188. defineExpose({ onGetPageCommentNew })
  189. </script>
  190. <style scoped>
  191. .user-info {
  192. display: flex;
  193. align-items: center;
  194. width: 100%;
  195. height: 200px;
  196. border: 1px solid #dfe2e5;
  197. padding: 20px;
  198. }
  199. .resource-container {
  200. width: 100%;
  201. margin: 0 auto;
  202. padding: 20px;
  203. border: 1px solid #dfe2e5;
  204. }
  205. .user-avatar {
  206. width: 40px;
  207. height: 40px;
  208. background: #1e90ff;
  209. border-radius: 50%;
  210. margin-right: 10px;
  211. }
  212. .user-details {
  213. flex: 1;
  214. }
  215. .user-name {
  216. font-size: 13px;
  217. font-weight: bold;
  218. }
  219. .publish-time {
  220. font-size: 12px;
  221. color: #999;
  222. margin-top: 5px;
  223. }
  224. .metrics {
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. }
  229. .metric-item {
  230. display: flex;
  231. flex-direction: column;
  232. align-items: center;
  233. padding-left: 10px;
  234. padding-right: 10px;
  235. }
  236. .metric-item span:first-child {
  237. font-size: 18px;
  238. font-weight: bold;
  239. }
  240. .metric-item span:last-child {
  241. font-size: 12px;
  242. color: #666;
  243. }
  244. .actions {
  245. display: flex;
  246. }
  247. .share-btn,
  248. .favorite-btn {
  249. background-color: transparent;
  250. border: none;
  251. cursor: pointer;
  252. }
  253. .course-info {
  254. margin-top: 20px;
  255. line-height: 1.6;
  256. }
  257. .liene {
  258. height: 35px;
  259. width: 1px;
  260. background: #00000018;
  261. }
  262. .resource-container {
  263. width: 100%;
  264. margin: 0 auto;
  265. padding: 20px;
  266. border: 1px solid #dfe2e5;
  267. }
  268. h1 {
  269. text-align: center;
  270. margin-bottom: 20px;
  271. }
  272. .ant-descriptions {
  273. margin-top: 20px;
  274. }
  275. .ant-typography-title {
  276. margin-top: 20px;
  277. }
  278. .ant-typography-paragraph {
  279. margin-top: 10px;
  280. }
  281. .ant-space {
  282. margin-top: 10px;
  283. }
  284. .video-info {
  285. height: 100%; /* 确保填满容器高度 */
  286. }
  287. .resInfo {
  288. margin-left: 10px;
  289. width: 350px;
  290. height: 570px;
  291. border: 1px solid #dfe2e5;
  292. padding: 10px;
  293. }
  294. .user-info-container {
  295. display: flex;
  296. }
  297. .tallList {
  298. display: flex;
  299. flex-direction: column;
  300. }
  301. .tallListInfo {
  302. color: rgba(0, 0, 0, 0.479);
  303. font-size: 12px;
  304. }
  305. .line {
  306. width: 100%;
  307. height: 0.5px;
  308. background-color: rgba(0, 0, 0, 0.075);
  309. margin-top: 10px;
  310. margin-bottom: 10px;
  311. }
  312. .equalList {
  313. display: flex;
  314. flex-direction: column;
  315. }
  316. .resInfoTitile {
  317. width: 5px;
  318. height: 20px;
  319. background-color: #1e90ff;
  320. margin-right: 5px;
  321. }
  322. .flex-3 {
  323. flex: 3;
  324. }
  325. .flex-1 {
  326. flex: 1;
  327. }
  328. </style>