post.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <script setup lang="ts">
  2. import { onMounted, ref } from 'vue'
  3. import service from '../plugins/axios'
  4. import { useRoute, useRouter } from 'vue-router'
  5. import { ElMessage } from 'element-plus'
  6. import authorInformation from '../views/post/authorInformation.vue'
  7. import postarticle from '../views/post/postarticle.vue'
  8. import postcomment from '../views/post/comment.vue'
  9. import { useDark } from '@vueuse/core'
  10. import { watch } from 'vue'
  11. import { token } from '../plugins/pinia'
  12. import { ChatSquare } from '@element-plus/icons-vue'
  13. const id = useRoute().params.id as string
  14. const data = await (await service.get(`/post?id=${id}`)).data
  15. const views = await (await service.get(`post/addview?id=${id}`)).data
  16. if (data.cod === 400) {
  17. window.location.href = '/home'
  18. }
  19. const router = useRouter()
  20. const bt_comment = () => {
  21. if (token().token) {
  22. window.location.href = `/reply?postid=${id}`
  23. return
  24. }
  25. window.location.href = '/auth?type=login'
  26. }
  27. </script>
  28. <template>
  29. <el-row gutter="10">
  30. <el-col :xs="24"
  31. :sm="24"
  32. :md="6"
  33. :lg="6"
  34. :xl="6">
  35. <Suspense>
  36. <template #default>
  37. <authorInformation :id="data.author.auth_id"
  38. :numberOfReplies="data.comment"
  39. :views="views.data" />
  40. </template>
  41. <template #fallback>
  42. <el-skeleton />
  43. </template>
  44. </Suspense>
  45. </el-col>
  46. <el-col :xs="24"
  47. :sm="24"
  48. :md="18"
  49. :lg="18"
  50. :xl="18">
  51. <Suspense>
  52. <template #default>
  53. <postarticle :postid="id"
  54. :auth_id="data.author.auth_id"
  55. :title="data.title"
  56. :plateId="data.plateId"
  57. :content="data.content"
  58. :updatedAt="data.updatedAt"
  59. :Istop="data.isTop" />
  60. </template>
  61. <template #fallback>
  62. <el-skeleton />
  63. </template>
  64. </Suspense>
  65. </el-col>
  66. </el-row>
  67. <el-divider />
  68. <el-affix position="bottom"
  69. :offset="20">
  70. <div class="fl">
  71. <el-button type="primary"
  72. @click="bt_comment"
  73. size="large"
  74. :icon="ChatSquare"
  75. circle></el-button>
  76. </div>
  77. </el-affix>
  78. <Suspense>
  79. <template #default>
  80. <postcomment :postid="id"
  81. class="commentid" />
  82. </template>
  83. <template #fallback>
  84. <el-skeleton />
  85. </template>
  86. </Suspense>
  87. </template>
  88. <style scoped>
  89. .post-card {
  90. min-height: 800px;
  91. }
  92. /* 右对齐 */
  93. .card-header {
  94. display: flex;
  95. justify-content: space-between;
  96. align-items: center;
  97. }
  98. .el-affix {
  99. position: absolute;
  100. right: 0;
  101. bottom: 0;
  102. }
  103. </style>