收银台增加轮询

This commit is contained in:
yezian 2024-04-22 21:54:06 +08:00
parent 74c5afca5d
commit b1bd9b861d
1 changed files with 69 additions and 60 deletions

View File

@ -16,72 +16,81 @@ export default function Pay({ params }) {
// //
const [superfanshipData, setSuperfanshipData] = useState(); const [superfanshipData, setSuperfanshipData] = useState();
const [isFetching, setIsFetching] = useState(true); const [isFetching, setIsFetching] = useState(true);
useEffect(() => {
const getData = async () => { //
try { const getData = async () => {
const base = webviewBaseRequest(); try {
const body = { const base = webviewBaseRequest();
zid: parseInt(params.zid), const body = {
moment_id: parseInt(params.moment_id), zid: parseInt(params.zid),
product_id: params.product_id, moment_id: parseInt(params.moment_id),
...base, product_id: params.product_id,
}; ...base,
const signature = generateSignature(body); };
const response = await fetch( const signature = generateSignature(body);
`/api/zone/get_cashier?signature=${signature}`, const response = await fetch(
{ `/api/zone/get_cashier?signature=${signature}`,
method: "POST", {
headers: { method: "POST",
"Content-Type": "application/json", headers: {
}, "Content-Type": "application/json",
body: JSON.stringify(body), },
} 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;
} }
setData(temData.data); );
setIsFetching(false); const temData = await response.json();
} catch (error) { if (temData.ret === -1) {
console.error(error); Toast.show({
content: temData.msg,
});
return;
} }
}; setData(temData.data);
const getSuperfanshipData = async () => { setIsFetching(false);
try { } catch (error) {
const base = webviewBaseRequest(); console.error(error);
const body = { }
zid: parseInt(params.zid), };
product_id: "h5_zone_superfanship",
...base, //
}; const getSuperfanshipData = async () => {
const signature = generateSignature(body); try {
const response = await fetch( const base = webviewBaseRequest();
`/api/zone/get_cashier?signature=${signature}`, const body = {
{ zid: parseInt(params.zid),
method: "POST", product_id: "h5_zone_superfanship",
headers: { ...base,
"Content-Type": "application/json", };
}, const signature = generateSignature(body);
body: JSON.stringify(body), const response = await fetch(
} `/api/zone/get_cashier?signature=${signature}`,
); {
const temData = await response.json(); method: "POST",
console.log(temData, JSON.stringify(body)); headers: {
if (temData.ret === -1) return; "Content-Type": "application/json",
setSuperfanshipData(temData.data); },
} catch (error) { body: JSON.stringify(body),
console.error(error); }
} );
}; const temData = await response.json();
if (temData.ret === -1) return;
setSuperfanshipData(temData.data);
} catch (error) {
console.error(error);
}
};
//
useEffect(() => {
setTimeout(() => { setTimeout(() => {
getData(); getData();
getSuperfanshipData(); getSuperfanshipData();
}, 500); }, 500);
const intervalId = setInterval(() => {
getData();
getSuperfanshipData();
}, 2000);
return () => clearInterval(intervalId);
}, []); }, []);
//switch //switch