import { renderRichTextToReact } from '@kkk/richtext' import { differenceInSeconds, format, formatDistanceToNow } from 'date-fns' import { zhCN } from 'date-fns/locale' import { Heart, MessageCircle } from 'lucide-react' import React from 'react' import { isDark } from '../../../../utils/theme' import { DefaultLayout } from '../../../components/DefaultLayout' import { QRCodeWithAvatar } from '../../../components/QRCodeWithAvatar' import type { PosterProps } from '../../../types/ctx' import type { KuaishouCommentData } from './types' const kuaishouMentionClassName = 'text-[#03488d] dark:text-[#c7daef]' const renderKuaishouCommentRichText = (content: KuaishouCommentData['CommentsData'][0]['text']) => { return renderRichTextToReact(content, { mention: { className: kuaishouMentionClassName } }) } const formatKuaishouCommentTime = (timestamp: number): string => { if (!timestamp) { return '' } const commentDate = new Date(timestamp) const diffSeconds = differenceInSeconds(new Date(), commentDate) if (diffSeconds < 30) { return '刚刚' } if (diffSeconds < 7776000) { return formatDistanceToNow(commentDate, { locale: zhCN, addSuffix: true }) } return format(commentDate, 'yyyy-MM-dd') } const formatKuaishouLikeCount = (count: number): string => { if (count >= 10000) { return `${(count / 10000).toFixed(1)}w` } return String(count) } /** * 快手二维码组件 * @param props 组件属性 * @returns JSX元素 */ const KuaishouQRCodeSection: React.FC = (props) => { return (
{props.Type === '视频' ? '视频直链(永久)' : props.Type === '图集' ? `图集分享链接 共${props.ImageLength}张` : '分享链接'}
) } /** * 快手视频信息头部组件 * @param props 组件属性 * @returns JSX元素 */ const KuaishouVideoInfoHeader: React.FC = (props) => { return (
快手Logo { const target = e.target as HTMLImageElement target.style.display = 'none' const parent = target.parentElement if (parent) { parent.innerHTML = '
快手
' } }} />
评论数量:{props.CommentLength}条
{props.Type === '视频' && ( <>
视频大小:{props.VideoSize}MB
点赞数量:{props.likeCount}
观看次数:{props.viewCount}
)} {props.Type === '图集' && (
图片数量:{props.ImageLength}张
)}
) } /** * 快手单个评论组件 * @param props 组件属性 * @returns JSX元素 */ const KuaishouCommentItemComponent: React.FC = ( { ...props }, isLast = false ) => { return (
用户头像
{props.nickname}
{renderKuaishouCommentRichText(props.text)}
{(props.commentimage || props.sticker) && (
评论图片
)}
{formatKuaishouCommentTime(props.create_time)} {props.ip_label && {props.ip_label}} {props.reply_comment_total && props.reply_comment_total > 0 ? ( 共{props.reply_comment_total}条回复 ) : ( 回复 )}
{formatKuaishouLikeCount(props.digg_count)}
) } /** * 快手评论组件 * @param props 组件属性 * @returns JSX元素 */ export const KuaishouComment: React.FC> = React.memo((props) => { const commentsArray = Array.isArray(props.data?.CommentsData) ? props.data.CommentsData : [] return (
{commentsArray.length > 0 ? ( commentsArray.map((comment, index) => ( )) ) : (

暂无评论数据

)}
) }) export default KuaishouComment