tiefen_space_web/app/weibo/[user_id]/page.jsx

90 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import React, { useState, useEffect } from "react";
import baseRequest from "@/utils/baseRequest";
import { Toast } from "antd-mobile";
import InOtherApp from "@/components/InOtherApp";
import { generateSignature } from "@/utils/crypto";
import Link from "next/link";
import copy from "@/utils/copy";
export default function Weibo({ params }) {
//页面数据
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);
} catch (error) {
console.error(error);
}
};
getData();
}, []);
//将主播链接复制到剪贴板
const copyInviter = () => {
copy(
`${data?.name}】『ID${data?.user_id}复制此条消息打开铁粉空间APP查看详情https://tiefen.fun/${data?.user_id}`
);
};
return (
<section className="flex flex-1 flex-col container relative">
<InOtherApp />
<div className="flex flex-col flex-1 justify-center px-4 z-10">
<div className="flex flex-col items-center gap-8">
<div className="w-[74px] h-[74px] rounded-full overflow-hidden">
<img
src={data?.avatar?.images[0].urls[0]}
alt=""
className="w-full h-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>
<img
src={
process.env.NEXT_PUBLIC_CDN_URL +
"/public/icon/verification.png"
}
alt=""
className="w-6 h-6"
/>
</div>
<Link className="p-2" href="/" onClick={copyInviter}>
<p className="btn w-48 bg-gradient-to-r from-[#FF668B] to-[#FF66F0] rounded-full text-white font-medium">
成为Ta的铁粉
</p>
</Link>
</div>
</div>
</section>
);
}