zmdms-utils 0.0.14 → 0.0.16

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
@@ -1,3 +1,5 @@
1
+ import { AxiosResponse } from 'axios';
2
+
1
3
  /**
2
4
  * 附件下载方法
3
5
  * @param fileId 附件id
@@ -34,6 +36,12 @@ declare function batchDownloadFiles(fileList: {
34
36
  * @param options.fileList { attachId: string, attachName: string ... }[] 附件列表。批量预览时有用
35
37
  */
36
38
  declare function previewFile(fileId: string, fileName: string, options: IPreviewOptions): void;
39
+ /**
40
+ * 导出一个文件流
41
+ * @param response 需要导出的文件流
42
+ * @param fileName 文件名称
43
+ */
44
+ declare function exportBolb(response: AxiosResponse, fileName?: string): Promise<unknown>;
37
45
  /**
38
46
  * 生成附件下载链接
39
47
  * @param fileId 附件id
@@ -115,4 +123,4 @@ interface IThumbnailLinkOptions extends Partial<IOptions> {
115
123
  scale?: number;
116
124
  }
117
125
 
118
- export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, previewFile };
126
+ export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile };
package/dist/es/file.js CHANGED
@@ -147,6 +147,60 @@ function previewFile(fileId, fileName, options) {
147
147
  (fileName ? "&titleName=".concat(encodeURIComponent(previewFileName)) : ""));
148
148
  }
149
149
  }
150
+ /**
151
+ * 导出一个文件流
152
+ * @param response 需要导出的文件流
153
+ * @param fileName 文件名称
154
+ */
155
+ function exportBolb(response, fileName) {
156
+ return new Promise(function (resolve, reject) {
157
+ try {
158
+ var content = response.data;
159
+ var blob = new Blob([content], {
160
+ type: response.headers["content-type"],
161
+ });
162
+ // 判断是否支持下载
163
+ if ("download" in document.createElement("a")) {
164
+ // 非IE下载
165
+ var elink = document.createElement("a");
166
+ // 获取系统返回的名称
167
+ var copyName = response.headers["content-disposition"]
168
+ .split(";")[1]
169
+ .split("=")[1];
170
+ // 可以自定义名称
171
+ if (fileName) {
172
+ elink.download = fileName;
173
+ }
174
+ else if (copyName) {
175
+ // Content-disposition
176
+ elink.download = decodeURIComponent(copyName);
177
+ }
178
+ elink.style.display = "none";
179
+ elink.href = URL.createObjectURL(blob);
180
+ document.body.appendChild(elink);
181
+ elink.click();
182
+ URL.revokeObjectURL(elink.href); // 释放URL 对象
183
+ document.body.removeChild(elink);
184
+ resolve({
185
+ result: true,
186
+ msg: "下载成功",
187
+ });
188
+ }
189
+ else {
190
+ reject({
191
+ result: false,
192
+ msg: "浏览器不支持下载!请更换谷歌浏览器或者升级版本",
193
+ });
194
+ }
195
+ }
196
+ catch (err) {
197
+ reject({
198
+ result: false,
199
+ msg: "数据不是Bolb类型,无法导出!请检查传入的response",
200
+ });
201
+ }
202
+ });
203
+ }
150
204
  /**
151
205
  * 生成附件下载链接
152
206
  * @param fileId 附件id
@@ -250,4 +304,4 @@ function getBasicInfo(baseURL, token) {
250
304
  };
251
305
  }
252
306
 
253
- export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, previewFile };
307
+ export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile };
@@ -17,6 +17,7 @@ interface IOtherOptions {
17
17
  whiteWords?: string[];
18
18
  /** loading 发生变化触发事件 */
19
19
  loader?: (loading: boolean) => void;
20
+ startOptions?: any;
20
21
  }
21
22
  /**
22
23
  * 主应用初始化逻辑
@@ -9,7 +9,7 @@ import { registerMicroApps, setDefaultMountApp, start, runAfterFirstMounted, add
9
9
  */
