tiefen_space_h5/app/profile/[mid]/page.js

595 lines
21 KiB
JavaScript
Raw Normal View History

2024-07-06 11:05:19 +08:00
"use client";
import React, { useEffect, useRef, useState } from "react";
import {
Image,
Swiper,
Divider,
ImageViewer,
Popover,
Toast,
} from "antd-mobile";
import { useRouter, useParams } from "next/navigation";
2024-07-15 20:00:44 +08:00
import Link from "next/link";
2024-07-06 11:05:19 +08:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faAngleLeft,
faAngleRight,
faEllipsisVertical,
faWarning,
2024-10-23 16:06:06 +08:00
faCircleMinus,
2024-07-06 11:05:19 +08:00
} from "@fortawesome/free-solid-svg-icons";
2024-07-22 16:07:41 +08:00
import requireAPI from "@/utils/requireAPI";
2024-07-06 11:05:19 +08:00
import AddWeChat from "@/components/AddWeChat";
2024-10-23 16:06:06 +08:00
import { handleFollow, checkRelation, handleBlock } from "@/api/public";
2024-07-08 20:07:36 +08:00
import { getStreamerDetailInfo } from "@/api/space";
2024-07-06 11:05:19 +08:00
import { get } from "@/utils/storeInfo";
2024-08-07 19:33:31 +08:00
import { handleShowVideo } from "@/utils/tools/handleFuns";
2024-07-15 20:00:44 +08:00
import clipboard from "copy-to-clipboard";
2024-08-16 13:29:14 +08:00
import ImagesMask from "@/components/ImagesMask";
2024-07-06 11:05:19 +08:00
// import * as Clipboard from "expo-clipboard";
export default function PersonSpace() {
const { mid } = useParams();
const router = useRouter();
const [streamerInfo, setStreamerInfo] = useState(null);
const [spaceData, setSpaceData] = useState(null);
const [loading, setLoading] = useState(false);
const [visible, setVisible] = useState(false);
const [isFollow, setIsFollow] = useState(false);
2024-07-06 16:03:15 +08:00
const [topPhotos, setTopPhotos] = useState([]);
2024-10-23 16:06:06 +08:00
const [account, setAccount] = useState([]);
2024-08-07 19:02:47 +08:00
const currentIndex = useRef();
2024-08-16 13:29:14 +08:00
const imagesMaskRef = useRef(null);
2024-07-06 11:05:19 +08:00
// 获取屏幕高度
// const scrollHeight = 600;
useEffect(() => {
2024-07-08 20:07:36 +08:00
handleGetStreamerInfo();
2024-07-06 11:05:19 +08:00
getSpaceData();
getRelationData();
2024-10-23 16:06:06 +08:00
const account = get("account");
setAccount(account);
2024-07-06 11:05:19 +08:00
}, []);
const showPhotos = (photos, index) => {
2024-08-07 19:02:47 +08:00
currentIndex.current = index;
2024-08-16 13:29:14 +08:00
imagesMaskRef.current.show(photos, index, streamerInfo);
2024-08-07 19:02:47 +08:00
};
2024-07-08 20:07:36 +08:00
const handleGetStreamerInfo = async () => {
2024-07-06 11:05:19 +08:00
try {
setLoading(true);
2024-07-08 20:07:36 +08:00
const data = await getStreamerDetailInfo(Number(mid));
2024-07-06 11:05:19 +08:00
setStreamerInfo({
2024-07-08 20:07:36 +08:00
...data,
2024-07-06 11:05:19 +08:00
});
2024-07-06 16:03:15 +08:00
const photosArr = [
2024-07-08 20:07:36 +08:00
...data?.streamer_ext?.cover?.images?.map((item) => ({
2024-07-06 16:03:15 +08:00
url: item.urls[0],
type: "video",
})),
2024-07-08 20:07:36 +08:00
...data?.streamer_ext?.album?.images.map((item) => ({
2024-07-06 16:03:15 +08:00
url: item.urls[0],
type: "img",
})),
];
2024-08-05 18:59:30 +08:00
// console.log("photosArr", photosArr);
2024-07-06 16:03:15 +08:00
setTopPhotos(photosArr);
2024-07-06 11:05:19 +08:00
setLoading(false);
} catch (error) {
2024-09-09 15:34:31 +08:00
// console.error(error);
2024-07-06 11:05:19 +08:00
}
};
const getSpaceData = async () => {
try {
2024-07-22 16:07:41 +08:00
const data = await requireAPI("POST", "/api/zone/list_by_mid", {
2024-07-06 11:05:19 +08:00
body: {
mid: Number(mid),
},
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
setSpaceData(data.data.list[0]);
} catch (error) {
2024-09-09 15:34:31 +08:00
// console.error(error);
2024-07-06 11:05:19 +08:00
}
};
const getRelationData = async () => {
const account = get("account");
const subMid = account.mid;
const objMid = Number(mid);
const temIsFollowed = await checkRelation(subMid, objMid, 0);
setIsFollow(temIsFollowed);
};
2024-07-15 20:00:44 +08:00
//保存内容到剪贴板
const copy = (_data) => {
2024-08-05 18:59:30 +08:00
// console.log("_data", _data);
2024-07-15 20:00:44 +08:00
clipboard(_data);
Toast.show({
icon: "success",
content: "已复制到剪贴板",
position: "top",
});
};
2024-07-06 11:05:19 +08:00
return (
2024-07-08 20:07:36 +08:00
<div className="h-screen overflow-x-hidden overflow-y-auto">
2024-07-06 11:05:19 +08:00
<div className="flex justify-between items-center p-4 fixed top-0 z-10 w-full">
<div className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full">
<FontAwesomeIcon
icon={faAngleLeft}
size="xl"
style={{ maxWidth: "12px" }}
2024-07-06 11:05:19 +08:00
onClick={() => {
router.back();
}}
/>
</div>
2024-10-23 16:06:06 +08:00
{get("account")?.mid != mid && (
<Popover
stopPropagation={["click", "touchstart"]}
destroyOnHide={true}
style={{ "--background": "#1E1C29" }}
content={
<ul>
<li
onClick={async () => {
const account = await get("account");
const subMid = account.mid;
const objMid = mid;
handleBlock(subMid, Number(mid));
}}
>
<FontAwesomeIcon
icon={faCircleMinus}
// size="xl"
color="#f87171"
className="mr-4"
/>
<span>拉黑</span>
</li>
<hr className="border-[#ffffff2b] my-1" />
<li
onClick={() => {
router.push("/messageDetail");
}}
>
<FontAwesomeIcon
icon={faWarning}
// size="xl"
2024-10-22 17:24:02 +08:00
2024-10-23 16:06:06 +08:00
color="#3B69B8"
className="mr-4"
/>
<span>举报</span>
</li>
</ul>
}
trigger="click"
placement="left"
>
<div className="w-[36px] flex justify-center">
<FontAwesomeIcon
icon={faEllipsisVertical}
size="xl"
style={{ maxWidth: "5px" }}
/>
</div>
</Popover>
)}
2024-07-06 11:05:19 +08:00
</div>
{/* 内容 */}
2024-07-08 20:07:36 +08:00
<div className="overflow-y-auto">
<div className="min-h-[60px]">
{!!topPhotos.length && (
2024-07-06 16:03:15 +08:00
<Swiper
autoplay
loop
indicatorProps={{
style: {
"--dot-color": "#FF669E30",
"--active-dot-color": "#FF669E",
},
}}
>
{topPhotos.map((photo, index) => (
<Swiper.Item key={index}>
<div
2024-07-23 20:57:21 +08:00
className="relative min-w-full max-w-[100vw]"
2024-07-06 16:03:15 +08:00
key={index}
onClick={() => {
if (photo.type == "video") {
2024-08-07 19:33:31 +08:00
handleShowVideo({
2024-07-08 20:07:36 +08:00
url: streamerInfo?.streamer_ext?.shorts?.videos[0]
?.cover_urls[0],
mp4: streamerInfo?.streamer_ext?.shorts?.videos[0]
?.urls[0],
});
2024-07-06 16:03:15 +08:00
} else {
2024-07-08 20:07:36 +08:00
showPhotos(
topPhotos.filter((it) => it.type == "img"),
2024-08-16 13:29:14 +08:00
topPhotos
.filter((it) => it.type == "img")
.indexOf(photo)
2024-07-08 20:07:36 +08:00
);
2024-07-06 16:03:15 +08:00
}
}}
>
<Image
className="h-12 w-full"
fit="cover"
height={320}
src={photo?.url}
// onClick={() => {
// Toast.show(`你点击了卡片 ${index + 1}`);
// }}
/>
{photo.type == "video" && (
<div className="absolute top-0 w-full h-full flex justify-center items-center bg-[#33333348]">
<Image
className=""
width={98}
height={98}
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/play.png"
}
2024-07-06 16:03:15 +08:00
/>
</div>
)}
</div>
</Swiper.Item>
))}
</Swiper>
2024-07-08 20:07:36 +08:00
)}
</div>
2024-07-06 11:05:19 +08:00
<div className="p-4 pb-24">
<div>
<div className="mb-2">
<div className="flex items-center mb-2">
<p className="text-2xl mr-2">
{streamerInfo?.streamer_ext?.name}
</p>
<div className="w-5 h-5">
2024-08-16 13:29:14 +08:00
<Image
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/verification.png"
}
/>
2024-07-06 11:05:19 +08:00
</div>
</div>
<ul className="flex">
2024-07-06 16:03:15 +08:00
{streamerInfo?.streamer_ext?.tag?.map((item, index) => (
2024-07-06 11:05:19 +08:00
<li
key={index}
className="rounded-md bg-primary mr-2 px-2 py-1 text-xs mb-1"
>
{item}
</li>
))}
</ul>
</div>
<div>
2024-07-08 20:07:36 +08:00
<ul className="flex mb-1 flex-wrap">
<li className="h-4 flex items-center text-xs bg-[#FFFFFF1A] rounded-full px-2 py-2.5 mb-1 mr-1">
2024-07-06 11:05:19 +08:00
<Image
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/ID.png"
}
2024-07-06 11:05:19 +08:00
width={14}
height={14}
className="w-4 h-full mr-1"
/>
<span>{streamerInfo?.streamer_ext?.user_id}</span>
</li>
2024-07-15 20:00:44 +08:00
<li className="h-4 flex items-center text-xs bg-[#FFFFFF1A] rounded-full px-2 py-2.5 mb-1 mr-1">
2024-07-08 20:07:36 +08:00
<Image
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/fan.png"
}
2024-07-08 20:07:36 +08:00
width={14}
height={14}
className="w-4 h-full mr-1"
/>
<span className="text-white text-xs font-medium ml-0.5">
2024-07-12 22:52:48 +08:00
{`全网粉丝 : ${streamerInfo?.streamer_ext?.fans || 0}`}
2024-07-08 20:07:36 +08:00
</span>
</li>
{streamerInfo?.streamer_ext?.age && (
<li className="h-4 flex items-center text-xs bg-[#FFFFFF1A] rounded-full px-2 py-2.5 mb-1 mr-1">
{streamerInfo?.streamer_ext?.gender === 1 ? (
<Image
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/female.png"
}
2024-07-08 20:07:36 +08:00
width={14}
height={14}
className="w-4 h-full mr-1"
/>
) : (
<Image
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/male.png"
}
2024-07-08 20:07:36 +08:00
width={14}
height={14}
className="w-4 h-full mr-1"
/>
)}
<span className="text-white text-xs font-medium ml-0.5">
{streamerInfo?.streamer_ext?.age}
</span>
</li>
)}
{streamerInfo?.streamer_ext?.height && (
<li className="h-4 flex items-center text-xs bg-[#FFFFFF1A] rounded-full px-2 py-2.5 mb-1 mr-1">
<Image
width={14}
height={14}
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/height.png"
}
2024-07-08 20:07:36 +08:00
className="w-4 h-full mr-1"
/>
<span className="text-white text-xs font-medium ml-0.5">
{`${streamerInfo?.streamer_ext?.height}cm`}
</span>
</li>
)}
{streamerInfo?.streamer_ext?.weight && (
<li className="h-4 flex items-center text-xs bg-[#FFFFFF1A] rounded-full px-2 py-2.5 mb-1 mr-1">
<Image
width={14}
height={14}
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/weight.png"
}
2024-07-08 20:07:36 +08:00
className="w-4 h-full mr-1"
/>
<span className="text-white text-xs font-medium ml-0.5">
{`${streamerInfo?.streamer_ext?.weight}kg`}
</span>
</li>
)}
{streamerInfo?.streamer_ext?.constellation && (
<li className="h-4 flex items-center text-xs bg-[#FFFFFF1A] rounded-full px-2 py-2.5 mb-1 mr-1">
<Image
width={14}
height={14}
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/constellation.png"
}
2024-07-08 20:07:36 +08:00
className="w-4 h-full mr-1"
/>
<span className="text-white text-xs font-medium ml-0.5">
{streamerInfo?.streamer_ext?.constellation}
</span>
</li>
)}
{streamerInfo?.streamer_ext?.city && (
<li className="h-4 flex items-center text-xs bg-[#FFFFFF1A] rounded-full px-2 py-2.5 mb-1 mr-1">
<Image
width={14}
height={14}
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/location.png"
}
2024-07-08 20:07:36 +08:00
className="w-4 h-full mr-1"
/>
<span className="text-white text-xs font-medium ml-0.5">
{streamerInfo?.streamer_ext?.city}
</span>
</li>
)}
2024-07-06 11:05:19 +08:00
</ul>
2024-07-06 16:03:15 +08:00
{streamerInfo?.streamer_ext?.bio && (
2024-08-16 13:29:14 +08:00
<div
className="whitespace-pre-wrap"
style={{ overflowWrap: "anywhere" }}
>
<span className="text-[#ffffff88]">个性签名</span>
{streamerInfo?.streamer_ext?.bio}
</div>
2024-07-06 16:03:15 +08:00
)}
2024-07-06 11:05:19 +08:00
</div>
</div>
2024-08-16 13:29:14 +08:00
{spaceData && !!spaceData?.previews?.images?.length && (
2024-07-19 16:22:43 +08:00
<>
<Divider />
<div>
<div
onClick={() =>
router.push(
spaceData?.visitor_role === 4
? `/space/person_space_introduce/${mid}`
: `/space/${mid}`
)
}
>
<div className="flex justify-between items-center mb-2">
<span className="font-bold text-base">空间动态</span>
<div className="h-4 text-xs text-[#ffffff88]">
<span className="mr-2">
查看{spaceData?.zone_moment_count}
</span>
<FontAwesomeIcon
icon={faAngleRight}
size="xl"
style={{ maxWidth: "12px" }}
2024-07-19 16:22:43 +08:00
className="h-4"
onClick={() => {
router.back();
}}
/>
</div>
2024-07-06 11:05:19 +08:00
</div>
2024-07-19 16:22:43 +08:00
<div className="flex ">
2024-08-16 13:29:14 +08:00
{spaceData?.previews?.images
?.slice(0, 4)
.map((item, index) => (
<div
key={item.id}
className="w-20 h-20 overflow-hidden rounded mr-1"
>
<Image
width="20vw"
height="20vw"
className={`rounded mr-2 ${
spaceData?.visitor_role === 4 && "imageBlur"
}`}
fit="cover"
src={item.urls[0]}
/>
</div>
))}
2024-07-19 16:22:43 +08:00
</div>
</div>
2024-07-06 11:05:19 +08:00
</div>
2024-07-19 16:22:43 +08:00
</>
2024-08-16 13:29:14 +08:00
)}
2024-07-06 11:05:19 +08:00
2024-07-15 20:00:44 +08:00
<>
<Divider />
<div>
<p className="font-bold mb-2 text-base">来这找我玩</p>
2024-07-06 11:05:19 +08:00
2024-07-15 20:00:44 +08:00
<ul>
<li className="flex justify-between border-[1.5px] border-[#ffffff43] rounded-xl p-2 mb-2">
<div className="flex justify-between items-center">
<Image
height={32}
width={32}
className="mr-2"
2024-08-16 13:29:14 +08:00
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/images/platform_wechat.png"
}
2024-07-15 20:00:44 +08:00
/>
<div className="text-base">
<span>微信</span>
2024-07-19 16:22:43 +08:00
<span
2024-07-25 19:52:30 +08:00
className="text-[#3B69B8]"
2024-07-19 16:22:43 +08:00
onClick={() => setVisible(true)}
>
点击查看
</span>
2024-07-15 20:00:44 +08:00
</div>
</div>
</li>
{streamerInfo?.streamer_ext?.platforms?.map((item) => (
<li
key={item.id}
2024-08-02 22:12:54 +08:00
className="grid gap-1 justify-between border-[1.5px] border-[#ffffff43] rounded-xl p-2"
2024-08-16 13:29:14 +08:00
style={{ gridTemplateColumns: "calc(100% - 130px) 130px" }}
2024-07-15 20:00:44 +08:00
>
2024-08-05 13:10:33 +08:00
<div className="flex items-center">
2024-07-06 11:05:19 +08:00
<Image
height={32}
width={32}
className="mr-2"
2024-07-15 20:00:44 +08:00
src={item?.icon.images[0].urls[0]}
2024-07-06 11:05:19 +08:00
/>
2024-08-02 22:12:54 +08:00
<div className="text-base truncate">
2024-08-16 13:29:14 +08:00
{item?.link_name}{item?.nickname}
2024-07-06 11:05:19 +08:00
</div>
</div>
2024-08-02 22:12:54 +08:00
<div className="flex justify-between text-sm">
2024-07-15 20:00:44 +08:00
<div
2024-08-02 22:12:54 +08:00
className="flex items-center"
2024-07-15 20:00:44 +08:00
onClick={() => {
copy(item.url);
}}
>
2024-08-02 22:12:54 +08:00
{/* <FontAwesomeIcon
2024-07-15 20:00:44 +08:00
icon={faCopy}
size="xl"
className="h-3 mr-1"
2024-08-02 22:12:54 +08:00
/> */}
<Image
2024-08-16 13:29:14 +08:00
height={24}
width={24}
className="mr-1"
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/copy.png"
}
/>
2024-08-02 22:12:54 +08:00
<span className="whitespace-nowrap">复制</span>
2024-07-06 11:05:19 +08:00
</div>
2024-07-15 20:00:44 +08:00
<div className="flex items-center">
2024-08-02 22:12:54 +08:00
{/* <FontAwesomeIcon
2024-07-15 20:00:44 +08:00
icon={faAngleRight}
size="xl"
className="h-3 mr-1"
2024-08-02 22:12:54 +08:00
/> */}
<Image
2024-08-16 13:29:14 +08:00
height={24}
width={24}
className="mr-1"
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/goto.png"
}
/>
<Link href={item?.url} className="whitespace-nowrap">
前往
</Link>
2024-07-06 11:05:19 +08:00
</div>
2024-07-15 20:00:44 +08:00
</div>
</li>
))}
</ul>
</div>
</>
2024-07-06 11:05:19 +08:00
</div>
<div className="flex justify-between items-center px-4 py-4 fixed bottom-0 bg-deepBg w-full border-t-2 border-[#FFFFFF1A]">
<div
2024-07-25 19:52:30 +08:00
className="text-base bg-[#FFFFFF1A] py-2 px-6 rounded-full whitespace-nowrap"
2024-07-06 11:05:19 +08:00
onClick={() => handleFollow(isFollow, Number(mid), setIsFollow)}
>
{isFollow ? "已关注" : "关注"}
</div>
2024-07-23 20:56:25 +08:00
<div
2024-07-25 19:52:30 +08:00
className="text-base bg-[#FFFFFF1A] py-2 px-6 rounded-full whitespace-nowrap"
2024-08-16 13:29:14 +08:00
onClick={() =>
router.push(
"/messageDetail?mid=" + streamerInfo?.streamer_ext?.mid
)
}
2024-07-23 20:56:25 +08:00
>
私聊
</div>
2024-07-06 11:05:19 +08:00
<div
2024-07-25 19:52:30 +08:00
className="bg-primary px-10 py-2 text-base rounded-full whitespace-nowrap"
2024-07-06 11:05:19 +08:00
onClick={() => setVisible(true)}
>
添加微信
</div>
</div>
</div>
<AddWeChat
visible={visible}
closeMask={setVisible}
price={streamerInfo?.streamer_ext?.wechat_coin_price}
name={streamerInfo?.streamer_ext?.name}
streamerMid={streamerInfo?.streamer_ext?.mid}
2024-07-15 20:00:44 +08:00
avatar={streamerInfo?.streamer_ext?.avatar?.images[0]?.urls[0]}
2024-07-08 20:07:36 +08:00
streamerData={streamerInfo}
2024-07-06 11:05:19 +08:00
/>
2024-08-16 13:29:14 +08:00
<ImagesMask ref={imagesMaskRef} />
2024-07-06 11:05:19 +08:00
</div>
);
}