This commit is contained in:
Viet An
2026-07-02 09:07:59 +07:00
parent 1fc8532ed8
commit e91f0d22c4
52 changed files with 131 additions and 159 deletions

View File

@@ -1,28 +0,0 @@
import dayjs from "dayjs";
import html2canvas from "html2canvas-pro";
export default async function exportImage(docid, filename = "file") {
const target = document.getElementById(docid);
const ignored = target.querySelectorAll(".ignore");
ignored.forEach((el) => el.style.setProperty("display", "none", "important"));
// Xóa cache ảnh để lần export sau không bị lỗi
target.querySelectorAll("img").forEach((img) => (img.src = `${img.src}`));
const restoreIcons = swapIconsForExport(target);
try {
await new Promise((r) => requestAnimationFrame(r));
const canvas = await html2canvas(target);
const link = document.createElement("a");
link.href = canvas.toDataURL("image/png");
link.download = `${filename}-${dayjs().format("YYYYMMDDHHmmss")}.png`;
link.click();
link.remove();
} finally {
restoreIcons();
ignored.forEach((el) => el.style.removeProperty("display"));
}
return filename;
}

View File

@@ -1,35 +0,0 @@
import dayjs from "dayjs";
import html2pdf from "html2pdf.js";
export default async function exportPdf(docid, { filename = "file", format = "a4", orientation = "portrait" } = {}) {
const target = document.getElementById(docid);
const ignored = target.querySelectorAll(".ignore");
ignored.forEach((el) => el.style.setProperty("display", "none", "important"));
// Xóa cache ảnh để lần export sau không bị lỗi
target.querySelectorAll("img").forEach((img) => (img.src = `${img.src}`));
const restoreIcons = swapIconsForExport(target);
const opt = {
margin: 3,
filename: `${filename}-${dayjs().format("YYYYMMDDHHmmss")}.pdf`,
jsPDF: { format, orientation, unit: "mm" },
html2canvas: { scale: 3, useCORS: true },
image: { type: "jpeg", quality: 1 },
pagebreak: {
mode: ["avoid-all", "css", "legacy"],
before: ".page-break-before",
after: ".page-break-after",
avoid: ".avoid-page-break",
},
};
try {
await new Promise((r) => requestAnimationFrame(r));
await html2pdf().set(opt).from(target).save();
} finally {
restoreIcons();
ignored.forEach((el) => el.style.removeProperty("display"));
}
return opt.filename;
}

View File

@@ -1,20 +0,0 @@
export default function qr(amount, qrVars = {}) {
const defaultQRVars = {
bankId: "BIDV",
accountNo: "1222198820",
accountName: "Nguyen Viet An",
template: "Rxp4lcv",
description: "Thanh toan ERP",
};
const finalVars = {
...defaultQRVars,
...qrVars,
};
const { bankId, accountNo, template, description, accountName } = finalVars;
const qrSrc = `https://img.vietqr.io/image/${bankId}-${accountNo}-${template}.png?amount=${amount}&addInfo=${description}&accountName=${accountName}`;
return qrSrc;
}