修复 时间 格式化为题
This commit is contained in:
@@ -3,6 +3,7 @@ import { View, Text, ScrollView, Image, Input } from "@tarojs/components";
|
||||
import { Avatar } from "@nutui/nutui-react-taro";
|
||||
import { withAuth, EmptyState } from "@/components";
|
||||
import commentService, { CommentActivity } from "@/services/commentService";
|
||||
import { formatShortRelativeTime } from "@/utils/timeUtils";
|
||||
import Taro from "@tarojs/taro";
|
||||
import "./index.scss";
|
||||
|
||||
@@ -78,31 +79,6 @@ const CommentReply = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化时间显示
|
||||
const formatTime = (timeStr: string) => {
|
||||
if (!timeStr) return "";
|
||||
|
||||
const date = new Date(timeStr);
|
||||
const now = new Date();
|
||||
const diff = now.getTime() - date.getTime();
|
||||
const minutes = Math.floor(diff / (1000 * 60));
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (minutes < 60) {
|
||||
return `${minutes}分钟前`;
|
||||
} else if (hours < 24) {
|
||||
return `${hours}小时前`;
|
||||
} else if (days === 1) {
|
||||
return "1天前";
|
||||
} else if (days < 7) {
|
||||
return `${days}天前`;
|
||||
} else {
|
||||
const month = date.getMonth() + 1;
|
||||
const day = date.getDate();
|
||||
return `${month}月${day}日`;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理回复
|
||||
const handleReply = (e: any, item: CommentReplyItem) => {
|
||||
@@ -266,7 +242,7 @@ const CommentReply = () => {
|
||||
|
||||
<View className="action-row">
|
||||
<Text className="action-text">{actionText}</Text>
|
||||
<Text className="time-text">{formatTime(item.time)}</Text>
|
||||
<Text className="time-text">{formatShortRelativeTime(item.time)}</Text>
|
||||
</View>
|
||||
|
||||
<Text className="comment-text">{item.content}</Text>
|
||||
|
||||
Reference in New Issue
Block a user