/* eslint-disable eqeqeq */ import IconFont from '@/components/IconFont'; import Limit from '@/components/Limit'; import { CloseOutlined, EditFilled, LoadingOutlined, MessageFilled, } from '@ant-design/icons'; import { Avatar, Popconfirm, Tooltip } from 'antd'; import dayjs from 'dayjs'; import { useEffect, useRef, useState } from 'react'; import ReplyChildCard from './ReplyChildCard'; function difftime(start, end) { const diffInMs = start.diff(end); if (diffInMs < 60 * 60 * 1000) { // 时间差小于 1 小时,转为分钟 const diffInMinutes = Math.round(diffInMs / (60 * 1000)); return diffInMinutes + '分钟前'; } else { // 时间差大于等于 1 小时,继续判断是否超过 24 小时 const diffInHours = Math.round(diffInMs / (60 * 60 * 1000)); if (diffInHours >= 24) { // 时间差超过 24 小时,转为天 const diffInDays = Math.round(diffInHours / 24); return diffInDays + '天前'; } else { // 时间差在 1 小时到 24 小时之间,直接输出小时数 return diffInHours + '小时前'; } } } const emojiarr = ['👍', '👎', '😆', '😊', '😢', '😭', '😂', '🎉', '❤️', '🚀', '👀']; function qc(arr) { let tempArr = []; let obj = {}; let resultArr = []; arr.forEach((v) => { if (!tempArr.includes(v)) { tempArr.push(v); } }); arr.forEach((v) => { if (obj[v]) { obj[v]++; } else { obj[v] = 1; } }); tempArr.forEach((v) => { resultArr.push({ name: v, num: obj[v], }); }); return resultArr; } const ReplyCard = ({ user = {}, reply, bereply_user = {}, otherusers = [], setdoreply, id, doreply, currentUser, drawer, run, loading, info, formRef, children, created_at, curitem, other, }) => { const [curclickid, setcurclickid] = useState(); const intoRef = useRef(); useEffect(() => { if (curitem?.msg_id == id) { intoRef?.current?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start', }); } }, [curitem?.msg_id]); return (
{user?.head_url ? null : user?.user_name?.charAt(0)}
回复 {bereply_user?.user_name}
{qc(info?.map?.((it) => it?.type) ?? [])?.map((it) => { return (
{ setcurclickid(id); if (loading && curclickid == id) return; run({ url: `/webtool/v1/msg/${id}`, params: { emoji: it?.name }, method: 'PUT', }); }} > {emojiarr[it?.name]} {it?.num}
); })}
{emojiarr?.map((it, i) => { return (
{ setcurclickid(id); if (loading && curclickid == id) return; run({ url: `/webtool/v1/msg/${id}`, params: { emoji: i.toString() }, method: 'PUT', }); }} > {it}
); })}
{ e.stopPropagation(); await setdoreply({ ...user, curid: id, type: 'reply', }); setTimeout(() => { intoRef?.current?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start', }); }, 300); }} >
{currentUser?.id == user?.id ? (
{ e.stopPropagation(); await setdoreply({ ...bereply_user, curid: id, type: 'edit1', other: other ?.split(',') ?.filter((it) => it !== '') ?.map((it) => parseInt(it)) ?? [], }); formRef?.current?.setFieldsValue({ reply }); setTimeout(() => { intoRef?.current?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start', }); }, 300); }} > {loading && curclickid == id ? ( ) : ( )}
) : null} {currentUser?.id == user?.id ? ( document.getElementById(`container${id}`)} onConfirm={(e) => { e.stopPropagation(); setcurclickid(id); run({ url: `/webtool/v1/msg/${id}`, params: {}, method: 'DELETE' }); }} onCancel={(e) => { e.stopPropagation(); }} >
{ e.stopPropagation(); }} > {loading && curclickid == id ? ( ) : ( )}
) : null}
{difftime(dayjs(), dayjs(created_at))} 0 ? 'inline' : 'none' }}> @{' '} {otherusers?.map?.((it) => ( {it?.user_name} ))}
{children?.map((it) => { return ( { setdoreply(val); }} /> ); })}
); }; export default ReplyCard