sa2kit 1.6.97 → 1.6.100

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.
@@ -556,11 +556,13 @@ var UniversalExportClient = class {
556
556
  * 转换API返回的导出结果
557
557
  */
558
558
  transformExportResultFromAPI(apiResult) {
559
+ const fileBlob = this.createFileBlobFromBase64(apiResult.fileData, apiResult.fileName);
559
560
  return {
560
561
  exportId: apiResult.exportId,
561
562
  fileName: apiResult.fileName,
562
563
  fileSize: apiResult.fileSize,
563
564
  fileUrl: apiResult.fileUrl,
565
+ fileBlob,
564
566
  exportedRows: apiResult.exportedRows,
565
567
  startTime: new Date(apiResult.startTime),
566
568
  endTime: new Date(apiResult.endTime),
@@ -568,6 +570,57 @@ var UniversalExportClient = class {
568
570
  statistics: apiResult.statistics
569
571
  };
570
572
  }
573
+ /**
574
+ * 将后端返回的base64文件数据转换为Blob
575
+ */
576
+ createFileBlobFromBase64(fileData, fileName) {
577
+ if (!fileData || typeof fileData !== "string") {
578
+ return void 0;
579
+ }
580
+ try {
581
+ if (typeof atob === "function") {
582
+ const binaryString = atob(fileData);
583
+ const bytes = new Uint8Array(binaryString.length);
584
+ for (let i = 0; i < binaryString.length; i++) {
585
+ bytes[i] = binaryString.charCodeAt(i);
586
+ }
587
+ const arrayBuffer = bytes.buffer.slice(
588
+ bytes.byteOffset,
589
+ bytes.byteOffset + bytes.byteLength
590
+ );
591
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
592
+ } else if (typeof Buffer !== "undefined") {
593
+ const bufferBytes = Buffer.from(fileData, "base64");
594
+ const bytes = Uint8Array.from(bufferBytes);
595
+ const arrayBuffer = bytes.buffer.slice(
596
+ bytes.byteOffset,
597
+ bytes.byteOffset + bytes.byteLength
598
+ );
599
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
600
+ } else {
601
+ return void 0;
602
+ }
603
+ } catch {
604
+ return void 0;
605
+ }
606
+ }
607
+ /**
608
+ * 根据文件名推断MIME类型
609
+ */
610
+ getMimeTypeByFileName(fileName) {
611
+ const extension = fileName?.split(".").pop()?.toLowerCase();
612
+ switch (extension) {
613
+ case "csv":
614
+ return "text/csv; charset=utf-8";
615
+ case "xlsx":
616
+ case "xls":
617
+ return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
618
+ case "json":
619
+ return "application/json; charset=utf-8";
620
+ default:
621
+ return "application/octet-stream";
622
+ }
623
+ }
571
624
  /**
572
625
  * 转换API返回的进度数据
573
626
  */