tiefen_space_h5/app/noticeDetail/components/NoticeItem/index.jsx

99 lines
3.7 KiB
React
Raw Normal View History

2024-12-13 18:24:36 +08:00
import React, { useMemo } from "react";
import { formatTimestamp, goToPage } from "@/utils/tools";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleRight } from "@fortawesome/free-solid-svg-icons";
import { useRouter } from "next/navigation";
2024-12-17 17:31:50 +08:00
import { Image } from "antd-mobile";
2024-12-13 18:24:36 +08:00
export default function NoticeItem({ navigation, leftIcon, hasLink, data }) {
const router = useRouter();
const currentLink = useMemo(() => {
if (hasLink && data?.hyperlinks) {
const hasAppLink = data.hyperlinks.filter(
(it) => it.action === "app_router_path"
)[0];
return hasAppLink ?? null;
}
}, [data]);
return (
<div className="bg-[#FFFFFF1A] rounded-2xl mb-2 py-[24px] px-[18px]">
2024-12-17 17:31:50 +08:00
<div className="flex text-white">
2024-12-13 18:24:36 +08:00
<div className="flex-1">
{/* 内容 */}
<div>
{/* 文本内容 */}
<div className="flex items-center">
{/* 头像 */}
<div className="flex justify-center items-center rounded-full mr-2 w-[28px] h-[28px]">
{/* <Icon type="ionicon" name="megaphone" size={24} color="white" /> */}
{leftIcon}
</div>
2024-12-17 17:31:50 +08:00
<p className="text-lg font-medium mr-2 ">{data?.title}</p>
2024-12-13 18:24:36 +08:00
</div>
2024-12-19 18:33:13 +08:00
<pre className="text-base font-medium my-2 whitespace-pre-wrap">
{data?.message}
</pre>
2024-12-13 18:24:36 +08:00
{/* 链接跳转 */}
2024-12-17 17:31:50 +08:00
{!!data?.hyperlinks && (
2024-12-13 18:24:36 +08:00
<div
onClick={() => {}}
className="rounded-xl p-2 flex flex-row items-center my-2 bg-[#FFFFFF1A]"
>
<div className="mr-2 bg-white rounded-lg w-[50px] h-[50px]">
2024-12-17 17:31:50 +08:00
<Image
2024-12-13 18:24:36 +08:00
// style={{ transform: [{ scale: 0.9 }] }}
2024-12-17 17:31:50 +08:00
// width={120}
className="rounded-lg"
height="100%"
fit="cover"
src={data.thumbnail?.images[0].urls[0]}
/>
2024-12-13 18:24:36 +08:00
</div>
<div
className="flex flex-row justify-between flex-1 px-4 items-center"
onClick={() => {
2024-12-17 17:31:50 +08:00
const links = data?.hyperlinks;
if (links) {
2024-12-13 18:24:36 +08:00
// const linkAndParams = goToPage(
2024-12-17 17:31:50 +08:00
// links[1]?.params
2024-12-13 18:24:36 +08:00
// );
// if (linkAndParams) {
// typeof linkAndParams === "object"
// ? router.push(...linkAndParams)
// : router.push(linkAndParams);
// }
2024-12-17 17:31:50 +08:00
if (links.length > 1) {
links[1]?.action === "app_router_path";
router.push(links[1]?.params);
} else {
links[0]?.action === "outward";
router.push(links[0]?.params);
}
2024-12-13 18:24:36 +08:00
}
}}
>
<span className="text-base font-medium mr-2">
{hasLink.text}
</span>
<div>
<FontAwesomeIcon
icon={faAngleRight}
style={{ maxWidth: "12px" }}
size="xl"
/>
</div>
</div>
</div>
)}
</div>
{/* 时间 */}
<div>
<span className="text-xs text-[#FFFFFF80]">
2024-12-17 17:31:50 +08:00
{formatTimestamp(data?.push_time || data?.ct)}
2024-12-13 18:24:36 +08:00
</span>
</div>
</div>
</div>
</div>
);
}