tiefen_space_h5/app/space/setting/page.js

200 lines
6.2 KiB
JavaScript
Raw Normal View History

2024-07-03 19:59:39 +08:00
"use client";
2024-07-16 20:20:12 +08:00
import React, { useEffect, useState, useCallback } from "react";
2024-07-11 23:57:26 +08:00
import { Image, Avatar, Divider, Dialog, Toast } from "antd-mobile";
2024-07-17 16:58:27 +08:00
import { redirect, useRouter, useSearchParams } from "next/navigation";
2024-07-03 19:59:39 +08:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2024-07-11 23:57:26 +08:00
import {
faAngleLeft,
faAngleRight,
faCalendar,
} from "@fortawesome/free-solid-svg-icons";
2024-07-17 16:58:27 +08:00
import { getSpaceData } from "@/api/space";
2024-08-02 22:12:54 +08:00
import requireAPI from "@/utils/requireAPI";
2024-07-03 19:59:39 +08:00
export default function Setting() {
const router = useRouter();
2024-07-11 23:57:26 +08:00
const searchParams = useSearchParams();
const [streamerInfo, setStreamerInfo] = useState(null);
2024-07-03 19:59:39 +08:00
useEffect(() => {
2024-07-17 16:58:27 +08:00
(async () => {
const currentData = searchParams.get("data");
if (currentData) {
let data = await JSON.parse(decodeURIComponent(searchParams.get("data")));
2024-08-05 18:59:30 +08:00
// console.log("data",data)
2024-07-17 16:58:27 +08:00
await getSpaceData(Number(data.mid)).then((res) => {
2024-07-31 20:05:17 +08:00
setStreamerInfo({ ...data,refund_enable:res?.refund_enable });
2024-07-17 16:58:27 +08:00
});
}
})();
2024-07-03 19:59:39 +08:00
}, []);
2024-07-16 20:20:12 +08:00
const handleShowDialog = () => {
const result = Dialog.show({
2024-07-11 23:57:26 +08:00
title: "是否确认退出空间?",
2024-07-16 20:20:12 +08:00
content:
"一旦退出,您的空间成员身份将会被取消,若当前空间为付费空间,下次加入时,需要再次付费。请确保知晓以上内容后谨慎选择退出。",
2024-07-11 23:57:26 +08:00
bodyStyle: {
maxHeight: "none",
width: "80vw",
2024-07-16 20:20:12 +08:00
position: "fixed",
top: "200px",
2024-07-11 23:57:26 +08:00
left: "10vw",
2024-07-16 20:20:12 +08:00
"--text-color": "#fff",
color: "#fff",
},
// cancelText:"确认",
// confirmText:"取消",
style: {
"--text-color": "#fff",
2024-07-11 23:57:26 +08:00
},
2024-07-16 20:20:12 +08:00
closeOnAction: true,
2024-07-11 23:57:26 +08:00
actions: [
2024-07-16 20:20:12 +08:00
[
{
key: "submit",
text: "确认",
style: { color: "#ffffff80" },
onClick: handleExitSpace,
2024-07-11 23:57:26 +08:00
},
2024-07-16 20:20:12 +08:00
{
key: "close",
text: "取消",
bold: true,
style: { color: "#fff" },
onClick: () => {
2024-07-19 14:14:40 +08:00
Dialog?.clear();
2024-07-16 20:20:12 +08:00
},
},
],
2024-07-11 23:57:26 +08:00
],
});
2024-07-17 16:58:27 +08:00
// if (result) {
// Toast.show({ content: "点击了确认", position: "bottom" });
// }
2024-07-16 20:20:12 +08:00
};
//格式化时间
const formatDate = useCallback((timestamp) => {
const date = new Date(timestamp * 1000);
const year = date.getFullYear();
const month = date.getMonth() + 1; // 月份从0开始,所以需要加1
const day = date.getDate();
return `${year}/${month}/${day}`;
}, []);
const handleExitSpace = async () => {
2024-08-02 22:12:54 +08:00
2024-07-16 20:20:12 +08:00
try {
2024-08-02 22:12:54 +08:00
const _data = await requireAPI("POST", "/api/zone/exit", {
2024-07-17 16:58:27 +08:00
body: {
2024-07-16 20:20:12 +08:00
zid: streamerInfo?.id,
2024-07-17 16:58:27 +08:00
},
});
2024-07-16 20:20:12 +08:00
if (_data.ret === -1) {
Toast.show({
icon: "fail",
content: _data.msg,
position: "top",
});
return;
}
Toast.show({
icon: "success",
content: "退出空间成功",
position: "top",
});
2024-08-02 22:12:54 +08:00
setTimeout(() => router.replace("/"), 500);
2024-07-16 20:20:12 +08:00
} catch (error) {
console.error(error);
}
2024-07-11 23:57:26 +08:00
};
2024-07-03 19:59:39 +08:00
return (
<div className="">
<div className="p-4 fixed top-0 z-10 w-full">
<div className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full absolute">
<FontAwesomeIcon
icon={faAngleLeft}
size="xl"
onClick={() => {
router.back();
}}
/>
</div>
<p className="text-base text-center leading-9">空间设置</p>
</div>
{/* 内容 */}
2024-07-11 23:57:26 +08:00
<div className="p-4 pt-20">
<div className="flex items-center">
2024-07-03 19:59:39 +08:00
<Avatar
rounded-full
mr-4
2024-07-17 16:58:27 +08:00
src={streamerInfo?.avatar}
2024-07-03 19:59:39 +08:00
className="mr-4"
2024-07-11 23:57:26 +08:00
style={{ "--size": "52px", "--border-radius": "50%" }}
2024-07-03 19:59:39 +08:00
/>
<div>
2024-07-23 20:56:25 +08:00
<p className="text-xl">{streamerInfo?.name}</p>
2024-07-11 23:57:26 +08:00
<ul className="flex">
<li className="h-4 mr-1 flex items-center text-xs bg-[#ffffff18] rounded-full px-2 py-2.5 mt-1 w-max">
<Image
2024-07-24 19:08:22 +08:00
src={process.env.NEXT_PUBLIC_WEB_ASSETS_URL+"/icons/info/ID.png"}
2024-07-11 23:57:26 +08:00
width={14}
height={14}
className="w-4 h-full mr-1"
placeholder=""
/>
<span>{streamerInfo?.user_id}</span>
</li>
<li className="h-4 flex items-center text-xs bg-[#ffffff18] rounded-full px-2 py-2.5 mt-1 w-max">
<FontAwesomeIcon
icon={faCalendar}
size="sm"
className="mr-1"
onClick={() => {
router.back();
}}
/>
2024-07-16 20:20:12 +08:00
<span>{formatDate(streamerInfo?.ct)}</span>
2024-07-11 23:57:26 +08:00
</li>
</ul>
2024-07-03 19:59:39 +08:00
</div>
</div>
2024-07-11 23:57:26 +08:00
<ul className="mt-6">
<li>
<div
onClick={() => router.push("/share/" + streamerInfo.mid)}
className="flex justify-between"
>
<span className="text-base text-white">分享空间</span>
2024-07-16 20:20:12 +08:00
<FontAwesomeIcon icon={faAngleRight} size="xl" />
2024-07-11 23:57:26 +08:00
</div>
<Divider />
</li>
2024-07-30 22:53:41 +08:00
{
streamerInfo?.refund_enable === 1 &&
streamerInfo?.admission_price > 0 &&
streamerInfo?.visitor_role === 0 && (
2024-07-17 16:58:27 +08:00
<li>
<div
onClick={() =>
2024-07-31 20:05:17 +08:00
router.push("setting/spaceRefund?mid=" + streamerInfo.mid+"&id="+streamerInfo.id)
2024-07-17 16:58:27 +08:00
}
className="flex justify-between"
>
2024-07-30 22:53:41 +08:00
<span className="text-base text-white">申请退款</span>
2024-07-17 16:58:27 +08:00
<FontAwesomeIcon icon={faAngleRight} size="xl" />
</div>
<Divider />
</li>
)}
2024-07-23 20:56:25 +08:00
{streamerInfo?.visitor_role != 3 && <li onClick={handleShowDialog}>
2024-07-11 23:57:26 +08:00
<div className="flex justify-between">
<span className="text-base text-white">退出空间</span>
2024-07-16 20:20:12 +08:00
<FontAwesomeIcon icon={faAngleRight} size="xl" />
2024-07-11 23:57:26 +08:00
</div>
<Divider />
2024-07-23 20:56:25 +08:00
</li>}
2024-07-11 23:57:26 +08:00
</ul>
2024-07-03 19:59:39 +08:00
</div>
</div>
);
}