10
10
  function initMainApp(microApps, defaultAppLink, otherOptions) {
11
11
  if (otherOptions === void 0) { otherOptions = {}; }
12
- var _a = otherOptions.whiteWords, whiteWords = _a === void 0 ? [] : _a, loader = otherOptions.loader;
12
+ var _a = otherOptions.whiteWords, whiteWords = _a === void 0 ? [] : _a, loader = otherOptions.loader, _b = otherOptions.startOptions, startOptions = _b === void 0 ? {} : _b;
13
13
  /**
14
14
  * Step2 注册子应用
15
15
  */
@@ -21,12 +21,10 @@ function initMainApp(microApps, defaultAppLink, otherOptions) {
21
21
  /**
22
22
  * Setp4 启动应用
23
23
  */
24
- start({
25
- excludeAssetFilter: function (urls) {
24
+ start(__assign({ excludeAssetFilter: function (urls) {
26
25
  // 指定部分特殊的动态加载的微应用资源(css/js) 不被 qiankun 劫持处理
27
26
  return whiteWords.some(function (w) { return urls.includes(w); });
28
- },
29
- });
27
+ } }, startOptions));
30
28
  runAfterFirstMounted(function () {
31
29
  console.log("第一个微应用加载成功!");
32
30
  });
@@ -38,17 +38,28 @@ interface IOptions extends AxiosRequestConfig {
38
38
  isErrorMessage?: boolean;
39
39
  }
40
40
  interface IOtherOptions {
41
+ /** token过期等 需要跳转到登录页 */
41
42
  jumpCallback?: (status: number) => void;
43
+ /** 提示方法 外部传入 */
42
44
  messageWarning?: (msg: string, duration: number, callback?: () => void) => void;
43
45
  modalConfirm?: (msg: string, callback?: () => void) => void;
46
+ /** token相关值 */
44
47
  TenantId?: string;
48
+ /** auth值 */
45
49
  Authorization?: string;
50
+ /** 超时时间 */
46
51
  timeout?: number;
52
+ /** 基础url */
47
53
  baseURL?: string;
54
+ /** 加密实例方法 */
48
55
  crypto?: Crypto;
56
+ /** 超时是否需要弹框 */
49
57
  isTimeoutConfirm?: boolean;
58
+ /** 超时弹框提示内容 */
50
59
  isTimeoutConfirmStr?: string;
60
+ /** 拦截器自定义 */
51
61
  interceptorsRequestHandle?: () => void;
62
+ /** 响应器自定义 */
52
63
  interceptorsResponseHandle?: () => void;
53
64
  }
54
65
 
package/dist/index.d.ts CHANGED
@@ -9,4 +9,4 @@ export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, g
9
9
  export { divide, exactRound, formatUnit, minus, plus, times } from './es/math.js';
10
10
  export { validatePassword } from './es/passwordValidate.js';
11
11
  export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
12
- export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, previewFile } from './es/file.js';
12
+ export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile } from './es/file.js';
package/dist/index.js CHANGED
@@ -9,4 +9,4 @@ export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, g
9
9
  export { divide, exactRound, formatUnit, minus, plus, times } from './es/math.js';
10
10
  export { validatePassword } from './es/passwordValidate.js';
11
11
  export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
12
- export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, previewFile } from './es/file.js';
12
+ export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile } from './es/file.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/file.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  getFileExtension,
9
9
  isImageExtension,
10
10
  } from "./common";
11
+ import { AxiosResponse } from "axios";
11
12
 
