import { View, TouchableOpacity, Text, Alert } from "react-native"; import React from "react"; import { Icon } from "@rneui/themed"; import { useTailwind } from "tailwind-rn"; import { formatDate, goToPage } from "../../../../utils/tools"; import { Image } from "expo-image"; import Toast from "react-native-toast-message"; import * as Linking from "expo-linking"; import dayjs from "dayjs"; export default function NoticeItem({ navigation, leftIcon, hasLink, data }) { const tailwind = useTailwind(); // const currentLink = useMemo(() => { // if (hasLink && data?.hyperlinks) { // const hasAppLink = data.hyperlinks.filter( // (it) => it.action === "app_router_path" // )[0]; // return hasAppLink ?? null; // } // }, [data]); //日期格式 const renderDay = (time) => { const now = dayjs(); if (now.diff(dayjs(time * 1000), "hour") - now.hour() < 1) { return dayjs(time * 1000).format("HH:mm"); } else if (now.diff(dayjs(time * 1000), "hour") - now.hour() < 24) { return "昨天" + dayjs(time * 1000).format("HH:mm"); } else { return dayjs(time * 1000).format("MM-DD"); } }; return ( {/* 内容 */} {/* 文本内容 */} {/* 头像 */} {/* */} {leftIcon} {data?.title} {data?.message} {/* 链接跳转 */} {!!data?.link_text && ( { console.log("此链接已失效", data.is_valid); if (!data.is_valid) { Toast.show({ type: "error", text1: "此链接已失效", topOffset: 60, }); return; } if (data?.hyperlinks) { // const linkStr = goToPage(data?.hyperlinks[0]?.params); const links = data?.hyperlinks; let link = null; if (links.length > 1) { link = links.filter((it) => it.action === "inward")[0] ?.params; } else { link = links[0]?.params; } const linkAndParams = goToPage({ url: link, action: links[0]?.action, }); if (typeof linkAndParams === "string") { if ( links[0]?.action === "webViewHeaderInward" || links[0]?.action === "webViewHeaderOutward" ) { navigation.navigate("WebWithHeader", { title: "", uri: linkAndParams, }); return; } else if ( links[0]?.action === "webViewWithOutHeaderInward" || links[0]?.action === "webViewWithOutHeaderOutward" ) { navigation.navigate("WebWithoutHeader", { title: "", uri: linkAndParams, }); return; } try { // 尝试启动微信客户端 Linking.openURL(linkAndParams).catch(() => { // 启动微信客户端失败,弹出提示安装对话框 Alert.alert( "错误提醒", "打开链接失败,请返回重试或者联系在线客服", [{ text: "确认", style: "cancel" }], { cancelable: false } ); }); } catch (error) { // 启动微信客户端失败,继续加载URL console.error(error); } } else { navigation.navigate(...linkAndParams); } // if (linkAndParams) { // if (typeof linkAndParams === "object") { // navigation.navigate(...linkAndParams); // } else { // // if (linkAndParams.indexOf("JoinStreamer") != -1) { // // navigation.navigate("StreamerVerification", { // // screen: "JoinStreamer", // // }); // // } else if ( // // linkAndParams.indexOf( // // "CompleteStreamerInformation" // // ) != -1 // // ) { // // navigation.navigate("StreamerVerification", { // // screen: "CompleteStreamerInformation", // // }); // // return; // // } // navigation.navigate(linkAndParams); // } // } // console.log(linkStr); // if (linkStr.indexOf("JoinStreamer") != -1) { // navigation.navigate("StreamerVerification", { // screen: "JoinStreamer", // }); // return; // } else if ( // linkStr.indexOf("CompleteStreamerInformation") != -1 // ) { // navigation.navigate("StreamerVerification", { // screen: "CompleteStreamerInformation", // }); // return; // } // navigation.navigate(linkStr); } }} style={{ ...tailwind("rounded-xl p-2 flex flex-row items-center my-2"), backgroundColor: "#FFFFFF1A", }} > {hasLink.text} )} {/* 时间 */} {renderDay(data?.push_time || data?.ct)} ); }