trithuc-mvc-react 3.4.9 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,108 +1,79 @@
|
|
|
1
1
|
import { URL_APPLICATION, URL_APPLICATION_API } from "@/constants";
|
|
2
2
|
import { Download } from "@mui/icons-material";
|
|
3
3
|
import { Button, IconButton, Tooltip, Typography, useMediaQuery, useTheme } from "@mui/material";
|
|
4
|
+
import { useState } from "react";
|
|
4
5
|
import { toast } from "react-toastify";
|
|
5
6
|
import { exportExcel } from "../../api";
|
|
7
|
+
import useBlockNavigation from "./useBlockNavigation";
|
|
8
|
+
import LoadingOverlay from "./LoadingOverlay";
|
|
6
9
|
|
|
7
10
|
const ExportExcelButton = ({ tableName, data, size = "small" }) => {
|
|
8
11
|
const theme = useTheme();
|
|
9
|
-
const isSmallScreen = useMediaQuery(theme.breakpoints.down("sm"));
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const isSmallScreen = useMediaQuery(theme.breakpoints.down("sm"));
|
|
13
|
+
const [exporting, setExporting] = useState(false);
|
|
14
|
+
|
|
15
|
+
// 🚫 Chặn reload / close tab khi đang export
|
|
16
|
+
useBlockNavigation(exporting);
|
|
17
|
+
|
|
18
|
+
const handleExportExcel = async () => {
|
|
19
|
+
try {
|
|
20
|
+
setExporting(true);
|
|
21
|
+
|
|
22
|
+
const res = await exportExcel({ tableName, data });
|
|
23
|
+
|
|
24
|
+
if (res?.status) {
|
|
25
|
+
const url = URL_APPLICATION_API ? URL_APPLICATION + res.url : res.url;
|
|
26
|
+
|
|
27
|
+
window.open(url, "_blank");
|
|
15
28
|
} else {
|
|
16
|
-
|
|
29
|
+
toast.error("Xuất file thất bại!");
|
|
17
30
|
}
|
|
18
|
-
}
|
|
19
|
-
toast.error("
|
|
31
|
+
} catch (error) {
|
|
32
|
+
toast.error("Có lỗi khi xuất Excel!");
|
|
33
|
+
} finally {
|
|
34
|
+
setExporting(false);
|
|
20
35
|
}
|
|
21
36
|
};
|
|
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
|
-
variant="outlined"
|
|
62
|
-
color="primary"
|
|
63
|
-
size={size}
|
|
64
|
-
onClick={() => {
|
|
65
|
-
handleExportExcel(tableName, data);
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
68
|
-
<Download fontSize="inherit" />
|
|
69
|
-
</IconButton>
|
|
70
|
-
</Tooltip>
|
|
71
|
-
// <Button
|
|
72
|
-
// size={size}
|
|
73
|
-
// variant="outlined"
|
|
74
|
-
// startIcon={<Download />}
|
|
75
|
-
// onClick={() => {
|
|
76
|
-
// handleExportExcel(tableName, data);
|
|
77
|
-
// }}
|
|
78
|
-
// sx={{
|
|
79
|
-
// ml: 0.5,
|
|
80
|
-
// mr: 0.5,
|
|
81
|
-
// fontSize: {
|
|
82
|
-
// xs: "0.75rem",
|
|
83
|
-
// sm: "0.875rem",
|
|
84
|
-
// md: "1rem"
|
|
85
|
-
// },
|
|
86
|
-
// textAlign: "center",
|
|
87
|
-
// textTransform: "none"
|
|
88
|
-
// }}
|
|
89
|
-
// >
|
|
90
|
-
// <Typography
|
|
91
|
-
// noWrap
|
|
92
|
-
// sx={{
|
|
93
|
-
// width: "100%",
|
|
94
|
-
// fontSize: {
|
|
95
|
-
// xs: "0.75rem",
|
|
96
|
-
// sm: "0.875rem",
|
|
97
|
-
// md: "1rem"
|
|
98
|
-
// },
|
|
99
|
-
// textAlign: "center",
|
|
100
|
-
// textTransform: "none" // ✅ Đảm bảo chữ gốc giữ nguyên
|
|
101
|
-
// }}
|
|
102
|
-
// >
|
|
103
|
-
// Excel
|
|
104
|
-
// </Typography>
|
|
105
|
-
// </Button>
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
{/* 🔔 Màn hình chờ API */}
|
|
41
|
+
<LoadingOverlay open={exporting} text="Đang xuất file , vui lòng đợi..." />
|
|
42
|
+
|
|
43
|
+
{!isSmallScreen ? (
|
|
44
|
+
<Button
|
|
45
|
+
size={size}
|
|
46
|
+
variant="outlined"
|
|
47
|
+
startIcon={<Download />}
|
|
48
|
+
disabled={exporting}
|
|
49
|
+
onClick={handleExportExcel}
|
|
50
|
+
sx={{ ml: 0.5, mr: 0.5 }}
|
|
51
|
+
>
|
|
52
|
+
<Typography
|
|
53
|
+
noWrap
|
|
54
|
+
sx={{
|
|
55
|
+
width: "100%",
|
|
56
|
+
fontSize: {
|
|
57
|
+
xs: "0.65rem",
|
|
58
|
+
sm: "0.75rem",
|
|
59
|
+
md: "0.95rem"
|
|
60
|
+
},
|
|
61
|
+
textAlign: "center",
|
|
62
|
+
textTransform: "none"
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
Excel
|
|
66
|
+
</Typography>
|
|
67
|
+
</Button>
|
|
68
|
+
) : (
|
|
69
|
+
<Tooltip title="Excel">
|
|
70
|
+
<IconButton color="primary" size={size} disabled={exporting} onClick={handleExportExcel}>
|
|
71
|
+
<Download fontSize="inherit" />
|
|
72
|
+
</IconButton>
|
|
73
|
+
</Tooltip>
|
|
74
|
+
)}
|
|
75
|
+
</>
|
|
106
76
|
);
|
|
107
77
|
};
|
|
78
|
+
|
|
108
79
|
export default ExportExcelButton;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Modal, Box, CircularProgress, Typography } from "@mui/material";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import HubOutlinedIcon from "@mui/icons-material/HubOutlined";
|
|
4
|
+
|
|
5
|
+
const LoadingOverlay = ({ open, text }) => {
|
|
6
|
+
const [progress, setProgress] = useState(0);
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!open) {
|
|
10
|
+
setProgress(0);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const timer = setInterval(() => {
|
|
15
|
+
setProgress((p) => (p < 96 ? p + Math.random() * 3 : p));
|
|
16
|
+
}, 420);
|
|
17
|
+
|
|
18
|
+
return () => clearInterval(timer);
|
|
19
|
+
}, [open]);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Modal open={open} sx={{ zIndex: 99999 }}>
|
|
23
|
+
<Box
|
|
24
|
+
display="flex"
|
|
25
|
+
alignItems="center"
|
|
26
|
+
justifyContent="center"
|
|
27
|
+
height="100vh"
|
|
28
|
+
sx={{
|
|
29
|
+
backdropFilter: "blur(8px)",
|
|
30
|
+
backgroundColor: "rgba(225,235,245,0.65)"
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<Box
|
|
34
|
+
sx={{
|
|
35
|
+
width: 320,
|
|
36
|
+
px: 4,
|
|
37
|
+
py: 4,
|
|
38
|
+
borderRadius: 3,
|
|
39
|
+
background: "linear-gradient(180deg, rgba(255,255,255,0.96), rgba(240,247,255,0.96))",
|
|
40
|
+
boxShadow: "0 25px 50px rgba(0,60,120,0.25)",
|
|
41
|
+
border: "1px solid rgba(0,120,200,0.2)",
|
|
42
|
+
color: "#0d2b45",
|
|
43
|
+
textAlign: "center"
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{/* ICON */}
|
|
47
|
+
<Box
|
|
48
|
+
sx={{
|
|
49
|
+
width: 60,
|
|
50
|
+
height: 60,
|
|
51
|
+
borderRadius: "50%",
|
|
52
|
+
mx: "auto",
|
|
53
|
+
mb: 2.5,
|
|
54
|
+
background: "linear-gradient(135deg, rgba(0,150,255,0.18), rgba(0,200,255,0.28))",
|
|
55
|
+
display: "flex",
|
|
56
|
+
alignItems: "center",
|
|
57
|
+
justifyContent: "center",
|
|
58
|
+
animation: "pulse 2.4s infinite",
|
|
59
|
+
"@keyframes pulse": {
|
|
60
|
+
"0%": { boxShadow: "0 0 0 0 rgba(0,150,255,0.45)" },
|
|
61
|
+
"70%": { boxShadow: "0 0 0 20px rgba(0,150,255,0)" },
|
|
62
|
+
"100%": { boxShadow: "0 0 0 0 rgba(0,150,255,0)" }
|
|
63
|
+
}
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<HubOutlinedIcon sx={{ fontSize: 30, color: "#0277bd" }} />
|
|
67
|
+
</Box>
|
|
68
|
+
|
|
69
|
+
<Typography fontSize="1rem" fontWeight={600}>
|
|
70
|
+
{text || "Đang khởi tạo dữ liệu hệ thống"}
|
|
71
|
+
</Typography>
|
|
72
|
+
|
|
73
|
+
<Typography fontSize="0.75rem" color="rgba(13,43,69,0.7)" mt={0.6}>
|
|
74
|
+
Nền tảng số đang xử lý và kết nối dữ liệu
|
|
75
|
+
</Typography>
|
|
76
|
+
|
|
77
|
+
<Box mt={3}>
|
|
78
|
+
<CircularProgress
|
|
79
|
+
variant="determinate"
|
|
80
|
+
value={Math.min(progress, 100)}
|
|
81
|
+
size={50}
|
|
82
|
+
thickness={4}
|
|
83
|
+
sx={{
|
|
84
|
+
color: "#0288d1",
|
|
85
|
+
mb: 1
|
|
86
|
+
}}
|
|
87
|
+
/>
|
|
88
|
+
<Typography fontSize="0.8rem" fontWeight={500}>
|
|
89
|
+
{Math.floor(progress)}%
|
|
90
|
+
</Typography>
|
|
91
|
+
</Box>
|
|
92
|
+
</Box>
|
|
93
|
+
</Box>
|
|
94
|
+
</Modal>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default LoadingOverlay;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Chặn navigate (reload / close tab) khi shouldBlock = true
|
|
5
|
+
*/
|
|
6
|
+
const useBlockNavigation = (shouldBlock) => {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!shouldBlock) return;
|
|
9
|
+
|
|
10
|
+
const handleBeforeUnload = (event) => {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
event.returnValue = ""; // Bắt buộc cho Chrome
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
16
|
+
|
|
17
|
+
return () => {
|
|
18
|
+
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
19
|
+
};
|
|
20
|
+
}, [shouldBlock]);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default useBlockNavigation;
|