platePostItem.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <script setup lang="ts">
  2. import service from '../../plugins/axios'
  3. import { defineProps, ref } from 'vue'
  4. import { API_URL } from '../../config'
  5. const dp = defineProps({
  6. id: {
  7. type: String,
  8. required: true,
  9. },
  10. title: {
  11. type: String,
  12. required: true,
  13. },
  14. content: {
  15. type: String,
  16. required: true,
  17. },
  18. authorid: {
  19. type: String,
  20. required: true,
  21. },
  22. time: {
  23. type: String,
  24. required: true,
  25. },
  26. numberOfReplies: {
  27. type: String,
  28. required: true,
  29. },
  30. })
  31. //格式化时间几天前
  32. function formatDate(date: any) {
  33. const d = new Date(date)
  34. const now = Date.now()
  35. const diff = (now - d.getTime()) / 1000
  36. if (diff < 30) {
  37. return '刚刚'
  38. } else if (diff < 3600) {
  39. // less 1 hour
  40. return Math.ceil(diff / 60) + '分钟前'
  41. } else if (diff < 3600 * 24) {
  42. return Math.ceil(diff / 3600) + '小时前'
  43. } else if (diff < 3600 * 24 * 2) {
  44. return '1天前'
  45. }
  46. return Math.ceil(diff / (3600 * 24)) + '天前'
  47. }
  48. const userinfo = ref(
  49. await (
  50. await service.get(`userinfo/getuser?id=${dp.authorid}`)
  51. ).data
  52. )
  53. userinfo.value.data.user.avatar = API_URL + userinfo.value.data.user.avatar
  54. </script>
  55. <template>
  56. <el-card>
  57. <el-row>
  58. <el-col :span="4">
  59. <div>
  60. <el-avatar :src="userinfo.data.user.avatar? userinfo.data.user.avatar : 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'"
  61. size="large" />
  62. </div>
  63. </el-col>
  64. <el-col :span="20">
  65. <span class="title"
  66. v-html="dp.title" />
  67. <p class="content">{{dp.content}}</p>
  68. <!-- 左边 -->
  69. <div type="text"
  70. style="float: left">
  71. <el-space wrap>
  72. <el-tag type="primary">作者:{{ userinfo.data.user.nickname }}</el-tag>
  73. <el-tag type="info">{{ formatDate(dp.time) }}</el-tag>
  74. <el-tag type="success">回复{{ dp.numberOfReplies?numberOfReplies:0 }}</el-tag>
  75. <el-tag type="warning">浏览量~开发中</el-tag>
  76. </el-space>
  77. </div>
  78. <el-button type="text"
  79. style="float: right"
  80. @click="() => $router.push(`/${data.id}`)">
  81. 去看看
  82. </el-button>
  83. </el-col>
  84. </el-row>
  85. </el-card>
  86. </template>
  87. <style scoped>
  88. .title {
  89. font-size: 14px;
  90. color: #909399;
  91. margin-bottom: 6px;
  92. }
  93. .content {
  94. font-size: 14px;
  95. color: #606266;
  96. }
  97. .title .content {
  98. overflow: hidden;
  99. text-overflow: ellipsis;
  100. white-space: nowrap;
  101. }
  102. </style>