This commit is contained in:
2025-06-30 23:25:12 +07:00
parent 417284c7f0
commit 805f5a6d4f
3 changed files with 78 additions and 70 deletions
+43
View File
@@ -0,0 +1,43 @@
import { ref } from 'vue';
interface QROptions {
width?: number;
margin?: number;
color?: {
dark: string;
light: string;
};
}
export const qrOptions = ref<QROptions>({
width: 100,
margin: 1,
color: {
dark: '#000000',
light: 'f0f0f0'
}
});
export const downloadData = (data: string) => {
const b = base64ToBytes(data)
downloadFile(b, 'teams_qr_code.pdf', 'application/pdf;teams_qr_code.pdf')
}
export const base64ToBytes = (base64: string): Uint8Array => {
const binaryString = atob(base64);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes;
}
export const downloadFile = (bytes: Uint8Array, fileName: string, mimeType: string) => {
const blob = new Blob([bytes], { type: mimeType });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
link.click();
URL.revokeObjectURL(url);
};