zmdms-utils 0.0.86 → 0.0.87
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.
- package/dist/es/file.d.ts +2 -0
- package/dist/es/file.js +27 -2
- package/package.json +1 -1
- package/src/file.ts +36 -2
package/dist/es/file.d.ts
CHANGED
|
@@ -99,6 +99,8 @@ interface IDownloadOptions extends IOptions {
|
|
|
99
99
|
waterMark?: boolean | string;
|
|
100
100
|
/** 是否开发不需要登录信息 */
|
|
101
101
|
open?: boolean;
|
|
102
|
+
/** 是否解析异常blob结果 */
|
|
103
|
+
parseErrorBlob?: boolean;
|
|
102
104
|
}
|
|
103
105
|
interface IBatchDownloadOptions extends IOptions {
|
|
104
106
|
zipName: string;
|
package/dist/es/file.js
CHANGED
|
@@ -19,7 +19,7 @@ var isZmdmsFileService = FILE_SERVICE === "zmdms";
|
|
|
19
19
|
* @param options.open boolean 是否不需要登录信息
|
|
20
20
|
*/
|
|
21
21
|
function downloadFile(fileId, fileName, options) {
|
|
22
|
-
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, _a = options.waterMark, waterMark = _a === void 0 ? true : _a, open = options.open;
|
|
22
|
+
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, _a = options.waterMark, waterMark = _a === void 0 ? true : _a, open = options.open, _b = options.parseErrorBlob, parseErrorBlob = _b === void 0 ? false : _b;
|
|
23
23
|
if (isZmdmsFileService) {
|
|
24
24
|
fileId = encodeFileId(fileId, 2);
|
|
25
25
|
}
|
|
@@ -49,7 +49,32 @@ function downloadFile(fileId, fileName, options) {
|
|
|
49
49
|
resolve({ msg: "文件下载成功!" });
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
|
-
|
|
52
|
+
if (!parseErrorBlob) {
|
|
53
|
+
reject(xhr.response);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
if (Object.prototype.toString.call(xhr.response) === "[object Blob]") {
|
|
58
|
+
var blob = xhr.response;
|
|
59
|
+
blob
|
|
60
|
+
.text()
|
|
61
|
+
.then(function (text) {
|
|
62
|
+
var json = JSON.parse(text);
|
|
63
|
+
reject(json);
|
|
64
|
+
})
|
|
65
|
+
.catch(function (err) {
|
|
66
|
+
reject({
|
|
67
|
+
msg: (err === null || err === void 0 ? void 0 : err.message) || (err === null || err === void 0 ? void 0 : err.msg) || "下载失败!",
|
|
68
|
+
code: xhr.status,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
reject({
|
|
75
|
+
msg: "下载失败!",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
53
78
|
}
|
|
54
79
|
};
|
|
55
80
|
xhr.onerror = function (err) {
|
package/package.json
CHANGED
package/src/file.ts
CHANGED
|
@@ -35,7 +35,13 @@ export function downloadFile(
|
|
|
35
35
|
fileName: string,
|
|
36
36
|
options: IDownloadOptions
|
|
37
37
|
) {
|
|
38
|
-
const {
|
|
38
|
+
const {
|
|
39
|
+
API_BASEURL,
|
|
40
|
+
authToken,
|
|
41
|
+
waterMark = true,
|
|
42
|
+
open,
|
|
43
|
+
parseErrorBlob = false,
|
|
44
|
+
} = options;
|
|
39
45
|
if (isZmdmsFileService) {
|
|
40
46
|
fileId = encodeFileId(fileId, 2);
|
|
41
47
|
}
|
|
@@ -76,7 +82,33 @@ export function downloadFile(
|
|
|
76
82
|
|
|
77
83
|
resolve({ msg: "文件下载成功!" });
|
|
78
84
|
} else {
|
|
79
|
-
|
|
85
|
+
if (!parseErrorBlob) {
|
|
86
|
+
reject(xhr.response);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
if (
|
|
91
|
+
Object.prototype.toString.call(xhr.response) === "[object Blob]"
|
|
92
|
+
) {
|
|
93
|
+
const blob = xhr.response;
|
|
94
|
+
blob
|
|
95
|
+
.text()
|
|
96
|
+
.then((text: any) => {
|
|
97
|
+
const json = JSON.parse(text);
|
|
98
|
+
reject(json);
|
|
99
|
+
})
|
|
100
|
+
.catch((err: any) => {
|
|
101
|
+
reject({
|
|
102
|
+
msg: err?.message || err?.msg || "下载失败!",
|
|
103
|
+
code: xhr.status,
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
reject({
|
|
109
|
+
msg: "下载失败!",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
80
112
|
}
|
|
81
113
|
};
|
|
82
114
|
xhr.onerror = function (err) {
|
|
@@ -470,6 +502,8 @@ interface IDownloadOptions extends IOptions {
|
|
|
470
502
|
waterMark?: boolean | string;
|
|
471
503
|
/** 是否开发不需要登录信息 */
|
|
472
504
|
open?: boolean;
|
|
505
|
+
/** 是否解析异常blob结果 */
|
|
506
|
+
parseErrorBlob?: boolean;
|
|
473
507
|
}
|
|
474
508
|
interface IBatchDownloadOptions extends IOptions {
|
|
475
509
|
zipName: string;
|