增加主播邀请用户逻辑

This commit is contained in:
yezian 2024-01-12 20:43:37 +08:00
parent d24e6f1646
commit 305945672e
4 changed files with 30 additions and 4 deletions

View File

@ -16,6 +16,7 @@ export default function WechatBar({
price, price,
streamerMid, streamerMid,
auto_response_message, auto_response_message,
onClickDownloadApp,
}) { }) {
const router = useRouter(); const router = useRouter();
const [showBuyWechat, setShowBuyWechat] = useState(false); const [showBuyWechat, setShowBuyWechat] = useState(false);
@ -93,7 +94,10 @@ export default function WechatBar({
<div className="bg-[#FFFFFF26] h-0.5 w-4/5"></div> <div className="bg-[#FFFFFF26] h-0.5 w-4/5"></div>
<div <div
className="flex flex-row cursor-pointer items-center justify-center py-4 mb-2" className="flex flex-row cursor-pointer items-center justify-center py-4 mb-2"
onClick={() => router.push("/")} onClick={() => {
onClickDownloadApp();
router.push("/");
}}
> >
<Image src={app_purchase} alt="" className="w-5 h-5" /> <Image src={app_purchase} alt="" className="w-5 h-5" />
<p className="text-white text-base font-medium ml-2"> <p className="text-white text-base font-medium ml-2">

View File

@ -11,6 +11,7 @@ import Image from "next/image";
import verification from "@/public/icon/verification.png"; import verification from "@/public/icon/verification.png";
import icon_border from "@/public/images/icon_border.png"; import icon_border from "@/public/images/icon_border.png";
import Link from "next/link"; import Link from "next/link";
import { setCookie } from "cookies-next";
export default function StreamerDetail({ params }) { export default function StreamerDetail({ params }) {
// //
@ -50,6 +51,19 @@ export default function StreamerDetail({ params }) {
}; };
getData(); getData();
}, []); }, []);
//cookie
const copyAndSetCookieInviter = async () => {
try {
setCookie("inviter", data?.user_id);
await navigator.clipboard.writeText(
`${data?.name}】『ID${data?.user_id}复制此条消息打开铁粉空间APP查看详情https://tiefen.fun/${data?.user_id}`
);
} catch (error) {
console.error("复制到剪贴板时出现错误:", error);
}
};
return ( return (
<section className="flex flex-1 flex-col container relative"> <section className="flex flex-1 flex-col container relative">
<InOtherApp /> <InOtherApp />
@ -64,7 +78,7 @@ export default function StreamerDetail({ params }) {
</div> </div>
</div> </div>
<div className="flex flex-col flex-1 px-4 pt-2 pb-6 z-10"> <div className="flex flex-col flex-1 px-4 pt-2 pb-6 z-10">
<AuthBar /> <AuthBar onNotLoginedClick={copyAndSetCookieInviter} />
<div className="flex flex-col items-center mt-24"> <div className="flex flex-col items-center mt-24">
<div className="w-[74px] h-[74px] rounded-full overflow-hidden"> <div className="w-[74px] h-[74px] rounded-full overflow-hidden">
<img <img
@ -85,6 +99,7 @@ export default function StreamerDetail({ params }) {
price={Math.ceil(data?.wechat_coin_price / 9)} price={Math.ceil(data?.wechat_coin_price / 9)}
streamerMid={data?.mid} streamerMid={data?.mid}
auto_response_message={data?.auto_response_message} auto_response_message={data?.auto_response_message}
onClickDownloadApp={copyAndSetCookieInviter}
/> />
{data?.platforms?.map((item, index) => ( {data?.platforms?.map((item, index) => (
<div <div
@ -105,7 +120,7 @@ export default function StreamerDetail({ params }) {
<p className="text-white text-base font-medium">铁粉空间</p> <p className="text-white text-base font-medium">铁粉空间</p>
<p className="text-secondary text-sm font-medium">下载APP探索更多</p> <p className="text-secondary text-sm font-medium">下载APP探索更多</p>
</div> </div>
<Link className="p-2 pr-0" href="/"> <Link className="p-2 pr-0" href="/" onClick={copyAndSetCookieInviter}>
<p className="btn btn-sm bg-gradient-to-r from-[#FF668B] to-[#FF66F0] rounded-full text-white font-medium"> <p className="btn btn-sm bg-gradient-to-r from-[#FF668B] to-[#FF66F0] rounded-full text-white font-medium">
立即下载 立即下载
</p> </p>

View File

@ -8,6 +8,7 @@ import { signIn } from "@/utils/auth";
import Link from "next/link"; import Link from "next/link";
import baseRequest from "@/utils/baseRequest"; import baseRequest from "@/utils/baseRequest";
import { generateSignature } from "@/utils/crypto"; import { generateSignature } from "@/utils/crypto";
import { getCookie } from "cookies-next";
export default function PhonenumLogin() { export default function PhonenumLogin() {
const router = useRouter(); const router = useRouter();
@ -104,6 +105,9 @@ export default function PhonenumLogin() {
return; return;
} }
//
const inviter = getCookie("inviter");
//RSA //RSA
const encrypt = new JSEncrypt(); const encrypt = new JSEncrypt();
encrypt.setPublicKey(process.env.NEXT_PUBLIC_RSA_KEY); encrypt.setPublicKey(process.env.NEXT_PUBLIC_RSA_KEY);
@ -113,6 +117,7 @@ export default function PhonenumLogin() {
mobile_phone: mobile_phone, mobile_phone: mobile_phone,
region_code: regionCode, region_code: regionCode,
veri_code: value.veri_code, veri_code: value.veri_code,
inviter: inviter,
...base, ...base,
}); });
// //
@ -128,6 +133,7 @@ export default function PhonenumLogin() {
mobile_phone: mobile_phone, mobile_phone: mobile_phone,
region_code: regionCode, region_code: regionCode,
veri_code: value.veri_code, veri_code: value.veri_code,
inviter: inviter,
...base, ...base,
}), }),
} }

View File

@ -5,7 +5,7 @@ import { checkAuth, signOut } from "@/utils/auth";
import { getCookie } from "cookies-next"; import { getCookie } from "cookies-next";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
export default function AuthBar() { export default function AuthBar({ onNotLoginedClick = () => {} }) {
const router = useRouter(); const router = useRouter();
const [isLogined, setIsLogined] = useState(); const [isLogined, setIsLogined] = useState();
const [cookies, setCookies] = useState(); const [cookies, setCookies] = useState();
@ -31,6 +31,7 @@ export default function AuthBar() {
// //
const handleSignIn = () => { const handleSignIn = () => {
onNotLoginedClick();
router.push("/auth/login/phonenumlogin"); router.push("/auth/login/phonenumlogin");
}; };