-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp
More file actions
62 lines (53 loc) · 1.27 KB
/
tmp
File metadata and controls
62 lines (53 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { useState } from "react";
// 一个简单的全屏 Loading Modal
function LoadingModal({ visible }) {
if (!visible) return null;
return (
<div style={styles.overlay}>
<div style={styles.modal}>
<div className="spinner" />
<p>处理中,请稍候…</p>
</div>
</div>
);
}
export default function Example() {
const [loading, setLoading] = useState(false);
const fetchData = async () => {
try {
setLoading(true); // 显示 modal
// 模拟 API 请求
await new Promise((resolve) => setTimeout(resolve, 2000));
// 这里放真实的 API 调用,例如:
// await fetch("/api/data");
} finally {
setLoading(false); // 请求完成,关闭 modal
}
};
return (
<div>
<button onClick={fetchData}>请求 API</button>
<LoadingModal visible={loading} />
</div>
);
}
const styles = {
overlay: {
position: "fixed",
top: 0,
left: 0,
width: "100vw",
height: "100vh",
backgroundColor: "rgba(0,0,0,0.4)",
display: "flex",
alignItems: "center",
justifyContent: "center",
zIndex: 99999,
},
modal: {
background: "#fff",
padding: "24px 32px",
borderRadius: "8px",
boxShadow: "0 4px 12px rgba(0,0,0,0.25)",
},
};