cosey 0.3.17 → 0.3.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosey",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "description": "基于 Vue3 + vite 的后台管理系统框架",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -18,6 +18,7 @@
18
18
  "@floating-ui/dom": "^1.6.13",
19
19
  "@gunny/persist": "^1.0.2",
20
20
  "@iconify/types": "^2.0.0",
21
+ "@types/mime-types": "^3.0.1",
21
22
  "@types/nprogress": "^0.2.3",
22
23
  "@types/stylis": "^4.2.7",
23
24
  "@vue/shared": "^3.5.13",
@@ -32,6 +33,7 @@
32
33
  "jszip": "^3.10.1",
33
34
  "katex": "^0.16.22",
34
35
  "lodash-es": "^4.17.21",
36
+ "mime-types": "^3.0.1",
35
37
  "nprogress": "^0.2.0",
36
38
  "pinia": "^3.0.2",
37
39
  "quill": "^2.0.3",
@@ -63,6 +65,7 @@
63
65
  "jszip": "^3.10.1",
64
66
  "katex": "^0.16.22",
65
67
  "lodash-es": "^4.17.21",
68
+ "mime-types": "^3.0.1",
66
69
  "nprogress": "^0.2.0",
67
70
  "pinia": "^3.0.2",
68
71
  "quill": "^2.0.3",
package/utils/file.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type AxiosResponse } from 'axios';
1
2
  export interface ChooseFilesOptions {
2
3
  multiple?: boolean;
3
4
  accept?: string;
@@ -13,3 +14,9 @@ export declare function chooseFiles(options?: ChooseFilesOptions): Promise<File[
13
14
  export declare function getFileType(urlOrFile: string | File): string;
14
15
  export declare function readAsDataURL(file: File): Promise<string>;
15
16
  export declare function readAsArrayBuffer(file: File): Promise<ArrayBuffer>;
17
+ /**
18
+ * 下载附件
19
+ */
20
+ export declare function downloadAttachment(response: AxiosResponse, options?: {
21
+ filename?: string;
22
+ }): void;
package/utils/file.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isString } from './is.js';
2
+ import mime from 'mime-types';
2
3
 
3
4
  let input;
4
5
  function chooseFiles(options = {}) {
@@ -66,5 +67,26 @@ function readAsArrayBuffer(file) {
66
67
  reader.readAsArrayBuffer(file);
67
68
  });
68
69
  }
70
+ function downloadAttachment(response, options) {
71
+ let { filename } = options || {};
72
+ const type = response.headers["content-type"];
73
+ if (!filename) {
74
+ const contentDisposition = response.headers["content-disposition"];
75
+ if (contentDisposition) {
76
+ filename = contentDisposition.split("filename=")[1].trim().replace(/"/g, "");
77
+ }
78
+ }
79
+ if (!filename) {
80
+ filename = `download.${mime.extension(type)}`;
81
+ }
82
+ const blob = new Blob([response.data], { type });
83
+ const link = document.createElement("a");
84
+ link.href = window.URL.createObjectURL(blob);
85
+ link.download = filename;
86
+ link.click();
87
+ setTimeout(() => {
88
+ window.URL.revokeObjectURL(link.href);
89
+ }, 100);
90
+ }
69
91
 
70
- export { chooseFiles, getFileType, readAsArrayBuffer, readAsDataURL };
92
+ export { chooseFiles, downloadAttachment, getFileType, readAsArrayBuffer, readAsDataURL };
package/utils/index.js CHANGED
@@ -5,7 +5,7 @@ export { getLabelByValue, getTreeLabelByValue } from './collection.js';
5
5
  export { addPxUnit, cssObjectToString, getContextBoxWidth, getDir, getStyle, setStyle } from './css.js';
6
6
  export { DATE_FORMAT, DATE_TIME_FORMAT, MONTH_FORMAT, TIME_FORMAT, YEAR_FORMAT, formatAsBasicDateTime, formatAsDate, formatAsDateTime, getDayjs } from './date.js';
7
7
  export { exportExcel, flatColumns } from './excel/index.js';
8
- export { chooseFiles, getFileType, readAsArrayBuffer, readAsDataURL } from './file.js';
8
+ export { chooseFiles, downloadAttachment, getFileType, readAsArrayBuffer, readAsDataURL } from './file.js';
9
9
  export { isBoolean, isEmpty, isFunction, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isUndefined } from './is.js';
10
10
  export { minmax } from './number.js';
11
11
  export { deepAssign, initObject, omitObject, omitUndefined, uniformAssign } from './object.js';