fix: truncate long comment nicknames
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
<view class="comment-card__author">
|
<view class="comment-card__author">
|
||||||
<image class="comment-card__avatar" :src="getCommentAvatar(item)" mode="aspectFill"
|
<image class="comment-card__avatar" :src="getCommentAvatar(item)" mode="aspectFill"
|
||||||
@error="handleAvatarError" />
|
@error="handleAvatarError" />
|
||||||
<text class="comment-card__name">{{ item.user?.nickname || '我' }}</text>
|
<text class="comment-card__name">{{ formatNickname(item.user?.nickname) }}</text>
|
||||||
<text class="comment-card__label">{{ item.reply_to ? '回复了评论' : '评论了帖子' }}</text>
|
<text class="comment-card__label">{{ item.reply_to ? '回复了评论' : '评论了帖子' }}</text>
|
||||||
</view>
|
</view>
|
||||||
<text class="comment-card__time">{{ formatTime(item.create_time) }}</text>
|
<text class="comment-card__time">{{ formatTime(item.create_time) }}</text>
|
||||||
@@ -98,6 +98,12 @@ const handleAvatarError = () => {
|
|||||||
avatarLoadFailed.value = true
|
avatarLoadFailed.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatNickname = (value?: string) => {
|
||||||
|
const name = String(value || '我')
|
||||||
|
const characters = Array.from(name)
|
||||||
|
return characters.length > 4 ? `${characters.slice(0, 4).join('')}…` : name
|
||||||
|
}
|
||||||
|
|
||||||
const parseTimestamp = (value: string | number) => {
|
const parseTimestamp = (value: string | number) => {
|
||||||
if (typeof value === 'number') return value
|
if (typeof value === 'number') return value
|
||||||
return new Date(String(value).replace(/-/g, '/')).getTime() / 1000
|
return new Date(String(value).replace(/-/g, '/')).getTime() / 1000
|
||||||
|
|||||||
Reference in New Issue
Block a user