tiefen_space_h5/app/my/page.js

449 lines
13 KiB
JavaScript
Raw Normal View History

"use client";
2024-07-10 00:48:37 +08:00
import React, { useEffect, useState } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleRight } from "@fortawesome/free-solid-svg-icons";
import { Avatar, Image, Toast, Space } from "antd-mobile";
2024-10-22 17:24:02 +08:00
import { useRouter } from "next/navigation";
2024-07-10 00:48:37 +08:00
import { get } from "@/utils/storeInfo";
2024-07-22 16:07:41 +08:00
import requireAPI from "@/utils/requireAPI";
2024-07-03 19:59:39 +08:00
const My = () => {
2024-07-06 11:05:19 +08:00
const [userInfo, setUserInfo] = useState({});
2024-07-02 15:09:48 +08:00
const router = useRouter();
2024-10-22 17:24:02 +08:00
const [streamerNavigates, setStreamerNavigates] = useState([]);
const [userNavigates, setUserNavigates] = useState([]);
2024-07-06 11:05:19 +08:00
useEffect(() => {
const userInfo = get("account");
2024-10-22 17:24:02 +08:00
2024-07-06 11:05:19 +08:00
if (userInfo) {
2024-07-10 00:48:37 +08:00
getData(userInfo);
2024-07-06 11:05:19 +08:00
}
2024-07-10 00:48:37 +08:00
}, []);
const getData = async (oldUserInfo) => {
const data = await requireAPI(
"POST",
"/api/account_relation/count",
null,
true
);
2024-10-22 17:24:02 +08:00
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
const streamer = await requireAPI(
"POST",
"/api/streamer/list_ext_by_mid",
null,
true
);
if (streamer.ret === -1) {
Toast.show({
icon: "fail",
2024-10-24 21:28:49 +08:00
content: streamer.msg,
2024-10-22 17:24:02 +08:00
position: "top",
});
return;
}
const account = await requireAPI(
"POST",
"/api/account/list_by_mid",
null,
true
);
2024-10-22 17:24:02 +08:00
if (account.ret === -1) {
Toast.show({
icon: "fail",
2024-10-24 21:28:49 +08:00
content: account.msg,
2024-10-22 17:24:02 +08:00
position: "top",
});
return;
}
const statuses = await requireAPI(
"POST",
"/api/streamer_auth_approval/get_statuses",
null
);
if (statuses.ret === -1) {
2024-07-10 00:48:37 +08:00
Toast.show({
icon: "fail",
2024-10-24 21:28:49 +08:00
content: statuses.msg,
2024-07-10 00:48:37 +08:00
position: "top",
});
return;
}
2024-10-22 17:24:02 +08:00
const isInJoinProgress =
(statuses.data.basic_status === 0 ||
statuses.data.basic_status === 1 ||
statuses.data.basic_status === 3) &&
statuses.data.details_status !== 1;
setStreamerNavigates((old) => {
if (account.data.account.role == 3 || isInJoinProgress) {
const zoneLength = streamer.data?.streamer_ext?.zones?.length;
let currentOld = [
{
2024-10-24 21:28:49 +08:00
url: !zoneLength
? `my/createProfile`
: `space/${account.data.account.mid}`,
2024-10-22 17:24:02 +08:00
iconUrl: `icons/32DP/space.png`,
title: !zoneLength ? "开通空间" : "我的空间",
subTitle:
account.data.account.role == 3 ? "创作者功能" : "完善资料后解锁",
},
{
2024-10-24 21:28:49 +08:00
url: `streamerPosts/${account.data.account.mid}`,
2024-10-22 17:24:02 +08:00
iconUrl: "icons/32DP/myposts.png",
title: "广场动态",
subTitle:
account.data.account.role == 3 ? "创作者功能" : "完善资料后解锁",
},
{
url: `my/wechatWaitingToAdd`,
iconUrl: "icons/32DP/wechat.png",
title: "待添加微信",
subTitle:
account.data.account.role == 3 ? "创作者功能" : "完善资料后解锁",
},
{
url: `my/editprofile`,
iconUrl: "icons/32DP/editprofile.png",
title: "编辑资料",
subTitle:
account.data.account.role == 3 ? "创作者功能" : "完善资料后解锁",
},
// ...currentOld,
];
if (isInJoinProgress) {
currentOld = [
{
url: `my/streamerVerification/completeStreamerInformation`,
iconUrl: "icons/32DP/editprofile.png",
title: "完善资料",
subTitle: "完善后解锁全部功能",
2024-10-30 21:42:23 +08:00
status: !statuses.data.details_status ? "审核中" : "未通过",
disable: statuses.data.details_status == 2,
2024-10-22 17:24:02 +08:00
},
...currentOld,
];
}
return currentOld;
}
return old;
});
setUserNavigates((old) => {
let currentOld = [
{
url: `my/wallet`,
iconUrl: "icons/32DP/wallet.png",
title: "我的钱包",
},
{
url: `my/unlockedWechat`,
iconUrl: "icons/32DP/wechat.png",
title: "已解锁微信",
},
{
url: `/messageDetail`,
iconUrl: "icons/32DP/contact.png",
title: "联系客服",
},
{
url: `/my/addToHome`,
iconUrl: "icons/32DP/toScreen.png",
title: "添加到主屏幕",
},
];
2024-10-30 21:42:23 +08:00
if (
(account.data.account.role != 3 && !isInJoinProgress) ||
statuses.data.details_status === 2
) {
2024-10-22 17:24:02 +08:00
currentOld = [
2024-10-30 21:42:23 +08:00
{
url: `my/wallet`,
iconUrl: "icons/32DP/wallet.png",
title: "我的钱包",
},
{
url: `my/unlockedWechat`,
iconUrl: "icons/32DP/wechat.png",
title: "已解锁微信",
},
2024-10-22 17:24:02 +08:00
{
url: `my/streamerVerification/joinStreamer`,
iconUrl: "icons/32DP/join.png",
title: "申请入驻",
},
2024-10-30 21:42:23 +08:00
{
url: `/messageDetail`,
iconUrl: "icons/32DP/contact.png",
title: "联系客服",
},
{
url: `/my/addToHome`,
iconUrl: "icons/32DP/toScreen.png",
title: "添加到主屏幕",
},
2024-10-22 17:24:02 +08:00
];
}
return currentOld;
});
setUserInfo({ ...data.data, ...account.data.account, ...streamer.data });
};
2024-10-30 21:42:23 +08:00
const ItemEle = ({
url,
iconUrl,
title,
subTitle,
toWebView,
status,
disable,
}) => {
2024-10-22 17:24:02 +08:00
return (
<li
className="flex justify-between items-center p-3 py-2"
onClick={() => {
subTitle != "完善资料后解锁" &&
2024-10-30 21:42:23 +08:00
!disable &&
2024-10-22 17:24:02 +08:00
router.push(
toWebView ? `/webView/${encodeURIComponent(url)}` : url
);
}}
>
<div className="flex items-center">
<Image
className="mr-2"
width={32}
src={`${process.env.NEXT_PUBLIC_WEB_ASSETS_URL}/${iconUrl}`}
placeholder=""
/>
<span className="text-base">{title}</span>
</div>
2024-10-24 21:28:49 +08:00
<div className={`flex items-center text-[#FFFFFF80]`}>
2024-10-30 21:42:23 +08:00
<div
className={`rounded-full`}
style={{
backgroundColor: status
? status == "未通过"
? "#db2020"
: "#207edb"
: "none",
padding: status ? "2px 10px" : "0",
marginRight: !disable ? "0.5rem" : "0",
}}
>
{status || subTitle}
</div>
{!disable && (
<FontAwesomeIcon
icon={faAngleRight}
style={{ maxWidth: "12px" }}
size="sm"
className="h-4"
/>
)}
2024-10-22 17:24:02 +08:00
</div>
</li>
);
2024-07-10 00:48:37 +08:00
};
return (
<div
className={`p-4 pb-20 bg-no-repeat bg-contain bg-top`}
style={{
backgroundImage: `url(${
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/images/profilebackground.png"
})`,
}}
2024-07-24 19:08:22 +08:00
>
<div className="flex justify-end items-center z-10 w-full mb-4">
2024-07-10 00:48:37 +08:00
<div
className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full mr-2"
onClick={() =>
router.push("my/editUserProfile/selectUserProfileItem")
}
>
<Image
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL + "/icons/32DP/edit.png"
}
width={32}
className="w-4 h-full"
placeholder=""
/>
</div>
2024-07-10 00:48:37 +08:00
<div
className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full"
onClick={() => router.push("my/setting")}
>
<Image
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL + "/icons/32DP/setting.png"
}
width={32}
className="w-4 h-full"
placeholder=""
/>
</div>
</div>
2024-07-15 20:00:44 +08:00
{userInfo?.role === 3 ? (
<div
className="flex items-center justify-between mb-4"
onClick={() => router.push("profile/" + userInfo.mid)}
>
<div className="flex items-center">
<Avatar
rounded-full
src={userInfo.avatar?.images[0].urls[0]}
className="mr-4"
style={{ "--size": "76px", "--border-radius": "50%" }}
/>
<div>
<Space align="center">
<p
className={`text-2xl`}
style={{
color: userInfo?.is_a_member === 1 ? "#FFADBE" : "white",
}}
>
{userInfo.name}
</p>
{userInfo?.is_a_member === 1 && (
<Image
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/vipbig.png"
}
width={32}
height={32}
placeholder=""
/>
)}
</Space>
2024-07-15 20:00:44 +08:00
<div className="h-4 flex items-center text-xs bg-[#ffffff18] rounded-full px-2 py-2.5 mt-1 w-max">
<Image
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/ID.png"
}
2024-07-15 20:00:44 +08:00
width={14}
height={14}
className="w-4 h-full mr-1"
placeholder=""
/>
<span>{userInfo.user_id}</span>
</div>
</div>
</div>
<FontAwesomeIcon
icon={faAngleRight}
style={{ maxWidth: "12px" }}
2024-07-15 20:00:44 +08:00
size="xl"
className="h-6 mr-2"
onClick={() => {
// searchParams.append();
// router.back();
}}
/>
2024-07-15 20:00:44 +08:00
</div>
) : (
<div className="flex items-center justify-between mb-4">
2024-07-15 20:00:44 +08:00
<div className="flex items-center">
<Avatar
rounded-full
src={userInfo.avatar?.images[0].urls[0]}
className="mr-4"
style={{ "--size": "76px", "--border-radius": "50%" }}
/>
<div>
2024-09-12 19:14:02 +08:00
<Space align="center">
<p
className={`text-2xl`}
style={{
color: userInfo?.is_a_member === 1 ? "#FFADBE" : "white",
}}
>
{userInfo.name}
</p>
{userInfo?.is_a_member === 1 && (
<Image
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/vipbig.png"
}
width={32}
height={32}
placeholder=""
/>
)}
</Space>
2024-07-15 20:00:44 +08:00
<div className="h-4 flex items-center text-xs bg-[#ffffff18] rounded-full px-2 py-2.5 mt-1 w-max">
<Image
src={
process.env.NEXT_PUBLIC_WEB_ASSETS_URL +
"/icons/info/ID.png"
}
2024-07-15 20:00:44 +08:00
width={14}
height={14}
className="w-4 h-full mr-1"
placeholder=""
/>
<span>{userInfo.user_id}</span>
</div>
</div>
</div>
</div>
2024-07-15 20:00:44 +08:00
)}
<ul className="grid grid-cols-4 mb-4">
2024-07-10 00:48:37 +08:00
<li
className="text-center"
onClick={() => router.push("my/relationship?key=follow")}
>
2024-07-10 16:50:53 +08:00
<p className="text-2xl">{userInfo?.follow_count || 0}</p>
<p className="text-[#ffffff88]">关注</p>
</li>
2024-07-10 00:48:37 +08:00
<li
className="text-center"
onClick={() => router.push("my/relationship?key=fans")}
>
2024-07-10 16:50:53 +08:00
<p className="text-2xl">{userInfo?.is_followed_count || 0}</p>
<p className="text-[#ffffff88]">粉丝</p>
</li>
2024-07-10 00:48:37 +08:00
<li className="text-center" onClick={() => router.push("my/wallet")}>
2024-07-10 16:50:53 +08:00
<p className="text-2xl">{userInfo.gold_num || 0}</p>
<p className="text-[#ffffff88]">金币</p>
</li>
2024-07-10 00:48:37 +08:00
<li className="text-center" onClick={() => router.push("my/wallet")}>
2024-07-10 16:50:53 +08:00
<p className="text-2xl">{userInfo.diamond_num || 0}</p>
<p className="text-[#ffffff88]">钻石</p>
</li>
</ul>
2024-10-22 17:24:02 +08:00
{/* 主播用户 */}
{!!streamerNavigates.length && (
<div className="rounded-xl p-2 border-2 border-[#2c2b2f] mb-4">
<ul>
2024-10-23 16:06:06 +08:00
{streamerNavigates.map((item, index) => (
<ItemEle key={index} {...item} />
2024-10-22 17:24:02 +08:00
))}
</ul>
</div>
)}
{/* 普通用户 */}
2024-10-23 13:52:52 +08:00
{!!userNavigates.length && (
2024-10-22 17:24:02 +08:00
<div className="rounded-xl p-2 border-2 border-[#2c2b2f]">
<ul>
2024-10-23 16:06:06 +08:00
{userNavigates.map((item, index) => (
<ItemEle key={index} {...item} />
2024-10-22 17:24:02 +08:00
))}
</ul>
</div>
)}
</div>
);
2024-07-10 00:48:37 +08:00
};
2024-07-03 19:59:39 +08:00
2024-07-17 16:58:27 +08:00
export default My;