2024-01-03 01:07:16 +08:00
|
|
|
|
"use client";
|
2024-01-06 19:27:55 +08:00
|
|
|
|
|
2024-01-03 01:07:16 +08:00
|
|
|
|
import React, { useState, useEffect } from "react";
|
2024-01-06 19:27:55 +08:00
|
|
|
|
import baseRequest from "@/utils/baseRequest";
|
|
|
|
|
import { Toast } from "antd-mobile";
|
|
|
|
|
import { generateSignature } from "@/utils/crypto";
|
2024-01-03 01:07:16 +08:00
|
|
|
|
import Image from "next/image";
|
2024-01-06 19:27:55 +08:00
|
|
|
|
import html2canvas from "html2canvas";
|
2024-01-03 01:07:16 +08:00
|
|
|
|
|
|
|
|
|
export default function GenerateLink({ params }) {
|
|
|
|
|
//生成二维码
|
|
|
|
|
const [qrcodeUrl, setQrcodeUrl] = useState("");
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
var QRCode = require("qrcode");
|
|
|
|
|
QRCode.toDataURL(
|
|
|
|
|
`https://tiefen.fun/${params.user_id}`,
|
|
|
|
|
function (err, url) {
|
|
|
|
|
setQrcodeUrl(url);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2024-01-06 19:27:55 +08:00
|
|
|
|
//页面数据
|
|
|
|
|
const [isFetching, setIsFetching] = useState(true);
|
|
|
|
|
const [data, setData] = useState({});
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const getData = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const base = baseRequest();
|
|
|
|
|
const signature = generateSignature({
|
|
|
|
|
user_id: parseInt(params.user_id, 10),
|
|
|
|
|
...base,
|
|
|
|
|
});
|
|
|
|
|
const detailResponse = await fetch(
|
|
|
|
|
`/api/streamer/list_ext_by_user_id?signature=${signature}`,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
user_id: parseInt(params.user_id, 10),
|
|
|
|
|
...base,
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
const detailData = await detailResponse.json();
|
|
|
|
|
if (detailData.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
content: detailData.msg,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setData(detailData.data.streamer_ext);
|
|
|
|
|
setIsFetching(false);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
getData();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
//保存二维码
|
|
|
|
|
const saveQrcode = async () => {
|
2024-01-03 01:07:16 +08:00
|
|
|
|
window.ReactNativeWebView.postMessage(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
type: "SAVE_IMAGE",
|
|
|
|
|
data: qrcodeUrl,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-06 19:27:55 +08:00
|
|
|
|
//保存海报
|
|
|
|
|
const savePoster = async () => {
|
|
|
|
|
const element = document.getElementById("print");
|
|
|
|
|
const canvas = await html2canvas(element, {
|
|
|
|
|
useCORS: true,
|
|
|
|
|
});
|
|
|
|
|
const data = canvas.toDataURL("image/jpg");
|
2024-01-06 21:04:28 +08:00
|
|
|
|
|
2024-01-06 19:27:55 +08:00
|
|
|
|
window.ReactNativeWebView.postMessage(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
type: "SAVE_IMAGE",
|
|
|
|
|
data: data,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-03 01:07:16 +08:00
|
|
|
|
//复制链接
|
|
|
|
|
const copyUrl = () => {
|
|
|
|
|
window.ReactNativeWebView.postMessage(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
type: "COPY_URL",
|
|
|
|
|
data: `https://tiefen.fun/${params.user_id}`,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-01-06 19:27:55 +08:00
|
|
|
|
|
|
|
|
|
if (isFetching) {
|
|
|
|
|
return (
|
|
|
|
|
<section className="flex flex-1 justify-center container">
|
|
|
|
|
<span className="absolute top-1/2 loading loading-spinner loading-lg"></span>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 01:07:16 +08:00
|
|
|
|
return (
|
2024-01-06 19:27:55 +08:00
|
|
|
|
<section className="py-4">
|
2024-01-03 01:07:16 +08:00
|
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
<h1 className="text-white text-xl font-semibold text-center">
|
2024-01-06 19:27:55 +08:00
|
|
|
|
已为您生成专属链接与分享海报
|
2024-01-03 01:07:16 +08:00
|
|
|
|
</h1>
|
|
|
|
|
<p className="text-white text-base text-center">
|
2024-01-06 19:27:55 +08:00
|
|
|
|
请保存您的分享链接或海报
|
2024-01-03 01:07:16 +08:00
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2024-01-06 19:27:55 +08:00
|
|
|
|
<div className="flex flex-col gap-4 px-4 mt-4">
|
2024-01-03 01:07:16 +08:00
|
|
|
|
<button
|
|
|
|
|
onClick={copyUrl}
|
|
|
|
|
className="btn btn-primary text-white text-base"
|
|
|
|
|
>
|
|
|
|
|
复制链接
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
2024-01-06 19:27:55 +08:00
|
|
|
|
onClick={savePoster}
|
2024-01-03 01:07:16 +08:00
|
|
|
|
className="btn btn-primary text-white text-base"
|
|
|
|
|
>
|
2024-01-06 19:27:55 +08:00
|
|
|
|
保存分享海报到相册
|
2024-01-03 01:07:16 +08:00
|
|
|
|
</button>
|
2024-01-06 19:27:55 +08:00
|
|
|
|
<button
|
|
|
|
|
onClick={saveQrcode}
|
|
|
|
|
className="btn btn-primary text-white text-base"
|
|
|
|
|
>
|
|
|
|
|
只保存二维码到相册
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
id="print"
|
2024-01-06 21:04:28 +08:00
|
|
|
|
className="flex flex-1 scale-90 flex-col container bg-[#07050A] relative"
|
2024-01-06 19:27:55 +08:00
|
|
|
|
>
|
2024-01-06 21:04:28 +08:00
|
|
|
|
<div className="absolute top-0 left-0 w-full z-0">
|
|
|
|
|
<div className="relative w-full h-64 overflow-hidden">
|
2024-01-06 19:27:55 +08:00
|
|
|
|
<img
|
2024-01-06 21:04:28 +08:00
|
|
|
|
src={
|
|
|
|
|
"/cors/" +
|
|
|
|
|
data?.cover?.images[0].urls[0].split(
|
|
|
|
|
"https://file.tiefen.fun/"
|
|
|
|
|
)[1]
|
|
|
|
|
}
|
2024-01-06 19:27:55 +08:00
|
|
|
|
alt=""
|
2024-01-06 21:04:28 +08:00
|
|
|
|
className="w-full object-cover opacity-30"
|
2024-01-06 19:27:55 +08:00
|
|
|
|
/>
|
|
|
|
|
<div className="absolute top-0 left-0 w-full h-64 bg-gradient-to-t from-[#07050A] to-[#00000000]"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-01-06 21:04:28 +08:00
|
|
|
|
<div className="flex flex-col flex-1 px-4 py-2 z-10 relative">
|
2024-01-06 19:27:55 +08:00
|
|
|
|
<div className="flex flex-col items-center mt-24">
|
|
|
|
|
<div className="w-[74px] h-[74px] rounded-full overflow-hidden">
|
|
|
|
|
<img
|
2024-01-06 21:04:28 +08:00
|
|
|
|
src={
|
|
|
|
|
"/cors/" +
|
|
|
|
|
data?.avatar?.images[0].urls[0].split(
|
|
|
|
|
"https://file.tiefen.fun/"
|
|
|
|
|
)[1]
|
|
|
|
|
}
|
2024-01-06 19:27:55 +08:00
|
|
|
|
alt=""
|
|
|
|
|
className="w-full object-cover"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-row items-center mt-3">
|
|
|
|
|
<p className="text-white text-2xl font-medium mr-1">
|
|
|
|
|
{data?.name}
|
|
|
|
|
</p>
|
2024-01-06 21:04:28 +08:00
|
|
|
|
<div className="w-6 h-6">
|
|
|
|
|
<img src="/icon/verification.png" alt="" className="w-full" />
|
|
|
|
|
</div>
|
2024-01-06 19:27:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
<p className="text-secondary text-sm text-center font-medium mt-3 px-4">
|
|
|
|
|
{data?.bio}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col mt-8 bg-[#FFFFFF1A] rounded-2xl">
|
|
|
|
|
<div className="flex flex-row cursor-pointer bg-[#07050A] border-2 border-[#FFFFFF26] rounded-2xl h-12 items-center justify-center">
|
2024-01-06 21:04:28 +08:00
|
|
|
|
<div className="w-5 h-5">
|
|
|
|
|
<img
|
|
|
|
|
src="/images/platform_wechat.png"
|
|
|
|
|
alt=""
|
|
|
|
|
className="w-full object-cover"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2024-01-06 19:27:55 +08:00
|
|
|
|
<p className="text-white text-base font-medium ml-2">我的微信</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{data?.platforms?.map((item, index) => (
|
|
|
|
|
<div
|
|
|
|
|
key={index}
|
|
|
|
|
className="flex flex-row cursor-pointer bg-[#07050A] border-2 border-[#FFFFFF26] rounded-2xl h-12 items-center justify-center mt-4"
|
|
|
|
|
>
|
|
|
|
|
<img
|
2024-01-06 21:04:28 +08:00
|
|
|
|
src={
|
|
|
|
|
"/cors/" +
|
|
|
|
|
item.icon.images[0].urls[0].split(
|
|
|
|
|
"https://file.tiefen.fun/"
|
|
|
|
|
)[1]
|
|
|
|
|
}
|
2024-01-06 19:27:55 +08:00
|
|
|
|
alt=""
|
|
|
|
|
className="w-5 h-5"
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-white text-base font-medium ml-2">
|
|
|
|
|
{item.link_name}|{item.nickname}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2024-01-06 21:04:28 +08:00
|
|
|
|
<div className="flex justify-center pt-2 pb-4">
|
2024-01-06 19:27:55 +08:00
|
|
|
|
{qrcodeUrl && (
|
|
|
|
|
<Image
|
|
|
|
|
className="aspect-square object-contain rounded-xl"
|
|
|
|
|
src={qrcodeUrl}
|
|
|
|
|
width={96}
|
|
|
|
|
height={96}
|
|
|
|
|
alt=""
|
|
|
|
|
></Image>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2024-01-03 01:07:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|