zmdms-webui 1.2.4 → 1.2.6
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.
|
@@ -3,9 +3,14 @@ import { IButtonProps } from './interface.js';
|
|
|
3
3
|
|
|
4
4
|
interface IButtonDownloadProps extends Omit<IButtonProps, "onClick"> {
|
|
5
5
|
/** 附件id */
|
|
6
|
-
attachId
|
|
6
|
+
attachId?: string;
|
|
7
7
|
/** 附件名 */
|
|
8
|
-
attachName
|
|
8
|
+
attachName?: string;
|
|
9
|
+
/** 前置事件 */
|
|
10
|
+
beforeDownloadHandle?: () => Promise<{
|
|
11
|
+
attachId: string;
|
|
12
|
+
attachName: string;
|
|
13
|
+
}>;
|
|
9
14
|
/** 附件大小 */
|
|
10
15
|
attachSize?: number;
|
|
11
16
|
/** 是否通过公共链接下载 */
|
|
@@ -8,40 +8,56 @@ import useBaseContext from '../config/useBaseContext.js';
|
|
|
8
8
|
import { message } from 'antd';
|
|
9
9
|
|
|
10
10
|
var ButtonDownload = function (props) {
|
|
11
|
-
var attachId = props.attachId, attachName = props.attachName, isPublic = props.isPublic, API_BASEURL = props.API_BASEURL, onClick = props.onClick, resetProps = __rest(props, ["attachId", "attachName", "isPublic", "API_BASEURL", "onClick"]);
|
|
11
|
+
var attachId = props.attachId, attachName = props.attachName, beforeDownloadHandle = props.beforeDownloadHandle, isPublic = props.isPublic, API_BASEURL = props.API_BASEURL, onClick = props.onClick, resetProps = __rest(props, ["attachId", "attachName", "beforeDownloadHandle", "isPublic", "API_BASEURL", "onClick"]);
|
|
12
12
|
var _a = useState(false), loading = _a[0], setLoading = _a[1];
|
|
13
13
|
var apiBaseUrl = useBaseContext().apiBaseUrl;
|
|
14
|
+
function downloadFileHandle(fileOptions, e) {
|
|
15
|
+
var attachId = fileOptions.attachId, attachName = fileOptions.attachName;
|
|
16
|
+
return downloadFile(attachId, attachName || "", {
|
|
17
|
+
API_BASEURL: API_BASEURL || apiBaseUrl,
|
|
18
|
+
open: isPublic,
|
|
19
|
+
})
|
|
20
|
+
.then(function (res) {
|
|
21
|
+
onClick && onClick(e, { result: true });
|
|
22
|
+
setLoading(false);
|
|
23
|
+
})
|
|
24
|
+
.catch(function (err) {
|
|
25
|
+
onClick && onClick(e, { result: false });
|
|
26
|
+
try {
|
|
27
|
+
err
|
|
28
|
+
.text()
|
|
29
|
+
.then(function (e) {
|
|
30
|
+
var result = JSON.parse("{");
|
|
31
|
+
message.error(result.msg || "下载失败!");
|
|
32
|
+
})
|
|
33
|
+
.catch(function (err2) {
|
|
34
|
+
message.error("下载失败!");
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (err1) {
|
|
38
|
+
message.error("下载失败!");
|
|
39
|
+
}
|
|
40
|
+
setLoading(false);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
14
43
|
var onClickHandle = function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
15
44
|
return __generator(this, function (_a) {
|
|
16
|
-
if (
|
|
45
|
+
if (beforeDownloadHandle) {
|
|
17
46
|
setLoading(true);
|
|
18
|
-
return [2 /*return*/,
|
|
19
|
-
API_BASEURL: API_BASEURL || apiBaseUrl,
|
|
20
|
-
open: isPublic,
|
|
21
|
-
})
|
|
47
|
+
return [2 /*return*/, beforeDownloadHandle()
|
|
22
48
|
.then(function (res) {
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
var attachId = res.attachId, attachName = res.attachName;
|
|
50
|
+
return downloadFileHandle({ attachId: attachId, attachName: attachName }, e);
|
|
25
51
|
})
|
|
26
52
|
.catch(function (err) {
|
|
27
53
|
onClick && onClick(e, { result: false });
|
|
28
|
-
try {
|
|
29
|
-
err
|
|
30
|
-
.text()
|
|
31
|
-
.then(function (e) {
|
|
32
|
-
var result = JSON.parse("{");
|
|
33
|
-
message.error(result.msg || "下载失败!");
|
|
34
|
-
})
|
|
35
|
-
.catch(function (err2) {
|
|
36
|
-
message.error("下载失败!");
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
catch (err1) {
|
|
40
|
-
message.error("下载失败!");
|
|
41
|
-
}
|
|
42
54
|
setLoading(false);
|
|
43
55
|
})];
|
|
44
56
|
}
|
|
57
|
+
if (attachId && attachName) {
|
|
58
|
+
setLoading(true);
|
|
59
|
+
return [2 /*return*/, downloadFileHandle({ attachId: attachId, attachName: attachName }, e)];
|
|
60
|
+
}
|
|
45
61
|
return [2 /*return*/];
|
|
46
62
|
});
|
|
47
63
|
}); };
|
|
@@ -4,6 +4,8 @@ import { IButtonProps } from './interface.js';
|
|
|
4
4
|
interface IButtonDownloadProps extends Omit<IButtonProps, "onClick"> {
|
|
5
5
|
/** 导出的接口方法 */
|
|
6
6
|
fetchHandle?: () => Promise<any>;
|
|
7
|
+
/** 导出的前置行为 */
|
|
8
|
+
beforeExportHandle?: () => Promise<any>;
|
|
7
9
|
/** 代理点击事件 如果下载结束后 还需做别的处理 */
|
|
8
10
|
onClick?: (e: any, info: any) => void;
|
|
9
11
|
fileName?: string;
|
|
@@ -18,28 +18,40 @@ import { message } from 'antd';
|
|
|
18
18
|
// });
|
|
19
19
|
// }
|
|
20
20
|
var ButtonExport = function (props) {
|
|
21
|
-
var fetchHandle = props.fetchHandle,
|
|
21
|
+
var fetchHandle = props.fetchHandle, beforeExportHandle = props.beforeExportHandle,
|
|
22
22
|
// axiosRequestConfig = {},
|
|
23
|
-
onClick = props.onClick, fileName = props.fileName, resetProps = __rest(props, ["fetchHandle", "onClick", "fileName"]);
|
|
23
|
+
onClick = props.onClick, fileName = props.fileName, resetProps = __rest(props, ["fetchHandle", "beforeExportHandle", "onClick", "fileName"]);
|
|
24
24
|
var _a = useState(false), loading = _a[0], setLoading = _a[1];
|
|
25
25
|
// const { apiBaseUrl } = useBaseContext();
|
|
26
26
|
var onClickHandle = function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
27
|
-
var res,
|
|
27
|
+
var res, err_2, blob;
|
|
28
28
|
var _a, _b;
|
|
29
29
|
return __generator(this, function (_c) {
|
|
30
30
|
switch (_c.label) {
|
|
31
31
|
case 0:
|
|
32
32
|
setLoading(true);
|
|
33
|
+
if (!beforeExportHandle) return [3 /*break*/, 4];
|
|
33
34
|
_c.label = 1;
|
|
34
35
|
case 1:
|
|
35
|
-
_c.trys.push([1,
|
|
36
|
+
_c.trys.push([1, 3, , 4]);
|
|
37
|
+
return [4 /*yield*/, beforeExportHandle()];
|
|
38
|
+
case 2:
|
|
39
|
+
_c.sent();
|
|
40
|
+
return [3 /*break*/, 4];
|
|
41
|
+
case 3:
|
|
42
|
+
_c.sent();
|
|
43
|
+
onClick && onClick(e, { result: false });
|
|
44
|
+
setLoading(false);
|
|
45
|
+
return [2 /*return*/];
|
|
46
|
+
case 4:
|
|
47
|
+
_c.trys.push([4, 7, , 8]);
|
|
36
48
|
res = void 0;
|
|
37
|
-
if (!fetchHandle) return [3 /*break*/,
|
|
49
|
+
if (!fetchHandle) return [3 /*break*/, 6];
|
|
38
50
|
return [4 /*yield*/, fetchHandle()];
|
|
39
|
-
case
|
|
51
|
+
case 5:
|
|
40
52
|
res = _c.sent();
|
|
41
|
-
return [3 /*break*/,
|
|
42
|
-
case
|
|
53
|
+
return [3 /*break*/, 6];
|
|
54
|
+
case 6:
|
|
43
55
|
exportBolb(res, fileName)
|
|
44
56
|
.then(function (r) {
|
|
45
57
|
if (r.result) {
|
|
@@ -53,12 +65,12 @@ var ButtonExport = function (props) {
|
|
|
53
65
|
message.error((err === null || err === void 0 ? void 0 : err.msg) || "导出失败!");
|
|
54
66
|
});
|
|
55
67
|
setLoading(false);
|
|
56
|
-
return [3 /*break*/,
|
|
57
|
-
case
|
|
58
|
-
|
|
68
|
+
return [3 /*break*/, 8];
|
|
69
|
+
case 7:
|
|
70
|
+
err_2 = _c.sent();
|
|
59
71
|
setLoading(false);
|
|
60
|
-
if (Object.prototype.toString.call((_a =
|
|
61
|
-
blob = (_b =
|
|
72
|
+
if (Object.prototype.toString.call((_a = err_2 === null || err_2 === void 0 ? void 0 : err_2.response) === null || _a === void 0 ? void 0 : _a.data) === "[object Blob]") {
|
|
73
|
+
blob = (_b = err_2 === null || err_2 === void 0 ? void 0 : err_2.response) === null || _b === void 0 ? void 0 : _b.data;
|
|
62
74
|
blob
|
|
63
75
|
.text()
|
|
64
76
|
.then(function (text) {
|
|
@@ -71,14 +83,14 @@ var ButtonExport = function (props) {
|
|
|
71
83
|
});
|
|
72
84
|
return [2 /*return*/];
|
|
73
85
|
}
|
|
74
|
-
if (typeof
|
|
75
|
-
message.error(
|
|
86
|
+
if (typeof err_2 === "string") {
|
|
87
|
+
message.error(err_2);
|
|
76
88
|
}
|
|
77
89
|
else {
|
|
78
|
-
message.error((
|
|
90
|
+
message.error((err_2 === null || err_2 === void 0 ? void 0 : err_2.msg) || "导出失败!");
|
|
79
91
|
}
|
|
80
|
-
return [2 /*return*/,
|
|
81
|
-
case
|
|
92
|
+
return [2 /*return*/, err_2];
|
|
93
|
+
case 8: return [2 /*return*/];
|
|
82
94
|
}
|
|
83
95
|
});
|
|
84
96
|
}); };
|