zmdms-utils 0.0.86 → 0.0.88

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 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
- reject(xhr.response);
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) {
@@ -82,6 +82,11 @@ interface IOtherOptions {
82
82
  interceptorsRequestConfig?: (config: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any>;
83
83
  /** 响应器自定义 */
84
84
  interceptorsResponseHandle?: () => void;
85
+ /**
86
+ * 是否对于接口返回200状态码的 但是 data.code非200或201的情况 也提示异常
87
+ * 这个要配合(独立接口的) isErrorMessage 一起使用
88
+ */
89
+ isStatusSuccessCodeError?: boolean;
85
90
  }
86
91
 
87
92
  export { AxiosRequest, IOptions, IOtherOptions };
@@ -92,10 +92,21 @@ var AxiosRequest = /** @class */ (function () {
92
92
  };
93
93
  // 响应成功处理
94
94
  AxiosRequest.prototype.responseSuccess = function (response) {
95
- var _a;
95
+ var _a, _b;
96
96
  var config = response.config, status = response.status, data = response.data;
97
97
  // 对返回数据进行解密后 返回给客户端
98
98
  if ((_a = response.config) === null || _a === void 0 ? void 0 : _a.isCrypto) ;
99
+ // 提示业务错误
100
+ if (this.otherOptions.isStatusSuccessCodeError &&
101
+ (config === null || config === void 0 ? void 0 : config.isErrorMessage) &&
102
+ status === 200 &&
103
+ data &&
104
+ typeof data === "object" &&
105
+ ((data === null || data === void 0 ? void 0 : data.code) !== 200 || (data === null || data === void 0 ? void 0 : data.code) !== 201)) {
106
+ // 详细信息 再开发模式开启 之后上到别的环境会去掉
107
+ (_b = this.modalConfirm) === null || _b === void 0 ? void 0 : _b.call(this, "".concat((data === null || data === void 0 ? void 0 : data.msg) || "请求异常"));
108
+ return;
109
+ }
99
110
  if (!config.isEasyMessage) {
100
111
  return response;
101
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/file.ts CHANGED
@@ -35,7 +35,13 @@ export function downloadFile(
35
35
  fileName: string,
36
36
  options: IDownloadOptions
37
37
  ) {
38
- const { API_BASEURL, authToken, waterMark = true, open } = options;
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
- reject(xhr.response);
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;
package/src/request.ts CHANGED
@@ -131,6 +131,19 @@ export class AxiosRequest {
131
131
  // 对返回数据进行解密后 返回给客户端
132
132
  if ((response.config as any)?.isCrypto) {
133
133
  }
134
+ // 提示业务错误
135
+ if (
136
+ this.otherOptions.isStatusSuccessCodeError &&
137
+ (config as any)?.isErrorMessage &&
138
+ status === 200 &&
139
+ data &&
140
+ typeof data === "object" &&
141
+ (data?.code !== 200 || data?.code !== 201)
142
+ ) {
143
+ // 详细信息 再开发模式开启 之后上到别的环境会去掉
144
+ this.modalConfirm?.(`${data?.msg || "请求异常"}`);
145
+ return;
146
+ }
134
147
  if (!(config as any).isEasyMessage) {
135
148
  return response;
136
149
  }
@@ -432,4 +445,9 @@ export interface IOtherOptions {
432
445
  ) => InternalAxiosRequestConfig<any>;
433
446
  /** 响应器自定义 */
434
447
  interceptorsResponseHandle?: () => void;
448
+ /**
449
+ * 是否对于接口返回200状态码的 但是 data.code非200或201的情况 也提示异常
450
+ * 这个要配合(独立接口的) isErrorMessage 一起使用
451
+ */
452
+ isStatusSuccessCodeError?: boolean;
435
453
  }