"use client"; import React, { useEffect, useState, useMemo, useCallback } from "react"; import Photos from "../Photos"; import { useRouter } from "next/navigation"; import PaySpacePost from "../PaySpacePost"; import { Image, Popover, Divider, Toast } from "antd-mobile"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleRight } from "@fortawesome/free-solid-svg-icons"; import { handleFollow, thumbsUp, handleBlock } from "@/api/public"; import { get } from "@/utils/storeInfo"; import { Inter } from "next/font/google"; import requireAPI from "@/utils/requireAPI"; import { getcountLines } from "@/utils/tools"; const inter = Inter({ subsets: ["latin"] }); export default function PostItem({ type, follow, date = new Date(), data = {}, showFollow = true, }) { const router = useRouter(); const [isOpenText, setIsOpenText] = useState(false); const [popoverVisible, setPopoverVisible] = useState(false); const [isFollow, setIsFollow] = useState(data.is_followed); const [isThumbsUp, setIsThumbsUp] = useState( data?.is_thumbed_up || data?.is_zone_moment_thumbed_up ); const [account, setAccount] = useState( data?.is_thumbed_up || data?.is_zone_moment_thumbed_up ); //判断是否是发帖人 const [isCreator, setIsCreator] = useState(false); useEffect(() => { const currentAccount = get("account"); setAccount(currentAccount); if (currentAccount?.mid === data.mid) setIsCreator(true); return () => { router.prefetch("/profile/" + data.mid); }; }, []); const getDays = useMemo(() => { const today = new Date(); const days = Math.floor((today - data.ct) / (1000 * 60 * 60 * 24)); return days; }, []); function findLinksInText(text) { // 定义一个正则表达式来匹配URL // 注意:这个正则表达式可能无法匹配所有可能的URL,但可以匹配大部分常见的格式 var urlPattern = /https?:\/\/[^\s\/$.?#].[^\s]*/g; // 使用正则表达式的exec或match方法查找匹配项 // exec在全局搜索中需要循环调用,而match在全局模式下直接返回所有匹配项 var matches = text?.match(urlPattern); // // 如果没有找到匹配项,返回空数组 // if (!matches) { // return text; // } if (matches) { matches?.forEach((el) => { // console.log("index", text.indexOf(el)); text = text.replace( el, `#网页链接` ); }); // console.log("matches", matches); // console.log("text", text); } // 返回找到的链接数组 return text; } const formatZoneUpdateTime = useCallback((time) => { if (time === 0) return "今日"; if (time === 1) return "昨日"; return `${time}日前`; }, []); const handleDelete = async (type) => { try { const _data = await requireAPI( "POST", `/api/${type == "space" ? "zone_moment" : "moment"}/delete`, { body: { id: data?.id, }, } ); if (_data.ret === -1) { Toast.show({ icon: "fail", content: _data.msg, position: "top", }); return; } Toast.show({ icon: "success", content: "删除成功,请刷新页面", position: "top", }); return; } catch (error) { console.error(error); } finally { setPopoverVisible(false); } }; //置顶 const handleTop = async () => { try { const body = { zone_moment_ids: [data.id], op_type: data.is_headed ? 0 : 1, }; const _data = await requireAPI("POST", "/api/zone_moment/head", { body, }); if (_data.ret === -1) { Toast.show({ icon: "fail", content: _data.msg, position: "top", }); return; } Toast.show({ icon: "success", content: "操作成功,请刷新页面查看", position: "top", }); return; } catch (error) { console.error(error); } finally { setPopoverVisible(false); } }; return (
{ router.push( `${ type == "space" ? "/space/editSpacePost" : "/streamerPosts/editPost" }/${data.id}` ); }} > 审核未通过,请重新编辑。
)}