123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <template>
- <view class="tabs-content" :style="{ paddingBottom : `${props.paddingBottom || 0}rpx` }">
- <view v-for="(comment, index) in sortedCommentList" :key="index" class="comment-list-item">
- <view class="comment-list-left">
- <image src="/static/images/weixin.png" class="comment-list-avator"></image>
- </view>
- <view class="comment-list-right">
- <view style="margin-bottom: 15rpx;">
- <text class="comment-list-username">{{ comment.yongHuMing }}</text>
- <text class="comment-list-moment">{{ formatTime(comment.pingLunShiJian) }}</text>
- </view>
- <view>{{ comment.pingLunNeiRong }}</view>
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import {
- ref,
- defineProps,
- computed
- } from 'vue'
- const props = defineProps({
- paddingBottom: {
- type: Number,
- required: false,
- default: 10
- },
- commentList: {
- type: Array,
- required: false,
- default: () => []
- },
- });
-
- function formatDate(dateStr) {
- return dateStr.replace(" ", "T"); // Replace space with 'T' to make it ISO format
- }
-
- function formatTime(timeString) {
- const commentDate = new Date(formatDate(timeString));
- const now = new Date();
- const diff = now - commentDate; // Difference in milliseconds
-
- const minutes = Math.floor(diff / 60000); // Convert milliseconds to minutes
- const hours = Math.floor(diff / 3600000); // Convert milliseconds to hours
- const days = Math.floor(diff / 86400000); // Convert milliseconds to days
-
- if (minutes < 1) { // 修改这里以处理0分钟
- return "刚刚";
- } else if (minutes < 60) {
- return `${minutes}分钟前`;
- } else if (hours < 24) {
- return `${hours}小时前`;
- } else {
- return commentDate.toISOString().split('T')[0]; // Return date in yyyy-MM-dd format
- }
- }
-
- const sortedCommentList = computed(() => {
- return props.commentList.sort((a, b) =>
- new Date(formatDate(b.pingLunShiJian)) - new Date(formatDate(a.pingLunShiJian))
- );
- });
- </script>
- <style lang="scss" scoped>
- .tabs-content{
- padding-top: 10rpx;
- }
- .comment-list-item {
- display: flex;
- padding: 20rpx 0;
- font-size: 24rpx;
- .comment-list-left{
- flex: 0 0 auto;
- padding-right: 20rpx;
- padding-left: 10rpx;
- .comment-list-avator{
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- }
- }
- .comment-list-right{
- flex: 1;
- .comment-list-username{
- padding-right: 25rpx;
- font-size: 32rpx;
- font-weight: bold;
- }
- }
- }
- </style>
|