diff --git a/app/generatelink/[user_id]/page.jsx b/app/generatelink/[user_id]/page.jsx index f311b20..cd6d01c 100644 --- a/app/generatelink/[user_id]/page.jsx +++ b/app/generatelink/[user_id]/page.jsx @@ -1,6 +1,13 @@ "use client"; + import React, { useState, useEffect } from "react"; +import baseRequest from "@/utils/baseRequest"; +import { Toast } from "antd-mobile"; +import { generateSignature } from "@/utils/crypto"; import Image from "next/image"; +import verification from "@/public/icon/verification.png"; +import platform_wechat from "@/public/images/platform_wechat.png"; +import html2canvas from "html2canvas"; export default function GenerateLink({ params }) { //生成二维码 @@ -15,8 +22,48 @@ export default function GenerateLink({ params }) { ); }, []); - //保存图片 - const saveImage = async () => { + //页面数据 + 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 () => { window.ReactNativeWebView.postMessage( JSON.stringify({ type: "SAVE_IMAGE", @@ -25,6 +72,21 @@ export default function GenerateLink({ params }) { ); }; + //保存海报 + const savePoster = async () => { + const element = document.getElementById("print"); + const canvas = await html2canvas(element, { + useCORS: true, + }); + const data = canvas.toDataURL("image/jpg"); + window.ReactNativeWebView.postMessage( + JSON.stringify({ + type: "SAVE_IMAGE", + data: data, + }) + ); + }; + //复制链接 const copyUrl = () => { window.ReactNativeWebView.postMessage( @@ -34,31 +96,26 @@ export default function GenerateLink({ params }) { }) ); }; + + if (isFetching) { + return ( + + + + ); + } + return ( - + - 已为您生成专属链接与二维码 + 已为您生成专属链接与分享海报 - 请扫码或复制到浏览器查看 + 请保存您的分享链接或海报 - - - - - - https://tiefen.fun/{params.user_id} - - - + - 保存二维码到相册 + 保存分享海报到相册 + + 只保存二维码到相册 + + + + + + + + + + + + + + + + + {data?.name} + + + + + {data?.bio} + + + + + + 我的微信 + + + {data?.platforms?.map((item, index) => ( + + + + {item.link_name}|{item.nickname} + + + ))} + + + {qrcodeUrl && ( + + )} + );
- 请扫码或复制到浏览器查看 + 请保存您的分享链接或海报
- https://tiefen.fun/{params.user_id} -
+ {data?.name} +
+ {data?.bio} +
我的微信
+ {item.link_name}|{item.nickname} +