"use client"; import React, { useState, useEffect } from "react"; import AuthBar from "@/components/AuthBar"; import { Toast, Modal } from "antd-mobile"; import { checkAuth } from "@/utils/auth"; import { useRouter } from "next/navigation"; import baseRequest from "@/utils/baseRequest"; import { generateSignature } from "@/utils/crypto"; import copy from "@/utils/copy"; export default function Purchased() { //如果没登录直接跳转下载页 const router = useRouter(); useEffect(() => { const prepare = async () => { if (window.location.origin === "https://shop.tiefen.fun") { router.replace("https://tiefen.fun/purchased"); return; } const isLogined = await checkAuth(); if (!isLogined) { router.replace("/auth/login/phonenumlogin"); } }; prepare(); }, []); //获取订单数据 const [data, setData] = useState([]); useEffect(() => { const getData = async () => { try { const base = baseRequest(); const signature = generateSignature({ offset: 0, limit: 99, ...base, }); const detailResponse = await fetch( `/api/vas/h5_get_unlock_wechat_list?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ offset: 0, limit: 99, ...base, }), } ); const detailData = await detailResponse.json(); if (detailData.ret === -1) { Toast.show({ content: detailData.msg, }); return; } setData(detailData.data.list); } catch (error) { console.error(error); } }; getData(); }, []); const getWechat = async (streamerMid) => { // 获取微信 try { const base = baseRequest(); const signature = generateSignature({ uid: streamerMid, ...base, }); const detailResponse = await fetch( `/api/vas/query_wechat?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ uid: streamerMid, ...base, }), } ); const detailData = await detailResponse.json(); if (detailData.ret === -1) { Toast.show({ content: detailData.msg, }); return; } return detailData.data.wechat_contact; } catch (error) { console.error(error); } }; const DirectGetWechatItem = ({ item }) => { //点击查看微信 const handleClick = async () => { const wechat = await getWechat(item?.account.mid); Modal.alert({ showCloseButton: true, confirmText: "复制", onConfirm: () => { copy(wechat); Toast.show({ content: "复制成功", }); }, content: (
Ta的微信号:{wechat}
{item.account?.name}
{orderLabel}
{item.account?.name}
{status === "pending" ? "请填写您的微信等待Ta添加您" : "已提交您的微信,请留意好友请求"}
若购买成功却未展示订单,请刷新页面