fix download pdf logo issue
This commit is contained in:
parent
4bc6712e60
commit
c4b293fb74
|
|
@ -331,7 +331,7 @@ public static class ReportEmailService
|
|||
return $@"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta charset=""utf-8""></head>
|
||||
<head><meta charset=""utf-8""><style>*{{-webkit-print-color-adjust:exact!important;color-adjust:exact!important;print-color-adjust:exact!important}}@page{{margin:10mm;size:A4}}</style></head>
|
||||
<body style=""margin:0;padding:0;background:#f4f4f4;font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#333"">
|
||||
<table width=""100%"" cellpadding=""0"" cellspacing=""0"" style=""background:#f4f4f4;padding:20px 0"">
|
||||
<tr><td align=""center"">
|
||||
|
|
@ -628,7 +628,7 @@ public static class ReportEmailService
|
|||
return $@"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta charset=""utf-8""></head>
|
||||
<head><meta charset=""utf-8""><style>*{{-webkit-print-color-adjust:exact!important;color-adjust:exact!important;print-color-adjust:exact!important}}@page{{margin:10mm;size:A4}}</style></head>
|
||||
<body style=""margin:0;padding:0;background:#f4f4f4;font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#333"">
|
||||
<table width=""100%"" cellpadding=""0"" cellspacing=""0"" style=""background:#f4f4f4;padding:20px 0"">
|
||||
<tr><td align=""center"">
|
||||
|
|
@ -714,7 +714,7 @@ public static class ReportEmailService
|
|||
return $@"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta charset=""utf-8""></head>
|
||||
<head><meta charset=""utf-8""><style>*{{-webkit-print-color-adjust:exact!important;color-adjust:exact!important;print-color-adjust:exact!important}}@page{{margin:10mm;size:A4}}</style></head>
|
||||
<body style=""margin:0;padding:0;background:#f4f4f4;font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#333"">
|
||||
<table width=""100%"" cellpadding=""0"" cellspacing=""0"" style=""background:#f4f4f4;padding:20px 0"">
|
||||
<tr><td align=""center"">
|
||||
|
|
|
|||
|
|
@ -618,6 +618,7 @@ function SodioHomeInstallation(props: singleInstallationProps) {
|
|||
element={
|
||||
<WeeklyReport
|
||||
installationId={props.current_installation.id}
|
||||
installationName={props.current_installation.name}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import DailySection from './DailySection';
|
|||
|
||||
interface WeeklyReportProps {
|
||||
installationId: number;
|
||||
installationName?: string;
|
||||
}
|
||||
|
||||
interface DailyEnergyData {
|
||||
|
|
@ -223,7 +224,7 @@ function EmailBar({ onSend, disabled }: { onSend: (email: string) => Promise<voi
|
|||
|
||||
// ── Main Component ─────────────────────────────────────────────
|
||||
|
||||
function WeeklyReport({ installationId }: WeeklyReportProps) {
|
||||
function WeeklyReport({ installationId, installationName }: WeeklyReportProps) {
|
||||
const intl = useIntl();
|
||||
const [activeTab, setActiveTab] = useState(0);
|
||||
const [monthlyReports, setMonthlyReports] = useState<MonthlyReport[]>([]);
|
||||
|
|
@ -340,11 +341,19 @@ function WeeklyReport({ installationId }: WeeklyReportProps) {
|
|||
? `${reportPeriod.start.replace(/-/g, '')}-${reportPeriod.end.replace(/-/g, '')}`
|
||||
: new Date().toISOString().split('T')[0].replace(/-/g, '');
|
||||
|
||||
const safeName = (installationName || String(installationId))
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^a-zA-Z0-9\-_]/g, '');
|
||||
|
||||
printWindow.document.write(res.data);
|
||||
printWindow.document.close();
|
||||
printWindow.document.title = `inesco-energy-${installationId}-${reportType}-${dateRange}`;
|
||||
printWindow.document.title = `${safeName}-${reportType}-${dateRange}`;
|
||||
printWindow.onafterprint = () => printWindow.close();
|
||||
setTimeout(() => printWindow.print(), 500);
|
||||
const imgs = printWindow.document.querySelectorAll('img');
|
||||
const allLoaded = Array.from(imgs).map(img =>
|
||||
img.complete ? Promise.resolve() : new Promise<void>(r => { img.onload = () => r(); img.onerror = () => r(); })
|
||||
);
|
||||
Promise.all(allLoaded).then(() => setTimeout(() => printWindow.print(), 200));
|
||||
} catch (err) {
|
||||
console.error('PDF download failed', err);
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Reference in New Issue