12
13
  /**
13
14
  * 附件下载方法
@@ -194,6 +195,58 @@ export function previewFile(
194
195
  }
195
196
  }
196
197
 
198
+ /**
199
+ * 导出一个文件流
200
+ * @param response 需要导出的文件流
201
+ * @param fileName 文件名称
202
+ */
203
+ export function exportBolb(response: AxiosResponse, fileName?: string) {
204
+ return new Promise((resolve, reject) => {
205
+ try {
206
+ const content = response.data;
207
+ const blob = new Blob([content], {
208
+ type: response.headers["content-type"],
209
+ });
210
+ // 判断是否支持下载
211
+ if ("download" in document.createElement("a")) {
212
+ // 非IE下载
213
+ const elink = document.createElement("a");
214
+ // 获取系统返回的名称
215
+ let copyName: string = response.headers["content-disposition"]
216
+ .split(";")[1]
217
+ .split("=")[1];
218
+ // 可以自定义名称
219
+ if (fileName) {
220
+ elink.download = fileName;
221
+ } else if (copyName) {
222
+ // Content-disposition
223
+ elink.download = decodeURIComponent(copyName);
224
+ }
225
+ elink.style.display = "none";
226
+ elink.href = URL.createObjectURL(blob);
227
+ document.body.appendChild(elink);
228
+ elink.click();
229
+ URL.revokeObjectURL(elink.href); // 释放URL 对象
230
+ document.body.removeChild(elink);
231
+ resolve({
232
+ result: true,
233
+ msg: "下载成功",
234
+ });
235
+ } else {
236
+ reject({
237
+ result: false,
238
+ msg: "浏览器不支持下载!请更换谷歌浏览器或者升级版本",
239
+ });
240
+ }
241
+ } catch (err) {
242
+ reject({
243
+ result: false,
244
+ msg: "数据不是Bolb类型,无法导出!请检查传入的response",
245
+ });
246
+ }
247
+ });
248
+ }
249
+
197
250
  /**
198
251
  * 生成附件下载链接
199
252
  * @param fileId 附件id
package/src/index.ts CHANGED
@@ -31,6 +31,7 @@ export {
31
31
  downloadFile,
32
32
  batchDownloadFiles,
33
33
  previewFile,
34
+ exportBolb,
34
35
  createDownloadLink,
35
36
  createOriginalLink,
36
37
  createThumbnailLink,
package/src/mainApp.ts CHANGED
@@ -43,6 +43,7 @@ interface IOtherOptions {
43
43
  whiteWords?: string[];
44
44
  /** loading 发生变化触发事件 */
45
45
  loader?: (loading: boolean) => void;
46
+ startOptions?: any;
46
47
  }
47
48
 
48
49
  /**
@@ -56,7 +57,7 @@ export function initMainApp(
56
57
  defaultAppLink: string,
57
58
  otherOptions: IOtherOptions = {}
58
59
  ) {
59
- const { whiteWords = [], loader } = otherOptions;
60
+ const { whiteWords = [], loader, startOptions = {} } = otherOptions;
60
61
 
61
62
  /**
62
63
  * Step2 注册子应用
@@ -76,6 +77,7 @@ export function initMainApp(
76
77
  // 指定部分特殊的动态加载的微应用资源(css/js) 不被 qiankun 劫持处理
77
78
  return whiteWords.some((w) => urls.includes(w));
78
79
  },
80
+ ...startOptions,
79
81
  });
80
82
 
81
83
  runAfterFirstMounted(() => {
package/src/request.ts CHANGED
@@ -311,31 +311,31 @@ export interface IOptions extends AxiosRequestConfig {
311
311
  }
312
312
 
313
313
  export interface IOtherOptions {
314
- // token过期等 需要跳转到登录页
314
+ /** token过期等 需要跳转到登录页 */
315
315
  jumpCallback?: (status: number) => void;
316
- // 提示方法 外部传入
316
+ /** 提示方法 外部传入 */
317
317
  messageWarning?: (
318
318
  msg: string,
319
319
  duration: number,
320
320
  callback?: () => void
321
321
  ) => void;
322
322
  modalConfirm?: (msg: string, callback?: () => void) => void;
323
- // token相关值
323
+ /** token相关值 */
324
324
  TenantId?: string;
325
- // auth值
325
+ /** auth值 */
326
326
  Authorization?: string;
327
- // 超时时间
327
+ /** 超时时间 */
328
328
  timeout?: number;
329
- // 基础url
329
+ /** 基础url */
330
330
  baseURL?: string;
331
- // 加密实例方法
331
+ /** 加密实例方法 */
332
332
  crypto?: Crypto;
333
- // 超时是否需要弹框
333
+ /** 超时是否需要弹框 */
334
334
  isTimeoutConfirm?: boolean;
335
- // 超时弹框提示内容
335
+ /** 超时弹框提示内容 */
336
336
  isTimeoutConfirmStr?: string;
337
- // 拦截器自定义
337
+ /** 拦截器自定义 */
338
338
  interceptorsRequestHandle?: () => void;
339
- // 响应器自定义
339
+ /** 响应器自定义 */
340
340
  interceptorsResponseHandle?: () => void;
341
341
  }