From b1bd9b861df029828117ce6453c7e40f6e4522ad Mon Sep 17 00:00:00 2001 From: yezian Date: Mon, 22 Apr 2024 21:54:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E9=93=B6=E5=8F=B0=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BD=AE=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[zid]/[product_id]/[moment_id]/page.jsx | 129 ++++++++++-------- 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx b/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx index 2ce109e..30e8339 100644 --- a/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx +++ b/app/zone/pay/[zid]/[product_id]/[moment_id]/page.jsx @@ -16,72 +16,81 @@ export default function Pay({ params }) { //超粉商品数据 const [superfanshipData, setSuperfanshipData] = useState(); const [isFetching, setIsFetching] = useState(true); - useEffect(() => { - const getData = async () => { - try { - const base = webviewBaseRequest(); - const body = { - zid: parseInt(params.zid), - moment_id: parseInt(params.moment_id), - product_id: params.product_id, - ...base, - }; - const signature = generateSignature(body); - const response = await fetch( - `/api/zone/get_cashier?signature=${signature}`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - } - ); - const temData = await response.json(); - console.log(temData, JSON.stringify(body)); - if (temData.ret === -1) { - Toast.show({ - content: temData.msg, - }); - return; + + //获取当前选购的商品数据 + const getData = async () => { + try { + const base = webviewBaseRequest(); + const body = { + zid: parseInt(params.zid), + moment_id: parseInt(params.moment_id), + product_id: params.product_id, + ...base, + }; + const signature = generateSignature(body); + const response = await fetch( + `/api/zone/get_cashier?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), } - setData(temData.data); - setIsFetching(false); - } catch (error) { - console.error(error); + ); + const temData = await response.json(); + if (temData.ret === -1) { + Toast.show({ + content: temData.msg, + }); + return; } - }; - const getSuperfanshipData = async () => { - try { - const base = webviewBaseRequest(); - const body = { - zid: parseInt(params.zid), - product_id: "h5_zone_superfanship", - ...base, - }; - const signature = generateSignature(body); - const response = await fetch( - `/api/zone/get_cashier?signature=${signature}`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - } - ); - const temData = await response.json(); - console.log(temData, JSON.stringify(body)); - if (temData.ret === -1) return; - setSuperfanshipData(temData.data); - } catch (error) { - console.error(error); - } - }; + setData(temData.data); + setIsFetching(false); + } catch (error) { + console.error(error); + } + }; + + //获取超粉商品数据 + const getSuperfanshipData = async () => { + try { + const base = webviewBaseRequest(); + const body = { + zid: parseInt(params.zid), + product_id: "h5_zone_superfanship", + ...base, + }; + const signature = generateSignature(body); + const response = await fetch( + `/api/zone/get_cashier?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + } + ); + const temData = await response.json(); + if (temData.ret === -1) return; + setSuperfanshipData(temData.data); + } catch (error) { + console.error(error); + } + }; + + //轮询请求 + useEffect(() => { setTimeout(() => { getData(); getSuperfanshipData(); }, 500); + const intervalId = setInterval(() => { + getData(); + getSuperfanshipData(); + }, 2000); + return () => clearInterval(intervalId); }, []); //是否勾选购买超粉switch组件