等待图片

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

BIN
src/assets/altImg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB