zmdms-utils 0.0.65 → 0.0.67
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/constants.js +3 -1
- package/dist/es/file.js +72 -36
- package/package.json +1 -1
- package/src/constants.ts +3 -0
- package/src/file.ts +82 -36
package/dist/es/constants.js
CHANGED
|
@@ -25,5 +25,7 @@ var TOKEN_KEY = window.__TOKEN_KEY__ || "Cicoms-Auth";
|
|
|
25
25
|
// 基础前缀
|
|
26
26
|
// export const BASIC_KEY = "zmdms";
|
|
27
27
|
var BASIC_KEY = window.__BASIC_KEY__ || "cicoms";
|
|
28
|
+
// 附件相关服务
|
|
29
|
+
var FILE_SERVICE = window.__FILE_SERVICE__ || "cicoms";
|
|
28
30
|
|
|
29
|
-
export { BASIC_KEY, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, PERSONNEL_CENTER_APPNAME, SALARY_CENTER_APPNAME, TOKEN_KEY };
|
|
31
|
+
export { BASIC_KEY, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, FILE_SERVICE, PERSONNEL_CENTER_APPNAME, SALARY_CENTER_APPNAME, TOKEN_KEY };
|
package/dist/es/file.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { getToken } from './auth.js';
|
|
2
|
-
import { dangerouslyXss, specialString, getFileExtension } from './common.js';
|
|
3
|
-
import { BASIC_KEY, TOKEN_KEY } from './constants.js';
|
|
2
|
+
import { dangerouslyXss, specialString, getFileExtension, isImageExtension } from './common.js';
|
|
3
|
+
import { BASIC_KEY, TOKEN_KEY, FILE_SERVICE } from './constants.js';
|
|
4
|
+
import { Crypto } from './crypto.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 附件相关接口
|
|
7
8
|
*/
|
|
9
|
+
// 是否是中拓的附件服务
|
|
10
|
+
var isZmdmsFileService = FILE_SERVICE === "zmdms";
|
|
8
11
|
/**
|
|
9
12
|
* 附件下载方法
|
|
10
13
|
* @param fileId 附件id
|
|
@@ -17,6 +20,9 @@ import { BASIC_KEY, TOKEN_KEY } from './constants.js';
|
|
|
17
20
|
*/
|
|
18
21
|
function downloadFile(fileId, fileName, options) {
|
|
19
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
|
+
}
|
|
20
26
|
return new Promise(function (resolve, reject) {
|
|
21
27
|
var xhr = new XMLHttpRequest();
|
|
22
28
|
// 获取请求基础数据
|
|
@@ -95,6 +101,9 @@ function batchDownloadFiles(fileList, options) {
|
|
|
95
101
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
96
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, ",");
|
|
97
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
|
+
}
|
|
98
107
|
xhr.send("attachIds=".concat(fileIds, "&fileNames=").concat(fileNames, "&zipName=").concat(zipName, "&addWaterMark=").concat(waterMark));
|
|
99
108
|
});
|
|
100
109
|
}
|
|
@@ -109,7 +118,7 @@ function batchDownloadFiles(fileList, options) {
|
|
|
109
118
|
* @param options.fileList { attachId: string, attachName: string ... }[] 附件列表。批量预览时有用
|
|
110
119
|
*/
|
|
111
120
|
function previewFile(fileId, fileName, options) {
|
|
112
|
-
var API_BASEURL = options.API_BASEURL, authToken = options.authToken
|
|
121
|
+
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, _a = options.fileList, fileList = _a === void 0 ? [] : _a;
|
|
113
122
|
// 获取请求基础数据
|
|
114
123
|
var _b = getBasicInfo(API_BASEURL, authToken), token = _b.token, apiBaseURL = _b.apiBaseURL;
|
|
115
124
|
// 处理附件名中的一些特殊字符
|
|
@@ -126,34 +135,39 @@ function previewFile(fileId, fileName, options) {
|
|
|
126
135
|
// 如果文件名没变,文件内容改变。这样就会导致再次预览时 内容不会更新
|
|
127
136
|
// 所以将文件名 与 文件id组合来生成不同的文件名
|
|
128
137
|
previewFileName = "".concat(filePreName, "-").concat(fileId, ".").concat(fileExtension);
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
if (!isZmdmsFileService) {
|
|
139
|
+
// 2023-12-30 修改成数字中心预览
|
|
140
|
+
window.open("".concat(apiBaseURL, "/api/cicoms-cicohr-org/cicomscicohr/v1/common/filePreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
131
143
|
// 如果是图片 走批量预览接口
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
+
}
|
|
157
171
|
}
|
|
158
172
|
/**
|
|
159
173
|
* 导出一个文件流
|
|
@@ -238,6 +252,9 @@ function createDownloadLink(fileId, options) {
|
|
|
238
252
|
if (options === void 0) { options = {}; }
|
|
239
253
|
var API_BASEURL = options.API_BASEURL, authToken = options.authToken, open = options.open;
|
|
240
254
|
var _a = getBasicInfo(API_BASEURL || "", authToken), token = _a.token, apiBaseURL = _a.apiBaseURL;
|
|
255
|
+
if (isZmdmsFileService) {
|
|
256
|
+
fileId = encodeFileId(fileId, 2);
|
|
257
|
+
}
|
|
241
258
|
if (open) {
|
|
242
259
|
return "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/public/download-file/").concat(fileId);
|
|
243
260
|
}
|
|
@@ -272,11 +289,14 @@ function createOriginalLink(fileId, fileName, options) {
|
|
|
272
289
|
// 所以将文件名 与 文件id组合来生成不同的文件名
|
|
273
290
|
previewFileName = "".concat(filePreName, "-").concat(fileId, ".").concat(fileExtension);
|
|
274
291
|
// 2023-12-30 替换成数字中心的 预览接口
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
292
|
+
if (!isZmdmsFileService) {
|
|
293
|
+
return "".concat(apiBaseURL, "/api/cicoms-cicohr-org/cicomscicohr/v1/common/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)) : ""));
|
|
280
300
|
}
|
|
281
301
|
/**
|
|
282
302
|
* 生成缩略图路径
|
|
@@ -333,5 +353,21 @@ function getBasicInfo(baseURL, token) {
|
|
|
333
353
|
: baseURL,
|
|
334
354
|
};
|
|
335
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
|
+
}
|
|
336
372
|
|
|
337
|
-
export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile };
|
|
373
|
+
export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, encodeFileId, exportBolb, previewFile };
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -31,3 +31,6 @@ export const TOKEN_KEY = (window as any).__TOKEN_KEY__ || "Cicoms-Auth";
|
|
|
31
31
|
// 基础前缀
|
|
32
32
|
// export const BASIC_KEY = "zmdms";
|
|
33
33
|
export const BASIC_KEY = (window as any).__BASIC_KEY__ || "cicoms";
|
|
34
|
+
|
|
35
|
+
// 附件相关服务
|
|
36
|
+
export const FILE_SERVICE = (window as any).__FILE_SERVICE__ || "cicoms";
|
package/src/file.ts
CHANGED
|
@@ -8,8 +8,12 @@ import {
|
|
|
8
8
|
getFileExtension,
|
|
9
9
|
isImageExtension,
|
|
10
10
|
} from "./common";
|
|
11
|
-
import { TOKEN_KEY, BASIC_KEY } from "./constants";
|
|
11
|
+
import { TOKEN_KEY, BASIC_KEY, FILE_SERVICE } from "./constants";
|
|
12
12
|
import { AxiosResponse } from "axios";
|
|
13
|
+
import { Crypto } from "./crypto";
|
|
14
|
+
|
|
15
|
+
// 是否是中拓的附件服务
|
|
16
|
+
const isZmdmsFileService = FILE_SERVICE === "zmdms";
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* 附件下载方法
|
|
@@ -27,6 +31,9 @@ export function downloadFile(
|
|
|
27
31
|
options: IDownloadOptions
|
|
28
32
|
) {
|
|
29
33
|
const { API_BASEURL, authToken, waterMark = true, open } = options;
|
|
34
|
+
if (isZmdmsFileService) {
|
|
35
|
+
fileId = encodeFileId(fileId, 2);
|
|
36
|
+
}
|
|
30
37
|
return new Promise((resolve, reject) => {
|
|
31
38
|
const xhr = new XMLHttpRequest();
|
|
32
39
|
// 获取请求基础数据
|
|
@@ -129,8 +136,11 @@ export function batchDownloadFiles(
|
|
|
129
136
|
};
|
|
130
137
|
xhr.setRequestHeader(TOKEN_KEY, token || "");
|
|
131
138
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
132
|
-
|
|
139
|
+
let fileIds = fileList?.map?.((item) => item.attachId)?.join?.(",");
|
|
133
140
|
const fileNames = fileList?.map?.((item) => item.attachName)?.join?.(",");
|
|
141
|
+
if (isZmdmsFileService) {
|
|
142
|
+
fileIds = encodeFileId(fileIds, 2);
|
|
143
|
+
}
|
|
134
144
|
xhr.send(
|
|
135
145
|
`attachIds=${fileIds}&fileNames=${fileNames}&zipName=${zipName}&addWaterMark=${waterMark}`
|
|
136
146
|
);
|
|
@@ -169,37 +179,46 @@ export function previewFile(
|
|
|
169
179
|
// 所以将文件名 与 文件id组合来生成不同的文件名
|
|
170
180
|
previewFileName = `${filePreName}-${fileId}.${fileExtension}`;
|
|
171
181
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
if (!isZmdmsFileService) {
|
|
183
|
+
// 2023-12-30 修改成数字中心预览
|
|
184
|
+
window.open(
|
|
185
|
+
`${apiBaseURL}/api/cicoms-cicohr-org/cicomscicohr/v1/common/filePreview?attachId=${fileId}&${TOKEN_KEY}=${token}`
|
|
186
|
+
);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
176
189
|
|
|
177
190
|
// 如果是图片 走批量预览接口
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
191
|
+
|
|
192
|
+
const isImage = isImageExtension(fileExtension);
|
|
193
|
+
if (isImage) {
|
|
194
|
+
const imgFiles = fileList.filter((item) => {
|
|
195
|
+
const { attachName, attachId } = item;
|
|
196
|
+
const [, fileExtension] = getFileExtension(attachName);
|
|
197
|
+
if (isImageExtension(fileExtension) && attachId !== fileId) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
});
|
|
202
|
+
let attachIds = imgFiles.map((item) => item.attachId).join(",");
|
|
203
|
+
let fileIds = attachIds ? `${fileId},${attachIds}` : fileId;
|
|
204
|
+
if (isZmdmsFileService) {
|
|
205
|
+
fileIds = encodeFileId(fileIds, 1);
|
|
206
|
+
}
|
|
207
|
+
// 批量图片预览
|
|
208
|
+
window.open(
|
|
209
|
+
`${apiBaseURL}/picturesAttchPreview?attachIds=${fileIds}&${TOKEN_KEY}=${token}` +
|
|
210
|
+
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
211
|
+
);
|
|
212
|
+
} else {
|
|
213
|
+
if (isZmdmsFileService) {
|
|
214
|
+
fileId = encodeFileId(fileId, 1);
|
|
215
|
+
}
|
|
216
|
+
// 普通预览
|
|
217
|
+
window.open(
|
|
218
|
+
`${apiBaseURL}/attchPreview?attachId=${fileId}&${TOKEN_KEY}=${token}&officePreviewType=pdf` +
|
|
219
|
+
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
220
|
+
);
|
|
221
|
+
}
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
/**
|
|
@@ -286,6 +305,9 @@ export function createDownloadLink(
|
|
|
286
305
|
) {
|
|
287
306
|
const { API_BASEURL, authToken, open } = options;
|
|
288
307
|
const { token, apiBaseURL } = getBasicInfo(API_BASEURL || "", authToken);
|
|
308
|
+
if (isZmdmsFileService) {
|
|
309
|
+
fileId = encodeFileId(fileId, 2);
|
|
310
|
+
}
|
|
289
311
|
if (open) {
|
|
290
312
|
return `${apiBaseURL}/api/${BASIC_KEY}-resource/oss/endpoint/public/download-file/${fileId}`;
|
|
291
313
|
}
|
|
@@ -323,11 +345,16 @@ export function createOriginalLink(
|
|
|
323
345
|
// 所以将文件名 与 文件id组合来生成不同的文件名
|
|
324
346
|
previewFileName = `${filePreName}-${fileId}.${fileExtension}`;
|
|
325
347
|
// 2023-12-30 替换成数字中心的 预览接口
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
348
|
+
if (!isZmdmsFileService) {
|
|
349
|
+
return `${apiBaseURL}/api/cicoms-cicohr-org/cicomscicohr/v1/common/filePreview?attachId=${fileId}&${TOKEN_KEY}=${token}`;
|
|
350
|
+
}
|
|
351
|
+
if (isZmdmsFileService) {
|
|
352
|
+
fileId = encodeFileId(fileId, 2);
|
|
353
|
+
}
|
|
354
|
+
return (
|
|
355
|
+
`${apiBaseURL}/attchPreview?attachId=${fileId}&${TOKEN_KEY}=${token}&officePreviewType=pdf` +
|
|
356
|
+
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
357
|
+
);
|
|
331
358
|
}
|
|
332
359
|
|
|
333
360
|
/**
|
|
@@ -423,3 +450,22 @@ interface IThumbnailLinkOptions extends Partial<IOptions> {
|
|
|
423
450
|
/** 缩放比例 */
|
|
424
451
|
scale?: number;
|
|
425
452
|
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* 加密附件ID
|
|
456
|
+
* @param fileId 附件ID
|
|
457
|
+
* @description 加密方式
|
|
458
|
+
* 1. 都会通过encrypt加密一次
|
|
459
|
+
* 2. 如果参数是通过地址栏传输的,附件预览:encode一次;附件下载:encode两次;
|
|
460
|
+
* 3. 如果参数是通过body传输的,只需要encode一次
|
|
461
|
+
*/
|
|
462
|
+
export function encodeFileId(fileId: string, encodeNum: number = 1) {
|
|
463
|
+
const crypto = new Crypto(
|
|
464
|
+
(window as any).__CRYPTO_AES_KEY__,
|
|
465
|
+
(window as any).__CRYPTO_DES_KEY__
|
|
466
|
+
);
|
|
467
|
+
if (encodeNum === 1) {
|
|
468
|
+
return encodeURIComponent(crypto.encrypt(fileId));
|
|
469
|
+
}
|
|
470
|
+
return encodeURIComponent(encodeURIComponent(crypto.encrypt(fileId)));
|
|
471
|
+
}
|