等待图片
This commit is contained in:
105
src/App.tsx
105
src/App.tsx
@ -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
BIN
src/assets/altImg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 231 KiB |
Reference in New Issue
Block a user