ztxkutils 2.10.10 → 2.10.11

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.
@@ -9,9 +9,15 @@ interface IOtherOption {
9
9
  authToken?: string;
10
10
  callbackAfter?: () => void;
11
11
  callbackError?: () => void;
12
+ zipName?: string;
13
+ addWaterMark?: boolean;
12
14
  }
13
15
  export declare function downloadFile(apiUrl: string, fileId: string, fileName: string, authToken?: string): void;
14
16
  export declare function downloadFileCallBack(apiUrl: string, fileId: string, fileName: string, otherOption?: IOtherOption): void;
17
+ /**
18
+ * 批量下载
19
+ */
20
+ export declare function batchDownloadFileCallBack(apiUrl: string, fileIds: string, fileNames: string, otherOption?: IOtherOption): void;
15
21
  /**
16
22
  * @description 公共文件下载,并重命名
17
23
  * @param {string} apiUrl api服务器ip端口
@@ -64,6 +64,43 @@ function downloadFileCallBack(apiUrl, fileId, fileName, otherOption) {
64
64
  };
65
65
  xhr.send();
66
66
  }
67
+ /**
68
+ * 批量下载
69
+ */
70
+ function batchDownloadFileCallBack(apiUrl, fileIds, fileNames, otherOption) {
71
+ var _a = otherOption || {}, authToken = _a.authToken, zipName = _a.zipName, addWaterMark = _a.addWaterMark, callbackAfter = _a.callbackAfter, callbackError = _a.callbackError;
72
+ var xhr = new XMLHttpRequest();
73
+ var token = getToken() || authToken;
74
+ var _apiUrl = apiUrl.endsWith('/')
75
+ ? apiUrl.slice(0, apiUrl.length - 1)
76
+ : apiUrl;
77
+ xhr.open('POST', _apiUrl + "/api/zmdms-resource/oss/endpoint/batch-download-file", true);
78
+ xhr.responseType = 'blob';
79
+ xhr.onload = function () {
80
+ if (xhr.status === 200 || xhr.status === 201) {
81
+ var link = document.createElement('a');
82
+ var body = document.querySelector('body');
83
+ link.href = window.URL.createObjectURL(xhr.response);
84
+ link.download = zipName;
85
+ // fix Firefox
86
+ link.style.display = 'none';
87
+ body.appendChild(link);
88
+ link.click();
89
+ body.removeChild(link);
90
+ window.URL.revokeObjectURL(link.href);
91
+ callbackAfter && callbackAfter();
92
+ }
93
+ else {
94
+ callbackError && callbackError();
95
+ }
96
+ };
97
+ xhr.onerror = function (err) {
98
+ callbackError && callbackError();
99
+ };
100
+ xhr.setRequestHeader('Zmdms-Auth', token || '');
101
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
102
+ xhr.send("attachIds=" + fileIds + "&fileNames=" + fileNames + "&zipName=" + zipName + "&addWaterMark=" + addWaterMark);
103
+ }
67
104
  /**
68
105
  * @description 公共文件下载,并重命名
69
106
  * @param {string} apiUrl api服务器ip端口
@@ -204,4 +241,4 @@ function createThumbnailUrl(apiUrl, fileId, scale, otherOption) {
204
241
  return _apiUrl + "/api/zmdms-resource/oss/endpoint/thumbnail/" + fileId + "?scale=" + scale + "&Zmdms-Auth=bearer " + token;
205
242
  }
206
243
 
207
- export { createDownloadUrl, createDownloadUrlNoBase, createOriginalUrl, createPublicDownloadUrl, createThumbnailUrl, downloadFile, downloadFileCallBack, downloadPublicFile, previewFile };
244
+ export { batchDownloadFileCallBack, createDownloadUrl, createDownloadUrlNoBase, createOriginalUrl, createPublicDownloadUrl, createThumbnailUrl, downloadFile, downloadFileCallBack, downloadPublicFile, previewFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.10",
3
+ "version": "2.10.11",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",