FPSMS-frontend
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

34 行
1.1 KiB

  1. "use client";
  2. import { NEXT_PUBLIC_API_URL } from "@/config/api";
  3. import { EquipmentResult } from "./index";
  4. export const exportEquipmentQrCode = async (equipmentIds: number[]): Promise<{ blobValue: Uint8Array; filename: string }> => {
  5. const token = localStorage.getItem("accessToken");
  6. const response = await fetch(`${NEXT_PUBLIC_API_URL}/Equipment/export-qrcode`, {
  7. method: "POST",
  8. headers: {
  9. "Content-Type": "application/json",
  10. ...(token && { Authorization: `Bearer ${token}` }),
  11. },
  12. body: JSON.stringify({ equipmentIds }),
  13. });
  14. if (!response.ok) {
  15. if (response.status === 401) {
  16. throw new Error("Unauthorized: Please log in again");
  17. }
  18. throw new Error(`Failed to export QR code: ${response.status} ${response.statusText}`);
  19. }
  20. const filename = response.headers.get("Content-Disposition")?.split("filename=")[1]?.replace(/"/g, "") || "equipment_qrcode.pdf";
  21. const blob = await response.blob();
  22. const arrayBuffer = await blob.arrayBuffer();
  23. const blobValue = new Uint8Array(arrayBuffer);
  24. return { blobValue, filename };
  25. };