等待图片

This commit is contained in:
quantulr
2024-03-20 16:00:30 +08:00
parent 07b0d943e3
commit 8f89e593e9
2 changed files with 59 additions and 46 deletions

View File

@ -1,7 +1,8 @@
import "./App.css"; import "./App.css";
import { useEffect, useState } from "react"; import {useEffect, useState} from "react";
import altImg from "./assets/altImg.png"
interface Qrcode { interface SignInType {
qrcode?: string; qrcode?: string;
title?: string; title?: string;
start_time?: string; start_time?: string;
@ -9,45 +10,57 @@ interface Qrcode {
} }
function App() { function App() {
const [qrcode, setQrcode] = useState<Qrcode>(); const [signIn, setSignIn] = useState<SignInType>();
useEffect(() => { useEffect(() => {
fetch("http://101.35.127.74:3000/qrcode") fetch("http://101.35.127.74:3000/qrcode")
.then((res) => res.json()) .then((res) => res.json())
.then((data) => { .then((data) => {
setQrcode(() => data); setSignIn(() => data);
}); });
const source = new EventSource("http://101.35.127.74:3000/qrcode-sse", { const source = new EventSource("http://101.35.127.74:3000/qrcode-sse", {
// withCredentials: true, // withCredentials: true,
}); });
source.addEventListener("message", (ev: MessageEvent<string>) => { source.addEventListener("message", (ev: MessageEvent<string>) => {
const data = JSON.parse(ev.data) as Qrcode; const data = JSON.parse(ev.data) as SignInType;
setQrcode(() => data); setSignIn(() => data);
}); });
}, []); }, []);
return ( return (
<div className={"flex flex-col items-center pt-8"}> <div className={"flex flex-col items-center pt-8"}>
<h2 className={"font-bold text-3xl text-center"}>{qrcode?.title}</h2> {signIn ? (
{qrcode ? ( signIn.qrcode && !signIn.qrcode.startsWith("http") ? (
<>
<h2 className={"font-bold text-3xl text-center"}>{signIn?.title}</h2>
<img <img
alt={"没有正在进行的会议"} alt={""}
className={"w-[90vw] md:w-[30vw] aspect-square"} className={"w-[90vw] md:w-[30vw] aspect-square"}
src={qrcode?.qrcode} src={signIn.qrcode}
/> />
<p className={"text-lg"}> {signIn?.start_time}</p>
<p className={"text-lg"}> {signIn?.end_time}</p>
</>
) : (
<div
className={
"w-[90vw] md:w-[30vw] aspect-square flex justify-center items-center text-lg"
}
>
<img
alt={""}
className={"w-[90vw] md:w-[30vw] aspect-square"}
src={altImg}
/>
</div>
)
) : ( ) : (
<div <div
className={ className={
"w-64 justify-center flex items-center text-xl font-bold aspect-square" "w-64 justify-center flex items-center text-xl font-bold aspect-square"
} }
> >
loading
</div> </div>
)} )}
{qrcode?.qrcode && (
<>
<p className={"text-lg"}> {qrcode?.start_time}</p>
<p className={"text-lg"}> {qrcode?.end_time}</p>
</>
)}
</div> </div>
); );
} }

BIN
src/assets/altImg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB