zy-react-library 1.1.1 → 1.1.2
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/README.md +5 -1
- package/components/Cascader/Area/index.js +11 -11
- package/components/Cascader/Basic/index.js +23 -30
- package/components/Cascader/Dictionary/index.js +42 -42
- package/components/Cascader/Industry/index.js +12 -11
- package/components/Editor/index.js +43 -63
- package/components/FormBuilder/FormBuilder.js +97 -87
- package/components/FormBuilder/FormItemsRenderer.js +579 -581
- package/components/FormBuilder/index.js +5 -3
- package/components/HeaderBack/index.js +39 -32
- package/components/HiddenInfo/gwj/index.js +507 -439
- package/components/Icon/AddIcon/index.js +6 -6
- package/components/Icon/BackIcon/index.js +6 -6
- package/components/Icon/DeleteIcon/index.js +6 -6
- package/components/Icon/DownloadIcon/index.js +6 -6
- package/components/Icon/EditIcon/index.js +6 -6
- package/components/Icon/ExportIcon/index.js +6 -6
- package/components/Icon/ImportIcon/index.js +6 -6
- package/components/Icon/LocationIcon/index.js +6 -6
- package/components/Icon/PrintIcon/index.js +6 -6
- package/components/Icon/ResetIcon/index.js +6 -6
- package/components/Icon/SearchIcon/index.js +6 -6
- package/components/Icon/VideoIcon/index.js +6 -6
- package/components/Icon/ViewIcon/index.js +6 -6
- package/components/ImportFile/index.js +94 -91
- package/components/LeftTree/Area/index.js +15 -15
- package/components/LeftTree/Basic/index.js +54 -65
- package/components/LeftTree/Department/Gwj/index.js +29 -32
- package/components/LeftTree/Dictionary/index.js +42 -42
- package/components/Map/MapSelector.js +280 -254
- package/components/Map/index.js +90 -77
- package/components/Page/index.js +43 -34
- package/components/Pdf/index.js +92 -90
- package/components/PreviewImg/index.js +26 -32
- package/components/PreviewPdf/index.js +78 -86
- package/components/Search/index.js +147 -141
- package/components/Select/Basic/index.js +70 -76
- package/components/Select/Dictionary/index.js +42 -42
- package/components/Select/Personnel/Gwj/index.js +45 -49
- package/components/SelectCreate/index.js +33 -40
- package/components/SelectTree/Area/index.js +11 -17
- package/components/SelectTree/Basic/index.js +105 -102
- package/components/SelectTree/Department/Gwj/index.js +40 -46
- package/components/SelectTree/Dictionary/index.js +42 -42
- package/components/SelectTree/HiddenLevel/Gwj/index.js +33 -35
- package/components/SelectTree/HiddenPart/Gwj/index.js +16 -19
- package/components/SelectTree/Industry/index.js +12 -18
- package/components/Signature/index.js +68 -62
- package/components/Table/index.js +77 -73
- package/components/Table/index.less +7 -1
- package/components/TooltipPreviewImg/index.js +28 -27
- package/components/Upload/index.js +229 -275
- package/components/Video/AliPlayer.js +182 -160
- package/components/Video/index.js +71 -90
- package/css/common.less +4 -0
- package/enum/dictionary/index.js +5 -3
- package/enum/formItemRender/index.js +37 -35
- package/enum/hidden/gwj/index.js +65 -26
- package/enum/uploadFile/gwj/index.js +166 -84
- package/hooks/useDeleteFile/index.js +24 -30
- package/hooks/useDictionary/index.js +28 -30
- package/hooks/useDownloadBlob/index.js +78 -77
- package/hooks/useDownloadFile/index.js +76 -79
- package/hooks/useGetFile/index.js +32 -32
- package/hooks/useGetUrlQuery/index.js +1 -2
- package/hooks/useGetUserInfo/index.js +19 -26
- package/hooks/useIdle/index.js +9 -11
- package/hooks/useImportFile/index.js +30 -28
- package/hooks/useIsExistenceDuplicateSelection/index.js +25 -18
- package/hooks/useTable/index.js +49 -38
- package/hooks/useUploadFile/index.js +142 -147
- package/hooks/useUrlQueryCriteria/index.js +20 -13
- package/package.json +14 -1
- package/regular/index.js +34 -39
- package/utils/index.js +515 -511
|
@@ -1,79 +1,80 @@
|
|
|
1
|
-
import { message } from
|
|
2
|
-
import dayjs from
|
|
3
|
-
import { useState } from
|
|
4
|
-
|
|
1
|
+
import { message } from 'antd';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* 下载Blob流文件
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// loading状态
|
|
10
|
-
const [loading, setLoading] = useState(false);
|
|
11
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
-
let requestCount = 0;
|
|
13
|
-
|
|
14
|
-
// 下载Blob流文件
|
|
15
|
-
const downloadBlob = (url, options) => {
|
|
16
|
-
// 增加请求数量并设置loading状态
|
|
17
|
-
requestCount++;
|
|
18
|
-
if (requestCount > 0) {
|
|
19
|
-
setLoading(true);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
7
|
+
*/
|
|
8
|
+
function useDownloadBlob(returnType = "object") {
|
|
9
|
+
// loading状态
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
+
let requestCount = 0;
|
|
13
|
+
|
|
14
|
+
// 下载Blob流文件
|
|
15
|
+
const downloadBlob = (url, options) => {
|
|
16
|
+
// 增加请求数量并设置loading状态
|
|
17
|
+
requestCount++;
|
|
18
|
+
if (requestCount > 0) {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
}
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
if (!url) return reject(new Error("请传入 url"));
|
|
23
|
+
const {
|
|
24
|
+
name = "",
|
|
25
|
+
type = "",
|
|
26
|
+
params = {}
|
|
27
|
+
} = options;
|
|
28
|
+
const finalUrl = new URL((process.env.app.API_HOST || window.__JJB_ENVIRONMENT__.API_HOST) + url);
|
|
29
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
30
|
+
finalUrl.searchParams.append(key, value);
|
|
31
|
+
});
|
|
32
|
+
fetch(finalUrl, {
|
|
33
|
+
method: "GET",
|
|
34
|
+
mode: "cors",
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
"token": window.sessionStorage["token"]
|
|
38
|
+
}
|
|
39
|
+
}).then(response => {
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
console.error("网络响应异常");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return response.blob();
|
|
45
|
+
}).then(blob => {
|
|
46
|
+
const finalBlob = new Blob([blob], {
|
|
47
|
+
type: type || "application/vnd.ms-excel"
|
|
48
|
+
});
|
|
49
|
+
const downloadElement = document.createElement("a");
|
|
50
|
+
const href = window.URL.createObjectURL(finalBlob);
|
|
51
|
+
downloadElement.style.display = "none";
|
|
52
|
+
downloadElement.href = href;
|
|
53
|
+
downloadElement.download = name || dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
54
|
+
document.body.appendChild(downloadElement);
|
|
55
|
+
downloadElement.click();
|
|
56
|
+
document.body.removeChild(downloadElement);
|
|
57
|
+
window.URL.revokeObjectURL(href);
|
|
58
|
+
resolve({
|
|
59
|
+
data: finalBlob
|
|
60
|
+
});
|
|
61
|
+
}).catch(err => {
|
|
62
|
+
message.error("导出失败");
|
|
63
|
+
reject(err);
|
|
64
|
+
}).finally(() => {
|
|
65
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
66
|
+
requestCount--;
|
|
67
|
+
if (requestCount <= 0) {
|
|
68
|
+
setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
if (returnType === "array") return [loading, downloadBlob];
|
|
74
|
+
return {
|
|
75
|
+
loading,
|
|
76
|
+
downloadBlob
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { useDownloadBlob as default };
|
|
@@ -1,81 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useState } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { Modal, message } from 'antd';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { getFileUrl, getFileSuffix, getFileName } from '../../utils/index.js';
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* 下载文件
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// loading状态
|
|
10
|
-
const [loading, setLoading] = useState(false);
|
|
11
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
-
let requestCount = 0;
|
|
13
|
-
|
|
14
|
-
// 下载文件
|
|
15
|
-
const downloadFile =
|
|
16
|
-
// 增加请求数量并设置loading状态
|
|
17
|
-
requestCount++;
|
|
18
|
-
if (requestCount > 0) {
|
|
19
|
-
setLoading(true);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (name) {
|
|
36
|
-
if (!getFileSuffix(name) && getFileSuffix(url)) {
|
|
37
|
-
name = `${name}.${getFileSuffix(url)}`;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return [loading, downloadFile];
|
|
80
|
-
return { loading, downloadFile };
|
|
81
|
-
}
|
|
7
|
+
*/
|
|
8
|
+
function useDownloadFile(returnType = "object") {
|
|
9
|
+
// loading状态
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
+
let requestCount = 0;
|
|
13
|
+
|
|
14
|
+
// 下载文件
|
|
15
|
+
const downloadFile = options => {
|
|
16
|
+
// 增加请求数量并设置loading状态
|
|
17
|
+
requestCount++;
|
|
18
|
+
if (requestCount > 0) {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
}
|
|
21
|
+
const {
|
|
22
|
+
url,
|
|
23
|
+
name: fileName
|
|
24
|
+
} = options;
|
|
25
|
+
if (!url) {
|
|
26
|
+
console.error("请传入 url");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
Modal.confirm({
|
|
30
|
+
title: "提示",
|
|
31
|
+
content: "确定要下载此文件吗?",
|
|
32
|
+
onOk: () => {
|
|
33
|
+
const fileUrl = getFileUrl();
|
|
34
|
+
let name = fileName;
|
|
35
|
+
if (name) {
|
|
36
|
+
if (!getFileSuffix(name) && getFileSuffix(url)) {
|
|
37
|
+
name = `${name}.${getFileSuffix(url)}`;
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
name = getFileName(url);
|
|
41
|
+
}
|
|
42
|
+
fetch(!url.includes(fileUrl) ? fileUrl + url : url).then(res => res.blob()).then(blob => {
|
|
43
|
+
const a = document.createElement("a");
|
|
44
|
+
document.body.appendChild(a);
|
|
45
|
+
a.style.display = "none";
|
|
46
|
+
const urlObject = window.URL.createObjectURL(blob);
|
|
47
|
+
a.href = urlObject;
|
|
48
|
+
a.download = `${name}`;
|
|
49
|
+
a.click();
|
|
50
|
+
document.body.removeChild(a);
|
|
51
|
+
window.URL.revokeObjectURL(urlObject);
|
|
52
|
+
}).catch(() => {
|
|
53
|
+
message.error("下载失败");
|
|
54
|
+
}).finally(() => {
|
|
55
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
56
|
+
requestCount--;
|
|
57
|
+
if (requestCount <= 0) {
|
|
58
|
+
setLoading(false);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
onCancel: () => {
|
|
63
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
64
|
+
requestCount--;
|
|
65
|
+
if (requestCount <= 0) {
|
|
66
|
+
setLoading(false);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
if (returnType === "array") return [loading, downloadFile];
|
|
72
|
+
return {
|
|
73
|
+
loading,
|
|
74
|
+
downloadFile
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { useDownloadFile as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { request } from
|
|
2
|
-
import { useState } from
|
|
3
|
-
import { UPLOAD_FILE_TYPE_ENUM } from
|
|
4
|
-
import { addingPrefixToFile } from
|
|
1
|
+
import { request } from '@cqsjjb/jjb-common-lib/http';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { UPLOAD_FILE_TYPE_ENUM } from '../../enum/uploadFile/gwj/index.js';
|
|
4
|
+
import { addingPrefixToFile } from '../../utils/index.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 获取文件
|
|
@@ -13,7 +13,7 @@ function useGetFile(returnType = "object") {
|
|
|
13
13
|
let requestCount = 0;
|
|
14
14
|
|
|
15
15
|
// 获取文件
|
|
16
|
-
const getFile =
|
|
16
|
+
const getFile = options => {
|
|
17
17
|
if (!options) {
|
|
18
18
|
console.error("请传入 options");
|
|
19
19
|
return;
|
|
@@ -24,10 +24,11 @@ function useGetFile(returnType = "object") {
|
|
|
24
24
|
if (requestCount > 0) {
|
|
25
25
|
setLoading(true);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
return new Promise((resolve, reject) => {
|
|
29
|
-
const {
|
|
30
|
-
|
|
28
|
+
const {
|
|
29
|
+
eqType,
|
|
30
|
+
eqForeignKey
|
|
31
|
+
} = options;
|
|
31
32
|
if (!eqType) {
|
|
32
33
|
console.error("请传入 options.eqType");
|
|
33
34
|
return;
|
|
@@ -38,37 +39,36 @@ function useGetFile(returnType = "object") {
|
|
|
38
39
|
console.error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
42
|
if (eqForeignKey === undefined || eqForeignKey === null) {
|
|
43
43
|
console.error("请传入 options.eqForeignKey");
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// 发送请求
|
|
48
|
-
request(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
48
|
+
request("/basicInfo/imgFiles/listAll", "get", {
|
|
49
|
+
eqType,
|
|
50
|
+
eqForeignKey
|
|
51
|
+
}).then(res => {
|
|
52
|
+
resolve(addingPrefixToFile(res.data).map(item => ({
|
|
53
|
+
...item,
|
|
54
|
+
type: undefined
|
|
55
|
+
})));
|
|
56
|
+
}).catch(err => {
|
|
57
|
+
reject(err);
|
|
58
|
+
}).finally(() => {
|
|
59
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
60
|
+
requestCount--;
|
|
61
|
+
if (requestCount <= 0) {
|
|
62
|
+
setLoading(false);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
66
65
|
});
|
|
67
66
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
if (returnType === "array") return [loading, getFile];
|
|
68
|
+
return {
|
|
69
|
+
loading,
|
|
70
|
+
getFile
|
|
71
|
+
};
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export default
|
|
74
|
+
export { useGetFile as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { request } from
|
|
2
|
-
import { useState } from
|
|
1
|
+
import { request } from '@cqsjjb/jjb-common-lib/http';
|
|
2
|
+
import { useState } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 获取用户信息
|
|
@@ -17,33 +17,26 @@ function useGetUserInfo(returnType = "object") {
|
|
|
17
17
|
if (requestCount > 0) {
|
|
18
18
|
setLoading(true);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
return new Promise((resolve, reject) => {
|
|
22
21
|
// 发送请求
|
|
23
|
-
request(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.finally(() => {
|
|
35
|
-
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
36
|
-
requestCount--;
|
|
37
|
-
if (requestCount <= 0) {
|
|
38
|
-
setLoading(false);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
22
|
+
request("/basicInfo/user/getInfo", "get", {}).then(res => {
|
|
23
|
+
resolve(res.data);
|
|
24
|
+
}).catch(err => {
|
|
25
|
+
reject(err);
|
|
26
|
+
}).finally(() => {
|
|
27
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
28
|
+
requestCount--;
|
|
29
|
+
if (requestCount <= 0) {
|
|
30
|
+
setLoading(false);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
41
33
|
});
|
|
42
34
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
if (returnType === "array") return [loading, getUserInfo];
|
|
36
|
+
return {
|
|
37
|
+
loading,
|
|
38
|
+
getUserInfo
|
|
39
|
+
};
|
|
47
40
|
}
|
|
48
41
|
|
|
49
|
-
export default
|
|
42
|
+
export { useGetUserInfo as default };
|
package/hooks/useIdle/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 检测用户是否处于空闲状态
|
|
@@ -6,11 +6,9 @@ import { useEffect, useState } from "react";
|
|
|
6
6
|
function useIdle(options = {}) {
|
|
7
7
|
const {
|
|
8
8
|
timeout = 10000,
|
|
9
|
-
events = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"]
|
|
9
|
+
events = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"]
|
|
10
10
|
} = options;
|
|
11
|
-
|
|
12
11
|
const [isIdle, setIsIdle] = useState(false);
|
|
13
|
-
|
|
14
12
|
useEffect(() => {
|
|
15
13
|
let idleTimer;
|
|
16
14
|
|
|
@@ -40,28 +38,28 @@ function useIdle(options = {}) {
|
|
|
40
38
|
// 如果当前是空闲状态,用户操作后重置为活跃状态
|
|
41
39
|
if (isIdle) {
|
|
42
40
|
setActive();
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
41
|
+
} else {
|
|
45
42
|
// 如果当前是活跃状态,重置计时器
|
|
46
43
|
resetTimer();
|
|
47
44
|
}
|
|
48
45
|
};
|
|
49
46
|
|
|
50
47
|
// 添加事件监听器
|
|
51
|
-
events.forEach(
|
|
52
|
-
window.addEventListener(event, handleUserActivity, {
|
|
48
|
+
events.forEach(event => {
|
|
49
|
+
window.addEventListener(event, handleUserActivity, {
|
|
50
|
+
passive: true
|
|
51
|
+
});
|
|
53
52
|
});
|
|
54
53
|
|
|
55
54
|
// 清理函数
|
|
56
55
|
return () => {
|
|
57
56
|
clearTimeout(idleTimer);
|
|
58
|
-
events.forEach(
|
|
57
|
+
events.forEach(event => {
|
|
59
58
|
window.removeEventListener(event, handleUserActivity);
|
|
60
59
|
});
|
|
61
60
|
};
|
|
62
61
|
}, [timeout, events, isIdle]);
|
|
63
|
-
|
|
64
62
|
return isIdle;
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
export default
|
|
65
|
+
export { useIdle as default };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { request } from
|
|
2
|
-
import { useState } from
|
|
1
|
+
import { request } from '@cqsjjb/jjb-common-lib/http';
|
|
2
|
+
import { useState } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 导入文件
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
function useImportFile(returnType = "object") {
|
|
8
8
|
// loading状态
|
|
9
9
|
const [loading, setLoading] = useState(false);
|
|
10
10
|
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
@@ -17,43 +17,45 @@ export default function useImportFile(returnType = "object") {
|
|
|
17
17
|
if (requestCount > 0) {
|
|
18
18
|
setLoading(true);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
return new Promise((resolve, reject) => {
|
|
22
|
-
if (!url)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (!url) return reject(new Error("请传入 url"));
|
|
22
|
+
const {
|
|
23
|
+
files = [],
|
|
24
|
+
params = {}
|
|
25
|
+
} = options;
|
|
26
26
|
const formData = new FormData();
|
|
27
27
|
|
|
28
28
|
// 将文件添加到formData中
|
|
29
|
-
files.forEach(
|
|
29
|
+
files.forEach(f => {
|
|
30
30
|
f.originFileObj && formData.append("file", f.originFileObj);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
// 将额外携带的参数添加到formData中
|
|
34
|
-
Object.keys(params).forEach(
|
|
34
|
+
Object.keys(params).forEach(key => {
|
|
35
35
|
formData.append(key, params[key]);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// 发送请求
|
|
39
|
-
request(url, "post", formData, {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
39
|
+
request(url, "post", formData, {
|
|
40
|
+
"Content-Type": "multipart/form-data"
|
|
41
|
+
}).then(res => {
|
|
42
|
+
resolve(res);
|
|
43
|
+
}).catch(err => {
|
|
44
|
+
reject(err);
|
|
45
|
+
}).finally(() => {
|
|
46
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
47
|
+
requestCount--;
|
|
48
|
+
if (requestCount <= 0) {
|
|
49
|
+
setLoading(false);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
53
52
|
});
|
|
54
53
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
if (returnType === "array") return [loading, importFile];
|
|
55
|
+
return {
|
|
56
|
+
loading,
|
|
57
|
+
importFile
|
|
58
|
+
};
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
export { useImportFile as default };
|