sa2kit 1.6.98 → 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.
@@ -7461,11 +7461,13 @@ var UniversalExportClient = class {
7461
7461
  * 转换API返回的导出结果
7462
7462
  */
7463
7463
  transformExportResultFromAPI(apiResult) {
7464
+ const fileBlob = this.createFileBlobFromBase64(apiResult.fileData, apiResult.fileName);
7464
7465
  return {
7465
7466
  exportId: apiResult.exportId,
7466
7467
  fileName: apiResult.fileName,
7467
7468
  fileSize: apiResult.fileSize,
7468
7469
  fileUrl: apiResult.fileUrl,
7470
+ fileBlob,
7469
7471
  exportedRows: apiResult.exportedRows,
7470
7472
  startTime: new Date(apiResult.startTime),
7471
7473
  endTime: new Date(apiResult.endTime),
@@ -7473,6 +7475,57 @@ var UniversalExportClient = class {
7473
7475
  statistics: apiResult.statistics
7474
7476
  };
7475
7477
  }
7478
+ /**
7479
+ * 将后端返回的base64文件数据转换为Blob
7480
+ */
7481
+ createFileBlobFromBase64(fileData, fileName) {
7482
+ if (!fileData || typeof fileData !== "string") {
7483
+ return void 0;
7484
+ }
7485
+ try {
7486
+ if (typeof atob === "function") {
7487
+ const binaryString = atob(fileData);
7488
+ const bytes = new Uint8Array(binaryString.length);
7489
+ for (let i = 0; i < binaryString.length; i++) {
7490
+ bytes[i] = binaryString.charCodeAt(i);
7491
+ }
7492
+ const arrayBuffer = bytes.buffer.slice(
7493
+ bytes.byteOffset,
7494
+ bytes.byteOffset + bytes.byteLength
7495
+ );
7496
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
7497
+ } else if (typeof Buffer !== "undefined") {
7498
+ const bufferBytes = Buffer.from(fileData, "base64");
7499
+ const bytes = Uint8Array.from(bufferBytes);
7500
+ const arrayBuffer = bytes.buffer.slice(
7501
+ bytes.byteOffset,
7502
+ bytes.byteOffset + bytes.byteLength
7503
+ );
7504
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
7505
+ } else {
7506
+ return void 0;
7507
+ }
7508
+ } catch {
7509
+ return void 0;
7510
+ }
7511
+ }
7512
+ /**
7513
+ * 根据文件名推断MIME类型
7514
+ */
7515
+ getMimeTypeByFileName(fileName) {
7516
+ const extension = fileName?.split(".").pop()?.toLowerCase();
7517
+ switch (extension) {
7518
+ case "csv":
7519
+ return "text/csv; charset=utf-8";
7520
+ case "xlsx":
7521
+ case "xls":
7522
+ return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
7523
+ case "json":
7524
+ return "application/json; charset=utf-8";
7525
+ default:
7526
+ return "application/octet-stream";
7527
+ }
7528
+ }
7476
7529
  /**
7477
7530
  * 转换API返回的进度数据
7478
7531
  */