zmdms-utils 0.0.75 → 0.0.76
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/_virtual/_commonjsHelpers.js +3 -0
- package/dist/es/_virtual/_tslib.js +87 -0
- package/dist/es/_virtual/decimal.js +7 -0
- package/dist/es/_virtual/parseTimeTest.js +3 -0
- package/dist/es/_virtual/test.js +3 -0
- package/dist/es/auth.d.ts +9 -0
- package/dist/es/auth.js +49 -0
- package/dist/es/baseUrl.d.ts +23 -0
- package/dist/es/baseUrl.js +50 -0
- package/dist/es/canvas.d.ts +6 -0
- package/dist/es/canvas.js +14 -0
- package/dist/es/common.d.ts +81 -0
- package/dist/es/common.js +304 -0
- package/dist/es/constants.d.ts +20 -0
- package/dist/es/constants.js +33 -0
- package/dist/es/crypto.d.ts +51 -0
- package/dist/es/crypto.js +97 -0
- package/dist/es/file.d.ts +127 -0
- package/dist/es/file.js +373 -0
- package/dist/es/htmlToPdf.d.ts +44 -0
- package/dist/es/htmlToPdf.js +84 -0
- package/dist/es/locales/i18n.d.ts +15 -0
- package/dist/es/locales/t-in-non-react.d.ts +17 -0
- package/dist/es/locales/t-options.d.ts +7 -0
- package/dist/es/locales/use-translation.d.ts +42 -0
- package/dist/es/mainApp.d.ts +36 -0
- package/dist/es/mainApp.js +44 -0
- package/dist/es/math.d.ts +29 -0
- package/dist/es/math.js +147 -0
- package/dist/es/microAppCreator.d.ts +46 -0
- package/dist/es/microAppCreator.js +89 -0
- package/dist/es/node_modules/decimal.js/decimal.js +4896 -0
- package/dist/es/node_modules/decimal.js/decimal2.js +4930 -0
- package/dist/es/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js +5 -0
- package/dist/es/node_modules/i18next/dist/esm/i18next.js +2242 -0
- package/dist/es/node_modules/js-base64/base64.js +273 -0
- package/dist/es/node_modules/jwt-decode/build/jwt-decode.esm.js +3 -0
- package/dist/es/node_modules/mitt/dist/mitt.js +3 -0
- package/dist/es/node_modules/pinyin-pro/dist/index.js +12627 -0
- package/dist/es/node_modules/react-i18next/dist/es/Trans.js +47 -0
- package/dist/es/node_modules/react-i18next/dist/es/TransWithoutContext.js +312 -0
- package/dist/es/node_modules/react-i18next/dist/es/context.js +18 -0
- package/dist/es/node_modules/react-i18next/dist/es/defaults.js +21 -0
- package/dist/es/node_modules/react-i18next/dist/es/i18nInstance.js +7 -0
- package/dist/es/node_modules/react-i18next/dist/es/initReactI18next.js +12 -0
- package/dist/es/node_modules/react-i18next/dist/es/unescape.js +27 -0
- package/dist/es/node_modules/react-i18next/dist/es/useTranslation.js +112 -0
- package/dist/es/node_modules/react-i18next/dist/es/utils.js +63 -0
- package/dist/es/node_modules/void-elements/index.js +23 -0
- package/dist/es/parseTime.d.ts +29 -0
- package/dist/es/parseTime.js +189 -0
- package/dist/es/parseTimeTest.js +2 -0
- package/dist/es/passwordValidate.d.ts +9 -0
- package/dist/es/passwordValidate.js +169 -0
- package/dist/es/pdf.d.ts +49 -0
- package/dist/es/pdf.js +176 -0
- package/dist/es/pinyin.js +1 -0
- package/dist/es/print.d.ts +23 -0
- package/dist/es/print.js +43 -0
- package/dist/es/qiankunUtils.d.ts +13 -0
- package/dist/es/qiankunUtils.js +32 -0
- package/dist/es/request.d.ts +87 -0
- package/dist/es/request.js +308 -0
- package/dist/es/src/locales/i18n.js +16 -0
- package/dist/es/src/locales/t-in-non-react.js +54 -0
- package/dist/es/src/locales/t-options.js +20 -0
- package/dist/es/src/locales/use-translation.js +60 -0
- package/dist/es/src/parseTimeTest.js +288 -0
- package/dist/es/src/test.js +245 -0
- package/dist/es/test.js +2 -0
- package/dist/es/validate.d.ts +26 -0
- package/dist/es/validate.js +47 -0
- package/dist/es/water.d.ts +53 -0
- package/dist/es/water.js +88 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/package.json +1 -1
- package/src/math.ts +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// 薪酬中心-app name
|
|
2
|
+
var SALARY_CENTER_APPNAME = "cicohr-salary";
|
|
3
|
+
// 人事中心-app name
|
|
4
|
+
var PERSONNEL_CENTER_APPNAME = "cicohr-personnel";
|
|
5
|
+
// 发布订阅的常量 parent call children
|
|
6
|
+
/**
|
|
7
|
+
* 子应用 通知 父应用
|
|
8
|
+
*/
|
|
9
|
+
var EMITTER_CCP_KEY = "emitter-ccp-key";
|
|
10
|
+
/**
|
|
11
|
+
* 父应用 通知 子应用订阅
|
|
12
|
+
*/
|
|
13
|
+
var EMITTER_PCC_KEY = "emitter-pcc-key";
|
|
14
|
+
var EMITTER_TYPE = {
|
|
15
|
+
delTab: "delTab",
|
|
16
|
+
addTab: "addTab",
|
|
17
|
+
delTabs: "delTabs",
|
|
18
|
+
routes: "routes",
|
|
19
|
+
treeSearchWhitePath: "treeSearchWhitePath",
|
|
20
|
+
treeSearchSet: "treeSearchSet", // 父应用传递搜索树的值
|
|
21
|
+
};
|
|
22
|
+
// token key 值
|
|
23
|
+
// export const TOKEN_KEY = "Zmdms-Auth";
|
|
24
|
+
var TOKEN_KEY = window.__TOKEN_KEY__ || "Cicoms-Auth";
|
|
25
|
+
// 基础前缀
|
|
26
|
+
// export const BASIC_KEY = "zmdms";
|
|
27
|
+
var BASIC_KEY = window.__BASIC_KEY__ || "cicoms";
|
|
28
|
+
// 附件相关服务
|
|
29
|
+
var FILE_SERVICE = window.__FILE_SERVICE__ || "cicoms";
|
|
30
|
+
// 默认的附件预览服务地址
|
|
31
|
+
var FILE_PRVIEW_SERVICE_URL = window.__FILE_PRVIEW_SERVICE_URL__ || "";
|
|
32
|
+
|
|
33
|
+
export { BASIC_KEY, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, FILE_PRVIEW_SERVICE_URL, FILE_SERVICE, PERSONNEL_CENTER_APPNAME, SALARY_CENTER_APPNAME, TOKEN_KEY };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对称加密和hash
|
|
3
|
+
*/
|
|
4
|
+
declare class Crypto {
|
|
5
|
+
private aesKey;
|
|
6
|
+
private desKey;
|
|
7
|
+
constructor(aesKey: string, desKey: string);
|
|
8
|
+
/**
|
|
9
|
+
* aes 加密方法
|
|
10
|
+
* @param data
|
|
11
|
+
* @returns {*}
|
|
12
|
+
*/
|
|
13
|
+
encrypt(data: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* aes 解密方法
|
|
16
|
+
* @param data
|
|
17
|
+
* @returns {*}
|
|
18
|
+
*/
|
|
19
|
+
decrypt(data: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* des 加密方法
|
|
22
|
+
* @param data
|
|
23
|
+
* @returns {*}
|
|
24
|
+
*/
|
|
25
|
+
encrypt_des(data: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* des 解密方法
|
|
28
|
+
* @param data
|
|
29
|
+
* @returns {*}
|
|
30
|
+
*/
|
|
31
|
+
decrypt_des(data: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
|
|
34
|
+
*/
|
|
35
|
+
private encryptAES;
|
|
36
|
+
/**
|
|
37
|
+
* aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
|
|
38
|
+
*/
|
|
39
|
+
private decryptAES;
|
|
40
|
+
/**
|
|
41
|
+
* des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
|
|
42
|
+
*/
|
|
43
|
+
private encryptDES;
|
|
44
|
+
/**
|
|
45
|
+
* des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
|
|
46
|
+
*/
|
|
47
|
+
private decryptDES;
|
|
48
|
+
}
|
|
49
|
+
declare const md5: (str: string) => string;
|
|
50
|
+
|
|
51
|
+
export { Crypto, md5 };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import CryptoJS from 'crypto-js';
|
|
2
|
+
export { Base64 } from './node_modules/js-base64/base64.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 对称加密和hash
|
|
6
|
+
*/
|
|
7
|
+
var Crypto = /** @class */ (function () {
|
|
8
|
+
function Crypto(aesKey, desKey) {
|
|
9
|
+
this.aesKey = aesKey;
|
|
10
|
+
this.desKey = desKey;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* aes 加密方法
|
|
14
|
+
* @param data
|
|
15
|
+
* @returns {*}
|
|
16
|
+
*/
|
|
17
|
+
Crypto.prototype.encrypt = function (data) {
|
|
18
|
+
return this.encryptAES(data, this.aesKey);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* aes 解密方法
|
|
22
|
+
* @param data
|
|
23
|
+
* @returns {*}
|
|
24
|
+
*/
|
|
25
|
+
Crypto.prototype.decrypt = function (data) {
|
|
26
|
+
return this.decryptAES(data, this.aesKey);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* des 加密方法
|
|
30
|
+
* @param data
|
|
31
|
+
* @returns {*}
|
|
32
|
+
*/
|
|
33
|
+
Crypto.prototype.encrypt_des = function (data) {
|
|
34
|
+
return this.encryptDES(data, this.desKey);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* des 解密方法
|
|
38
|
+
* @param data
|
|
39
|
+
* @returns {*}
|
|
40
|
+
*/
|
|
41
|
+
Crypto.prototype.decrypt_des = function (data) {
|
|
42
|
+
return this.decryptDES(data, this.desKey);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
|
|
46
|
+
*/
|
|
47
|
+
Crypto.prototype.encryptAES = function (data, key) {
|
|
48
|
+
var dataBytes = CryptoJS.enc.Utf8.parse(data);
|
|
49
|
+
var keyBytes = CryptoJS.enc.Utf8.parse(key);
|
|
50
|
+
var encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
|
|
51
|
+
iv: keyBytes,
|
|
52
|
+
mode: CryptoJS.mode.CBC,
|
|
53
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
54
|
+
});
|
|
55
|
+
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
|
|
59
|
+
*/
|
|
60
|
+
Crypto.prototype.decryptAES = function (data, key) {
|
|
61
|
+
var keyBytes = CryptoJS.enc.Utf8.parse(key);
|
|
62
|
+
var decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
|
|
63
|
+
iv: keyBytes,
|
|
64
|
+
mode: CryptoJS.mode.CBC,
|
|
65
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
66
|
+
});
|
|
67
|
+
return CryptoJS.enc.Utf8.stringify(decrypted);
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
|
|
71
|
+
*/
|
|
72
|
+
Crypto.prototype.encryptDES = function (data, key) {
|
|
73
|
+
var keyHex = CryptoJS.enc.Utf8.parse(key);
|
|
74
|
+
var encrypted = CryptoJS.DES.encrypt(data, keyHex, {
|
|
75
|
+
mode: CryptoJS.mode.ECB,
|
|
76
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
77
|
+
});
|
|
78
|
+
return encrypted.toString();
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
|
|
82
|
+
*/
|
|
83
|
+
Crypto.prototype.decryptDES = function (data, key) {
|
|
84
|
+
var keyHex = CryptoJS.enc.Utf8.parse(key);
|
|
85
|
+
var decrypted = CryptoJS.DES.decrypt({
|
|
86
|
+
ciphertext: CryptoJS.enc.Base64.parse(data),
|
|
87
|
+
}, keyHex, {
|
|
88
|
+
mode: CryptoJS.mode.ECB,
|
|
89
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
90
|
+
});
|
|
91
|
+
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
92
|
+
};
|
|
93
|
+
return Crypto;
|
|
94
|
+
}());
|
|
95
|
+
var md5 = function (str) { return CryptoJS.MD5(str).toString().toLowerCase(); };
|
|
96
|
+
|
|
97
|
+
export { Crypto, md5 };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 附件下载方法
|
|
5
|
+
* @param fileId 附件id
|
|
6
|
+
* @param fileName 附件名称
|
|
7
|
+
* @param options
|
|
8
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 必传
|
|
9
|
+
* @param options.authToken {string} token 非必传
|
|
10
|
+
* @param options.waterMark {boolean | string} 是否添加水印 是否指定水印名称 非必传
|
|
11
|
+
* @param options.open boolean 是否不需要登录信息
|
|
12
|
+
*/
|
|
13
|
+
declare function downloadFile(fileId: string, fileName: string, options: IDownloadOptions): Promise<unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* 附件批量下载方法
|
|
16
|
+
* @param fileList 附件列表
|
|
17
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 必传
|
|
18
|
+
* @param options.authToken {string} token 非必传
|
|
19
|
+
* @param options.waterMark {boolean | string} 是否添加水印 是否指定水印名称 非必传
|
|
20
|
+
* @param options.zipName string zip名字
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
declare function batchDownloadFiles(fileList: {
|
|
24
|
+
attachId: string;
|
|
25
|
+
attachName: string;
|
|
26
|
+
[props: string]: string;
|
|
27
|
+
}[], options: IBatchDownloadOptions): Promise<unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* 附件预览。如果传入的附件是图片,那么实现批量预览
|
|
30
|
+
* 预览使用文件服务器baseURL
|
|
31
|
+
* @param fileId 附件id
|
|
32
|
+
* @param fileName 附件名称
|
|
33
|
+
* @param options
|
|
34
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 必传(文件服务器baseURL)
|
|
35
|
+
* @param options.authToken {string} token 非必传
|
|
36
|
+
* @param options.fileList { attachId: string, attachName: string ... }[] 附件列表。批量预览时有用
|
|
37
|
+
*/
|
|
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>;
|
|
45
|
+
/**
|
|
46
|
+
* 生成附件下载链接
|
|
47
|
+
* @param fileId 附件id
|
|
48
|
+
* @param options
|
|
49
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
50
|
+
* @param options.authToken {string} token 非必传
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
declare function createDownloadLink(fileId: string, options?: IDownloadLinkOptions): string;
|
|
54
|
+
/**
|
|
55
|
+
* 生成原始图片路径
|
|
56
|
+
* 预览使用文件服务器baseURL
|
|
57
|
+
* @param fileId 附件id
|
|
58
|
+
* @param fileName 附件名称
|
|
59
|
+
* @param options
|
|
60
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传(文件服务器baseURL)
|
|
61
|
+
* @param options.authToken {string} token 非必传
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
declare function createOriginalLink(fileId: string, fileName: string, options?: IOriginLinkOptions): string;
|
|
65
|
+
/**
|
|
66
|
+
* 生成缩略图路径
|
|
67
|
+
* @param fileId 附件id
|
|
68
|
+
* @param fileName 附件名称
|
|
69
|
+
* @param options
|
|
70
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
71
|
+
* @param options.authToken {string} token 非必传
|
|
72
|
+
* @param options.scale {number} 缩略比
|
|
73
|
+
* @returns
|
|
74
|
+
* createThumbnailLink('1', 'z', { API_BASEURL: 1 })
|
|
75
|
+
*/
|
|
76
|
+
declare function createThumbnailLink(fileId: string, fileName: string, options: IThumbnailLinkOptions): string;
|
|
77
|
+
/**
|
|
78
|
+
* 生成图片上传地址
|
|
79
|
+
* @param options
|
|
80
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
81
|
+
* @param options.authToken {string} token 非必传
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
declare function createUploadFileLink(options: IOptions): string;
|
|
85
|
+
/**
|
|
86
|
+
* 生成图片删除地址
|
|
87
|
+
* @param options
|
|
88
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
89
|
+
* @param options.authToken {string} token 非必传
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
declare function createDeleteFileLink(options: IOptions): string;
|
|
93
|
+
interface IOptions {
|
|
94
|
+
API_BASEURL: string;
|
|
95
|
+
authToken?: string;
|
|
96
|
+
}
|
|
97
|
+
interface IDownloadOptions extends IOptions {
|
|
98
|
+
/** 是否添加水印 */
|
|
99
|
+
waterMark?: boolean | string;
|
|
100
|
+
/** 是否开发不需要登录信息 */
|
|
101
|
+
open?: boolean;
|
|
102
|
+
}
|
|
103
|
+
interface IBatchDownloadOptions extends IOptions {
|
|
104
|
+
zipName: string;
|
|
105
|
+
/** 是否添加水印 */
|
|
106
|
+
waterMark?: boolean | string;
|
|
107
|
+
}
|
|
108
|
+
interface IDownloadLinkOptions extends Partial<IOptions> {
|
|
109
|
+
/** 不需要登录信息的附件下载链接 */
|
|
110
|
+
open?: boolean;
|
|
111
|
+
}
|
|
112
|
+
interface IPreviewOptions extends IOptions {
|
|
113
|
+
/** 附件列表 */
|
|
114
|
+
fileList?: {
|
|
115
|
+
attachId: string;
|
|
116
|
+
attachName: string;
|
|
117
|
+
[props: string]: string;
|
|
118
|
+
}[];
|
|
119
|
+
}
|
|
120
|
+
interface IOriginLinkOptions extends Partial<IOptions> {
|
|
121
|
+
}
|
|
122
|
+
interface IThumbnailLinkOptions extends Partial<IOptions> {
|
|
123
|
+
/** 缩放比例 */
|
|
124
|
+
scale?: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile };
|
package/dist/es/file.js
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { getToken } from './auth.js';
|
|
2
|
+
import { dangerouslyXss, specialString, getFileExtension, isImageExtension } from './common.js';
|
|
3
|
+
import { BASIC_KEY, TOKEN_KEY, FILE_SERVICE, FILE_PRVIEW_SERVICE_URL } from './constants.js';
|
|
4
|
+
import { Crypto } from './crypto.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 附件相关接口
|
|
8
|
+
*/
|
|
9
|
+
// 是否是中拓的附件服务
|
|
10
|
+
var isZmdmsFileService = FILE_SERVICE === "zmdms";
|
|
11
|
+
/**
|
|
12
|
+
* 附件下载方法
|
|
13
|
+
* @param fileId 附件id
|
|
14
|
+
* @param fileName 附件名称
|
|
15
|
+
* @param options
|
|
16
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 必传
|
|
17
|
+
* @param options.authToken {string} token 非必传
|
|
18
|
+
* @param options.waterMark {boolean | string} 是否添加水印 是否指定水印名称 非必传
|
|
19
|
+
* @param options.open boolean 是否不需要登录信息
|
|
20
|
+
*/
|
|
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;
|
|
23
|
+
if (isZmdmsFileService) {
|
|
24
|
+
fileId = encodeFileId(fileId, 2);
|
|
25
|
+
}
|
|
26
|
+
return new Promise(function (resolve, reject) {
|
|
27
|
+
var xhr = new XMLHttpRequest();
|
|
28
|
+
// 获取请求基础数据
|
|
29
|
+
var _a = getBasicInfo(API_BASEURL, authToken), token = _a.token, apiBaseURL = _a.apiBaseURL;
|
|
30
|
+
if (open) {
|
|
31
|
+
xhr.open("GET", "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/public/download-file/").concat(fileId), true);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
xhr.open("GET", "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/download-file/").concat(fileId, "?").concat(TOKEN_KEY, "=").concat(token, "&addWaterMark=").concat(waterMark), true);
|
|
35
|
+
}
|
|
36
|
+
xhr.responseType = "blob";
|
|
37
|
+
xhr.onload = function () {
|
|
38
|
+
if (xhr.status === 200 || xhr.status === 201) {
|
|
39
|
+
var link = document.createElement("a");
|
|
40
|
+
var body = document.querySelector("body");
|
|
41
|
+
link.href = window.URL.createObjectURL(xhr.response);
|
|
42
|
+
link.download = dangerouslyXss(fileName);
|
|
43
|
+
// fix Firefox
|
|
44
|
+
link.style.display = "none";
|
|
45
|
+
body.appendChild(link);
|
|
46
|
+
link.click();
|
|
47
|
+
body.removeChild(link);
|
|
48
|
+
window.URL.revokeObjectURL(link.href);
|
|
49
|
+
resolve({ msg: "文件下载成功!" });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
reject(xhr.response);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
xhr.onerror = function (err) {
|
|
56
|
+
reject(err);
|
|
57
|
+
};
|
|
58
|
+
xhr.send();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 附件批量下载方法
|
|
63
|
+
* @param fileList 附件列表
|
|
64
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 必传
|
|
65
|
+
* @param options.authToken {string} token 非必传
|
|
66
|
+
* @param options.waterMark {boolean | string} 是否添加水印 是否指定水印名称 非必传
|
|
67
|
+
* @param options.zipName string zip名字
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
function batchDownloadFiles(fileList, options) {
|
|
71
|
+
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, zipName = options.zipName, _a = options.waterMark, waterMark = _a === void 0 ? true : _a;
|
|
72
|
+
return new Promise(function (resolve, reject) {
|
|
73
|
+
var _a, _b, _c, _d, _e, _f;
|
|
74
|
+
var xhr = new XMLHttpRequest();
|
|
75
|
+
// 获取请求基础数据
|
|
76
|
+
var _g = getBasicInfo(API_BASEURL, authToken), token = _g.token, apiBaseURL = _g.apiBaseURL;
|
|
77
|
+
xhr.open("POST", "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-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
|
+
resolve({ msg: "文件下载成功!" });
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
reject(xhr.response);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
xhr.onerror = function (err) {
|
|
98
|
+
reject(err);
|
|
99
|
+
};
|
|
100
|
+
xhr.setRequestHeader(TOKEN_KEY, token || "");
|
|
101
|
+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
102
|
+
var fileIds = (_c = (_b = (_a = fileList === null || fileList === void 0 ? void 0 : fileList.map) === null || _a === void 0 ? void 0 : _a.call(fileList, function (item) { return item.attachId; })) === null || _b === void 0 ? void 0 : _b.join) === null || _c === void 0 ? void 0 : _c.call(_b, ",");
|
|
103
|
+
var fileNames = (_f = (_e = (_d = fileList === null || fileList === void 0 ? void 0 : fileList.map) === null || _d === void 0 ? void 0 : _d.call(fileList, function (item) { return item.attachName; })) === null || _e === void 0 ? void 0 : _e.join) === null || _f === void 0 ? void 0 : _f.call(_e, ",");
|
|
104
|
+
if (isZmdmsFileService) {
|
|
105
|
+
fileIds = encodeFileId(fileIds, 2);
|
|
106
|
+
}
|
|
107
|
+
xhr.send("attachIds=".concat(fileIds, "&fileNames=").concat(fileNames, "&zipName=").concat(zipName, "&addWaterMark=").concat(waterMark));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 附件预览。如果传入的附件是图片,那么实现批量预览
|
|
112
|
+
* 预览使用文件服务器baseURL
|
|
113
|
+
* @param fileId 附件id
|
|
114
|
+
* @param fileName 附件名称
|
|
115
|
+
* @param options
|
|
116
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 必传(文件服务器baseURL)
|
|
117
|
+
* @param options.authToken {string} token 非必传
|
|
118
|
+
* @param options.fileList { attachId: string, attachName: string ... }[] 附件列表。批量预览时有用
|
|
119
|
+
*/
|
|
120
|
+
function previewFile(fileId, fileName, options) {
|
|
121
|
+
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, _a = options.fileList, fileList = _a === void 0 ? [] : _a;
|
|
122
|
+
// 获取请求基础数据
|
|
123
|
+
var _b = getBasicInfo(FILE_PRVIEW_SERVICE_URL || API_BASEURL, authToken), token = _b.token, apiBaseURL = _b.apiBaseURL;
|
|
124
|
+
// 处理附件名中的一些特殊字符
|
|
125
|
+
var previewFileName = dangerouslyXss(fileName);
|
|
126
|
+
try {
|
|
127
|
+
previewFileName = specialString(previewFileName);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
console.log(err);
|
|
131
|
+
}
|
|
132
|
+
// 获取文件后缀
|
|
133
|
+
var _c = getFileExtension(previewFileName), filePreName = _c[0], fileExtension = _c[1];
|
|
134
|
+
// 由于预览使用了文件名地址作为iframe的路径
|
|
135
|
+
// 如果文件名没变,文件内容改变。这样就会导致再次预览时 内容不会更新
|
|
136
|
+
// 所以将文件名 与 文件id组合来生成不同的文件名
|
|
137
|
+
previewFileName = "".concat(filePreName, "-").concat(fileId, ".").concat(fileExtension);
|
|
138
|
+
if (!isZmdmsFileService) {
|
|
139
|
+
// 2023-12-30 修改成数字中心预览
|
|
140
|
+
window.open("".concat(apiBaseURL, "/api/cicoms-resource/attach/filePreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// 如果是图片 走批量预览接口
|
|
144
|
+
var isImage = isImageExtension(fileExtension);
|
|
145
|
+
if (isImage) {
|
|
146
|
+
var imgFiles = fileList.filter(function (item) {
|
|
147
|
+
var attachName = item.attachName, attachId = item.attachId;
|
|
148
|
+
var _a = getFileExtension(attachName), fileExtension = _a[1];
|
|
149
|
+
if (isImageExtension(fileExtension) && attachId !== fileId) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
});
|
|
154
|
+
var attachIds = imgFiles.map(function (item) { return item.attachId; }).join(",");
|
|
155
|
+
var fileIds = attachIds ? "".concat(fileId, ",").concat(attachIds) : fileId;
|
|
156
|
+
if (isZmdmsFileService) {
|
|
157
|
+
fileIds = encodeFileId(fileIds, 1);
|
|
158
|
+
}
|
|
159
|
+
// 批量图片预览
|
|
160
|
+
window.open("".concat(apiBaseURL, "/picturesAttchPreview?attachIds=").concat(fileIds, "&").concat(TOKEN_KEY, "=").concat(token) +
|
|
161
|
+
(fileName ? "&titleName=".concat(encodeURIComponent(previewFileName)) : ""));
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
if (isZmdmsFileService) {
|
|
165
|
+
fileId = encodeFileId(fileId, 1);
|
|
166
|
+
}
|
|
167
|
+
// 普通预览
|
|
168
|
+
window.open("".concat(apiBaseURL, "/attchPreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token, "&officePreviewType=pdf") +
|
|
169
|
+
(fileName ? "&titleName=".concat(encodeURIComponent(previewFileName)) : ""));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 导出一个文件流
|
|
174
|
+
* @param response 需要导出的文件流
|
|
175
|
+
* @param fileName 文件名称 可以传后缀名,传后缀名会直接用这个后缀名 如果不传的或者与文件类型的后缀名不同 会取接口中提供的后缀名
|
|
176
|
+
*/
|
|
177
|
+
function exportBolb(response, fileName) {
|
|
178
|
+
return new Promise(function (resolve, reject) {
|
|
179
|
+
try {
|
|
180
|
+
var content = response.data;
|
|
181
|
+
var blob = new Blob([content], {
|
|
182
|
+
type: response.headers["content-type"],
|
|
183
|
+
});
|
|
184
|
+
// 判断是否支持下载
|
|
185
|
+
if ("download" in document.createElement("a")) {
|
|
186
|
+
// 非IE下载
|
|
187
|
+
var elink = document.createElement("a");
|
|
188
|
+
// 获取系统返回的名称
|
|
189
|
+
var copyName = response.headers["content-disposition"]
|
|
190
|
+
.split(";")[1]
|
|
191
|
+
.split("=")[1];
|
|
192
|
+
// 去除前后引号
|
|
193
|
+
if (copyName.startsWith('"') || copyName.startsWith("'")) {
|
|
194
|
+
copyName = copyName.slice(1);
|
|
195
|
+
}
|
|
196
|
+
if (copyName.endsWith('"') || copyName.endsWith("'")) {
|
|
197
|
+
copyName = copyName.slice(0, -1);
|
|
198
|
+
}
|
|
199
|
+
// 可以自定义名称
|
|
200
|
+
if (fileName) {
|
|
201
|
+
var _a = getFileExtension(fileName), name_1 = _a[0], extension = _a[1];
|
|
202
|
+
if (copyName) {
|
|
203
|
+
var _b = getFileExtension(decodeURIComponent(copyName)), copyExtension = _b[1];
|
|
204
|
+
elink.download =
|
|
205
|
+
extension === copyExtension
|
|
206
|
+
? fileName
|
|
207
|
+
: "".concat(name_1, ".").concat(copyExtension);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
elink.download = fileName;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (copyName) {
|
|
214
|
+
// Content-disposition
|
|
215
|
+
elink.download = decodeURIComponent(copyName);
|
|
216
|
+
}
|
|
217
|
+
elink.style.display = "none";
|
|
218
|
+
elink.href = URL.createObjectURL(blob);
|
|
219
|
+
document.body.appendChild(elink);
|
|
220
|
+
elink.click();
|
|
221
|
+
URL.revokeObjectURL(elink.href); // 释放URL 对象
|
|
222
|
+
document.body.removeChild(elink);
|
|
223
|
+
resolve({
|
|
224
|
+
result: true,
|
|
225
|
+
msg: "下载成功",
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
reject({
|
|
230
|
+
result: false,
|
|
231
|
+
msg: "浏览器不支持下载!请更换谷歌浏览器或者升级版本",
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
reject({
|
|
237
|
+
result: false,
|
|
238
|
+
msg: "数据不是Bolb类型,无法导出!请检查传入的response",
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 生成附件下载链接
|
|
245
|
+
* @param fileId 附件id
|
|
246
|
+
* @param options
|
|
247
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
248
|
+
* @param options.authToken {string} token 非必传
|
|
249
|
+
* @returns
|
|
250
|
+
*/
|
|
251
|
+
function createDownloadLink(fileId, options) {
|
|
252
|
+
if (options === void 0) { options = {}; }
|
|
253
|
+
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, open = options.open;
|
|
254
|
+
var _a = getBasicInfo(API_BASEURL || "", authToken), token = _a.token, apiBaseURL = _a.apiBaseURL;
|
|
255
|
+
if (isZmdmsFileService) {
|
|
256
|
+
fileId = encodeFileId(fileId, 2);
|
|
257
|
+
}
|
|
258
|
+
if (open) {
|
|
259
|
+
return "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/public/download-file/").concat(fileId);
|
|
260
|
+
}
|
|
261
|
+
return "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/download-file/").concat(fileId, "?").concat(TOKEN_KEY, "=").concat(token);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 生成原始图片路径
|
|
265
|
+
* 预览使用文件服务器baseURL
|
|
266
|
+
* @param fileId 附件id
|
|
267
|
+
* @param fileName 附件名称
|
|
268
|
+
* @param options
|
|
269
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传(文件服务器baseURL)
|
|
270
|
+
* @param options.authToken {string} token 非必传
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
function createOriginalLink(fileId, fileName, options) {
|
|
274
|
+
if (options === void 0) { options = {}; }
|
|
275
|
+
var API_BASEURL = options.API_BASEURL, authToken = options.authToken;
|
|
276
|
+
var _a = getBasicInfo(FILE_PRVIEW_SERVICE_URL || API_BASEURL || "", authToken), token = _a.token, apiBaseURL = _a.apiBaseURL;
|
|
277
|
+
// 处理附件名中的一些特殊字符
|
|
278
|
+
var previewFileName = dangerouslyXss(fileName);
|
|
279
|
+
try {
|
|
280
|
+
previewFileName = specialString(previewFileName);
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
console.log(err);
|
|
284
|
+
}
|
|
285
|
+
// 获取文件后缀
|
|
286
|
+
var _b = getFileExtension(previewFileName), filePreName = _b[0], fileExtension = _b[1];
|
|
287
|
+
// 由于预览使用了文件名地址作为iframe的路径
|
|
288
|
+
// 如果文件名没变,文件内容改变。这样就会导致再次预览时 内容不会更新
|
|
289
|
+
// 所以将文件名 与 文件id组合来生成不同的文件名
|
|
290
|
+
previewFileName = "".concat(filePreName, "-").concat(fileId, ".").concat(fileExtension);
|
|
291
|
+
// 2023-12-30 替换成数字中心的 预览接口
|
|
292
|
+
if (!isZmdmsFileService) {
|
|
293
|
+
return "".concat(apiBaseURL, "/api/cicoms-resource/attach/filePreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token);
|
|
294
|
+
}
|
|
295
|
+
if (isZmdmsFileService) {
|
|
296
|
+
fileId = encodeFileId(fileId, 2);
|
|
297
|
+
}
|
|
298
|
+
return ("".concat(apiBaseURL, "/attchPreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token, "&officePreviewType=pdf") +
|
|
299
|
+
(fileName ? "&titleName=".concat(encodeURIComponent(previewFileName)) : ""));
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* 生成缩略图路径
|
|
303
|
+
* @param fileId 附件id
|
|
304
|
+
* @param fileName 附件名称
|
|
305
|
+
* @param options
|
|
306
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
307
|
+
* @param options.authToken {string} token 非必传
|
|
308
|
+
* @param options.scale {number} 缩略比
|
|
309
|
+
* @returns
|
|
310
|
+
* createThumbnailLink('1', 'z', { API_BASEURL: 1 })
|
|
311
|
+
*/
|
|
312
|
+
function createThumbnailLink(fileId, fileName, options) {
|
|
313
|
+
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, _a = options.scale, scale = _a === void 0 ? 0.5 : _a;
|
|
314
|
+
var _b = getBasicInfo(API_BASEURL || "", authToken), token = _b.token, apiBaseURL = _b.apiBaseURL;
|
|
315
|
+
return "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/thumbnail/").concat(fileId, "?scale=").concat(scale, "&").concat(TOKEN_KEY, "=").concat(token);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* 生成图片上传地址
|
|
319
|
+
* @param options
|
|
320
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
321
|
+
* @param options.authToken {string} token 非必传
|
|
322
|
+
* @returns
|
|
323
|
+
*/
|
|
324
|
+
function createUploadFileLink(options) {
|
|
325
|
+
var API_BASEURL = options.API_BASEURL;
|
|
326
|
+
var apiBaseURL = getBasicInfo(API_BASEURL || "").apiBaseURL;
|
|
327
|
+
return "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/put-file-attach");
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* 生成图片删除地址
|
|
331
|
+
* @param options
|
|
332
|
+
* @param options.API_BASEURL {string} 接口请求的前缀地址 非必传
|
|
333
|
+
* @param options.authToken {string} token 非必传
|
|
334
|
+
* @returns
|
|
335
|
+
*/
|
|
336
|
+
function createDeleteFileLink(options) {
|
|
337
|
+
var API_BASEURL = options.API_BASEURL;
|
|
338
|
+
var apiBaseURL = getBasicInfo(API_BASEURL || "").apiBaseURL;
|
|
339
|
+
return "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/remove-file");
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* 获取基础数据
|
|
343
|
+
* @param baseURL 基础URL
|
|
344
|
+
* @param token token
|
|
345
|
+
* @returns
|
|
346
|
+
*/
|
|
347
|
+
function getBasicInfo(baseURL, token) {
|
|
348
|
+
var _a;
|
|
349
|
+
return {
|
|
350
|
+
token: token || getToken(),
|
|
351
|
+
apiBaseURL: ((_a = baseURL === null || baseURL === void 0 ? void 0 : baseURL.endsWith) === null || _a === void 0 ? void 0 : _a.call(baseURL, "/"))
|
|
352
|
+
? baseURL.slice(0, baseURL.length - 1)
|
|
353
|
+
: baseURL,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* 加密附件ID
|
|
358
|
+
* @param fileId 附件ID
|
|
359
|
+
* @description 加密方式
|
|
360
|
+
* 1. 都会通过encrypt加密一次
|
|
361
|
+
* 2. 如果参数是通过地址栏传输的,附件预览:encode一次;附件下载:encode两次;
|
|
362
|
+
* 3. 如果参数是通过body传输的,只需要encode一次
|
|
363
|
+
*/
|
|
364
|
+
function encodeFileId(fileId, encodeNum) {
|
|
365
|
+
if (encodeNum === void 0) { encodeNum = 1; }
|
|
366
|
+
var crypto = new Crypto(window.__CRYPTO_AES_KEY__, window.__CRYPTO_DES_KEY__);
|
|
367
|
+
if (encodeNum === 1) {
|
|
368
|
+
return encodeURIComponent(crypto.encrypt(fileId));
|
|
369
|
+
}
|
|
370
|
+
return encodeURIComponent(encodeURIComponent(crypto.encrypt(fileId)));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, encodeFileId, exportBolb, previewFile };
|