2024-07-10 16:50:53 +08:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
|
import { Divider, Toast } from "antd-mobile";
|
2024-12-13 15:47:15 +08:00
|
|
|
|
import { useRouter, useParams } from "next/navigation";
|
2024-07-10 16:50:53 +08:00
|
|
|
|
import clipboard from "copy-to-clipboard";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2024-12-10 18:53:14 +08:00
|
|
|
|
import { faAngleLeft, faAngleRight } from "@fortawesome/free-solid-svg-icons";
|
2024-07-10 16:50:53 +08:00
|
|
|
|
import { getStreamerInfo } from "@/api/space";
|
2024-12-10 18:53:14 +08:00
|
|
|
|
import requireAPI from "@/utils/requireAPI";
|
|
|
|
|
|
2024-12-13 15:47:15 +08:00
|
|
|
|
export default function ShareSpace() {
|
2024-07-10 16:50:53 +08:00
|
|
|
|
const router = useRouter();
|
|
|
|
|
const { mid } = useParams();
|
|
|
|
|
const webUrl = process.env.NEXT_PUBLIC_WEB_URL;
|
|
|
|
|
const [streamerInfo, setStreamerInfo] = useState(null);
|
2024-12-10 18:53:14 +08:00
|
|
|
|
const [shareWebUrl, setShareWebUrl] = useState("https://tiefen.fun");
|
2024-12-13 15:47:15 +08:00
|
|
|
|
|
|
|
|
|
function generateRandomString(length = 10) {
|
|
|
|
|
const characters =
|
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
|
let result = "";
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
result += characters.charAt(
|
|
|
|
|
Math.floor(Math.random() * characters.length)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 16:50:53 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
getStreamerInfo(Number(mid)).then((res) => {
|
|
|
|
|
setStreamerInfo(res);
|
|
|
|
|
});
|
2024-12-10 18:53:14 +08:00
|
|
|
|
|
2024-12-13 15:47:15 +08:00
|
|
|
|
function getRandomUrl(urls) {
|
|
|
|
|
return urls[Math.floor(Math.random() * urls.length)];
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 18:53:14 +08:00
|
|
|
|
const getShareWebUrl = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await requireAPI("POST", "/api/config/cold_config", {
|
|
|
|
|
body: {},
|
|
|
|
|
});
|
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
content: data.msg,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-13 15:47:15 +08:00
|
|
|
|
const randomUrl = getRandomUrl(data.data.share_redirect_urls);
|
|
|
|
|
setShareWebUrl(randomUrl);
|
2024-12-10 18:53:14 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getShareWebUrl();
|
2024-07-10 16:50:53 +08:00
|
|
|
|
}, []);
|
|
|
|
|
//保存内容到剪贴板
|
|
|
|
|
const copy = (_data) => {
|
|
|
|
|
clipboard(_data);
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "success",
|
|
|
|
|
content: "已复制到剪贴板",
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//复制口令
|
|
|
|
|
const copyShareCode = () => {
|
|
|
|
|
const shareCode = `【${streamerInfo?.streamer_ext?.name}】『ID:${streamerInfo?.streamer_ext?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情${webUrl}/zone/${streamerInfo?.streamer_ext?.user_id}`;
|
|
|
|
|
|
|
|
|
|
copy(shareCode);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//复制邀请链接
|
|
|
|
|
const copyShareUrl = () => {
|
2024-12-13 15:47:15 +08:00
|
|
|
|
const randomStr = generateRandomString();
|
|
|
|
|
const shareCode = `${shareWebUrl}/zone/${streamerInfo?.streamer_ext?.user_id}/${randomStr}`;
|
2024-07-10 16:50:53 +08:00
|
|
|
|
copy(shareCode);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-12-13 15:47:15 +08:00
|
|
|
|
<div>
|
2024-07-10 16:50:53 +08:00
|
|
|
|
<div className="p-4 fixed top-0 z-10 w-full">
|
2024-07-30 22:53:41 +08:00
|
|
|
|
<div className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full float-left absolute">
|
2024-07-10 16:50:53 +08:00
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={faAngleLeft}
|
2024-08-21 11:30:19 +08:00
|
|
|
|
style={{ maxWidth: "12px" }}
|
2024-07-10 16:50:53 +08:00
|
|
|
|
size="xl"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
router.back();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-base text-center leading-9">分享空间</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-full flex flex-col p-4 pt-16">
|
|
|
|
|
<div onClick={copyShareCode} className="flex justify-between pt-4 pb-2">
|
|
|
|
|
<span className="text-base text-white">复制口令</span>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={faAngleRight}
|
|
|
|
|
size="xl"
|
2024-08-21 11:30:19 +08:00
|
|
|
|
style={{ maxWidth: "12px" }}
|
2024-07-10 16:50:53 +08:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Divider />
|
|
|
|
|
<div
|
|
|
|
|
onClick={copyShareUrl}
|
|
|
|
|
className="flex justify-between w-full pt-4 pb-2"
|
|
|
|
|
>
|
|
|
|
|
<span className="text-base text-white">复制邀请链接</span>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={faAngleRight}
|
|
|
|
|
size="xl"
|
2024-08-21 11:30:19 +08:00
|
|
|
|
style={{ maxWidth: "12px" }}
|
2024-07-10 16:50:53 +08:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Divider />
|
|
|
|
|
<div
|
|
|
|
|
onClick={() => {
|
2024-08-21 11:30:19 +08:00
|
|
|
|
router.push("/space/share/" + streamerInfo?.streamer_ext?.user_id);
|
2024-07-10 16:50:53 +08:00
|
|
|
|
}}
|
|
|
|
|
className="flex justify-between pt-4 pb-2"
|
|
|
|
|
>
|
|
|
|
|
<span className="text-base text-white">生成分享卡片</span>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={faAngleRight}
|
|
|
|
|
size="xl"
|
2024-08-21 11:30:19 +08:00
|
|
|
|
style={{ maxWidth: "12px" }}
|
2024-07-10 16:50:53 +08:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Divider />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|