sa2kit 1.6.98 → 1.6.101

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.
@@ -72,6 +72,14 @@ declare class UniversalExportClient {
72
72
  * 转换API返回的导出结果
73
73
  */
74
74
  private transformExportResultFromAPI;
75
+ /**
76
+ * 将后端返回的base64文件数据转换为Blob
77
+ */
78
+ private createFileBlobFromBase64;
79
+ /**
80
+ * 根据文件名推断MIME类型
81
+ */
82
+ private getMimeTypeByFileName;
75
83
  /**
76
84
  * 转换API返回的进度数据
77
85
  */
@@ -72,6 +72,14 @@ declare class UniversalExportClient {
72
72
  * 转换API返回的导出结果
73
73
  */
74
74
  private transformExportResultFromAPI;
75
+ /**
76
+ * 将后端返回的base64文件数据转换为Blob
77
+ */
78
+ private createFileBlobFromBase64;
79
+ /**
80
+ * 根据文件名推断MIME类型
81
+ */
82
+ private getMimeTypeByFileName;
75
83
  /**
76
84
  * 转换API返回的进度数据
77
85
  */
@@ -409,7 +409,6 @@ var UniversalExportClient = class {
409
409
  try {
410
410
  const isDataArray = Array.isArray(request.dataSource);
411
411
  const requestBody = {
412
- configId: request.configId,
413
412
  queryParams: request.queryParams,
414
413
  fieldMapping: request.fieldMapping,
415
414
  filters: request.filters,
@@ -417,6 +416,14 @@ var UniversalExportClient = class {
417
416
  pagination: request.pagination,
418
417
  customFileName: request.customFileName
419
418
  };
419
+ if (typeof request.configId === "string") {
420
+ requestBody.configId = request.configId;
421
+ } else {
422
+ requestBody.config = request.configId;
423
+ if (request.configId?.id) {
424
+ requestBody.configId = request.configId.id;
425
+ }
426
+ }
420
427
  if (isDataArray) {
421
428
  requestBody.data = request.dataSource;
422
429
  } else {
@@ -562,11 +569,13 @@ var UniversalExportClient = class {
562
569
  * 转换API返回的导出结果
563
570
  */
564
571
  transformExportResultFromAPI(apiResult) {
572
+ const fileBlob = this.createFileBlobFromBase64(apiResult.fileData, apiResult.fileName);
565
573
  return {
566
574
  exportId: apiResult.exportId,
567
575
  fileName: apiResult.fileName,
568
576
  fileSize: apiResult.fileSize,
569
577
  fileUrl: apiResult.fileUrl,
578
+ fileBlob,
570
579
  exportedRows: apiResult.exportedRows,
571
580
  startTime: new Date(apiResult.startTime),
572
581
  endTime: new Date(apiResult.endTime),
@@ -574,6 +583,57 @@ var UniversalExportClient = class {
574
583
  statistics: apiResult.statistics
575
584
  };
576
585
  }
586
+ /**
587
+ * 将后端返回的base64文件数据转换为Blob
588
+ */
589
+ createFileBlobFromBase64(fileData, fileName) {
590
+ if (!fileData || typeof fileData !== "string") {
591
+ return void 0;
592
+ }
593
+ try {
594
+ if (typeof atob === "function") {
595
+ const binaryString = atob(fileData);
596
+ const bytes = new Uint8Array(binaryString.length);
597
+ for (let i = 0; i < binaryString.length; i++) {
598
+ bytes[i] = binaryString.charCodeAt(i);
599
+ }
600
+ const arrayBuffer = bytes.buffer.slice(
601
+ bytes.byteOffset,
602
+ bytes.byteOffset + bytes.byteLength
603
+ );
604
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
605
+ } else if (typeof Buffer !== "undefined") {
606
+ const bufferBytes = Buffer.from(fileData, "base64");
607
+ const bytes = Uint8Array.from(bufferBytes);
608
+ const arrayBuffer = bytes.buffer.slice(
609
+ bytes.byteOffset,
610
+ bytes.byteOffset + bytes.byteLength
611
+ );
612
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
613
+ } else {
614
+ return void 0;
615
+ }
616
+ } catch {
617
+ return void 0;
618
+ }
619
+ }
620
+ /**
621
+ * 根据文件名推断MIME类型
622
+ */
623
+ getMimeTypeByFileName(fileName) {
624
+ const extension = fileName?.split(".").pop()?.toLowerCase();
625
+ switch (extension) {
626
+ case "csv":
627
+ return "text/csv; charset=utf-8";
628
+ case "xlsx":
629
+ case "xls":
630
+ return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
631
+ case "json":
632
+ return "application/json; charset=utf-8";
633
+ default:
634
+ return "application/octet-stream";
635
+ }
636
+ }
577
637
  /**
578
638
  * 转换API返回的进度数据
579
639
  */