zmdms-utils 0.0.13 → 0.0.15
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/baseUrl.js +1 -1
- package/dist/es/file.d.ts +9 -1
- package/dist/es/file.js +55 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/baseUrl.ts +1 -1
- package/src/file.ts +53 -0
- package/src/index.ts +1 -0
package/dist/es/baseUrl.js
CHANGED
|
@@ -10,7 +10,7 @@ function getBaseUrl(processObj) {
|
|
|
10
10
|
};
|
|
11
11
|
// file 服务器
|
|
12
12
|
var fileBaseUrlObj = {
|
|
13
|
-
dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.
|
|
13
|
+
dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.134:88",
|
|
14
14
|
test: processObj.REACT_APP_FILE_TEST || "http://172.55.5.101:33013",
|
|
15
15
|
stage: processObj.REACT_APP_FILE_STAGE || "https://dzfile-prod.zmd.com.cn",
|
|
16
16
|
product: processObj.REACT_APP_FILE_PRODUCT || "https://dzfile.zmd.com.cn:8012",
|
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 };
|
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
package/src/baseUrl.ts
CHANGED
|
@@ -12,7 +12,7 @@ export function getBaseUrl(processObj: any) {
|
|
|
12
12
|
|
|
13
13
|
// file 服务器
|
|
14
14
|
const fileBaseUrlObj: any = {
|
|
15
|
-
dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.
|
|
15
|
+
dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.134:88",
|
|
16
16
|
test: processObj.REACT_APP_FILE_TEST || "http://172.55.5.101:33013",
|
|
17
17
|
stage: processObj.REACT_APP_FILE_STAGE || "https://dzfile-prod.zmd.com.cn",
|
|
18
18
|
product:
|
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
|