zy-react-library 1.1.2 → 1.1.3
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/components/Cascader/Area/index.js +1 -20
- package/components/Cascader/Basic/index.js +1 -57
- package/components/Cascader/Dictionary/index.js +1 -42
- package/components/Cascader/Industry/index.js +1 -21
- package/components/Editor/index.js +1 -82
- package/components/FormBuilder/FormBuilder.js +1 -97
- package/components/FormBuilder/FormItemsRenderer.js +1 -589
- package/components/FormBuilder/index.js +1 -5
- package/components/HeaderBack/index.js +1 -44
- package/components/HiddenInfo/gwj/index.js +1 -586
- package/components/Icon/AddIcon/index.js +1 -9
- package/components/Icon/BackIcon/index.js +1 -9
- package/components/Icon/DeleteIcon/index.js +1 -9
- package/components/Icon/DownloadIcon/index.js +1 -9
- package/components/Icon/EditIcon/index.js +1 -9
- package/components/Icon/ExportIcon/index.js +1 -9
- package/components/Icon/ImportIcon/index.js +1 -9
- package/components/Icon/LocationIcon/index.js +1 -9
- package/components/Icon/PrintIcon/index.js +1 -9
- package/components/Icon/ResetIcon/index.js +1 -9
- package/components/Icon/SearchIcon/index.js +1 -9
- package/components/Icon/VideoIcon/index.js +1 -9
- package/components/Icon/ViewIcon/index.js +1 -9
- package/components/ImportFile/index.js +1 -94
- package/components/LeftTree/Area/index.js +1 -15
- package/components/LeftTree/Basic/index.js +1 -160
- package/components/LeftTree/Department/Gwj/index.js +1 -29
- package/components/LeftTree/Dictionary/index.js +1 -42
- package/components/Map/MapSelector.js +1 -280
- package/components/Map/index.js +1 -90
- package/components/Page/index.js +1 -59
- package/components/Pdf/index.js +1 -136
- package/components/PreviewImg/index.js +1 -26
- package/components/PreviewPdf/index.js +1 -78
- package/components/Search/index.js +1 -147
- package/components/Select/Basic/index.js +1 -70
- package/components/Select/Dictionary/index.js +1 -42
- package/components/Select/Personnel/Gwj/index.js +1 -45
- package/components/SelectCreate/index.js +1 -48
- package/components/SelectTree/Area/index.js +1 -20
- package/components/SelectTree/Basic/index.js +1 -105
- package/components/SelectTree/Department/Gwj/index.js +1 -40
- package/components/SelectTree/Dictionary/index.js +1 -42
- package/components/SelectTree/HiddenLevel/Gwj/index.js +1 -70
- package/components/SelectTree/HiddenPart/Gwj/index.js +1 -36
- package/components/SelectTree/Industry/index.js +1 -21
- package/components/Signature/index.js +1 -100
- package/components/Table/index.js +1 -77
- package/components/TooltipPreviewImg/index.js +1 -28
- package/components/Upload/index.js +1 -229
- package/components/Video/AliPlayer.js +1 -182
- package/components/Video/index.js +1 -71
- package/enum/dictionary/index.js +1 -9
- package/enum/formItemRender/index.js +1 -39
- package/enum/hidden/gwj/index.js +1 -70
- package/enum/uploadFile/gwj/index.js +1 -258
- package/hooks/useDeleteFile/index.js +1 -95
- package/hooks/useDictionary/index.js +1 -64
- package/hooks/useDownloadBlob/index.js +1 -80
- package/hooks/useDownloadFile/index.js +1 -78
- package/hooks/useGetFile/index.js +1 -74
- package/hooks/useGetUrlQuery/index.js +1 -15
- package/hooks/useGetUserInfo/index.js +1 -42
- package/hooks/useIdle/index.js +1 -65
- package/hooks/useImportFile/index.js +1 -61
- package/hooks/useIsExistenceDuplicateSelection/index.js +1 -27
- package/hooks/useTable/index.js +1 -124
- package/hooks/useUploadFile/index.js +1 -144
- package/hooks/useUrlQueryCriteria/index.js +1 -84
- package/package.json +5 -1
- package/regular/index.js +1 -56
- package/utils/index.js +1 -591
|
@@ -1,95 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 删除文件
|
|
6
|
-
*/
|
|
7
|
-
function useDeleteFile(returnType = "object") {
|
|
8
|
-
// loading状态
|
|
9
|
-
const [loading, setLoading] = useState(false);
|
|
10
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
11
|
-
let requestCount = 0;
|
|
12
|
-
|
|
13
|
-
// 删除文件
|
|
14
|
-
const deleteFile = options => {
|
|
15
|
-
if (!options) {
|
|
16
|
-
console.error("请传入 options");
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// 增加请求数量并设置loading状态
|
|
21
|
-
requestCount++;
|
|
22
|
-
if (requestCount > 0) {
|
|
23
|
-
setLoading(true);
|
|
24
|
-
}
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
const {
|
|
27
|
-
files = [],
|
|
28
|
-
single = true
|
|
29
|
-
} = options;
|
|
30
|
-
if (!files) {
|
|
31
|
-
console.error("请传入 files");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (!Array.isArray(files)) {
|
|
35
|
-
console.error("请传入有效的 files");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 如果没有文件则直接返回
|
|
40
|
-
if (files.length === 0) {
|
|
41
|
-
requestCount--;
|
|
42
|
-
if (requestCount <= 0) {
|
|
43
|
-
setLoading(false);
|
|
44
|
-
}
|
|
45
|
-
resolve();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 单文件并且没有文件路径则直接返回
|
|
50
|
-
if (single) {
|
|
51
|
-
const firstFile = files[0];
|
|
52
|
-
if (!firstFile.filePath) {
|
|
53
|
-
requestCount--;
|
|
54
|
-
if (requestCount <= 0) {
|
|
55
|
-
setLoading(false);
|
|
56
|
-
}
|
|
57
|
-
resolve();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// 多文件并且没有文件id则直接返回
|
|
62
|
-
else {
|
|
63
|
-
const validFiles = files.filter(f => f.id);
|
|
64
|
-
if (validFiles.length === 0) {
|
|
65
|
-
requestCount--;
|
|
66
|
-
if (requestCount <= 0) {
|
|
67
|
-
setLoading(false);
|
|
68
|
-
}
|
|
69
|
-
resolve();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 发送请求
|
|
75
|
-
request(single ? `/basicInfo/imgFiles/delete?filePath=${files[0].filePath}` : `/basicInfo/imgFiles/ids?ids=${files.filter(f => f.id).map(f => f.id)}`, "delete").then(res => {
|
|
76
|
-
resolve(res.data);
|
|
77
|
-
}).catch(err => {
|
|
78
|
-
reject(err);
|
|
79
|
-
}).finally(() => {
|
|
80
|
-
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
81
|
-
requestCount--;
|
|
82
|
-
if (requestCount <= 0) {
|
|
83
|
-
setLoading(false);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
if (returnType === "array") return [loading, deleteFile];
|
|
89
|
-
return {
|
|
90
|
-
loading,
|
|
91
|
-
deleteFile
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export { useDeleteFile as default };
|
|
1
|
+
import{request as e}from"@cqsjjb/jjb-common-lib/http";import{useState as i}from"react";function r(r="object"){const[t,o]=i(!1);let l=0;const n=i=>{if(i)return l++,l>0&&o(!0),new Promise((r,t)=>{const{files:n=[],single:s=!0}=i;if(n)if(Array.isArray(n)){if(0===n.length)return l--,l<=0&&o(!1),void r();if(s){if(!n[0].filePath)return l--,l<=0&&o(!1),void r()}else if(0===n.filter(e=>e.id).length)return l--,l<=0&&o(!1),void r();e(s?`/basicInfo/imgFiles/delete?filePath=${n[0].filePath}`:`/basicInfo/imgFiles/ids?ids=${n.filter(e=>e.id).map(e=>e.id)}`,"delete").then(e=>{r(e.data)}).catch(e=>{t(e)}).finally(()=>{l--,l<=0&&o(!1)})}else console.error("请传入有效的 files");else console.error("请传入 files")});console.error("请传入 options")};return"array"===r?[t,n]:{loading:t,deleteFile:n}}export{r as default};
|
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { DICTIONARY_APP_KEY_ENUM } from '../../enum/dictionary/index.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 获取数据字典
|
|
7
|
-
*/
|
|
8
|
-
function useDictionary(returnType = "object") {
|
|
9
|
-
// loading状态
|
|
10
|
-
const [loading, setLoading] = useState(false);
|
|
11
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
-
let requestCount = 0;
|
|
13
|
-
|
|
14
|
-
// 获取数据字典
|
|
15
|
-
const getDictionary = options => {
|
|
16
|
-
if (!options) {
|
|
17
|
-
console.error("请传入 options");
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// 增加请求数量并设置loading状态
|
|
22
|
-
requestCount++;
|
|
23
|
-
if (requestCount > 0) {
|
|
24
|
-
setLoading(true);
|
|
25
|
-
}
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
const {
|
|
28
|
-
appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
|
|
29
|
-
dictValue
|
|
30
|
-
} = options;
|
|
31
|
-
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
|
|
32
|
-
console.error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (!dictValue) {
|
|
36
|
-
console.error("请传入 options.dictValue");
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 发送请求
|
|
41
|
-
request("/config/dict-trees/list/by/dictValues", "get", {
|
|
42
|
-
appKey,
|
|
43
|
-
dictValue
|
|
44
|
-
}).then(res => {
|
|
45
|
-
resolve(res.data);
|
|
46
|
-
}).catch(err => {
|
|
47
|
-
reject(err);
|
|
48
|
-
}).finally(() => {
|
|
49
|
-
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
50
|
-
requestCount--;
|
|
51
|
-
if (requestCount <= 0) {
|
|
52
|
-
setLoading(false);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
if (returnType === "array") return [loading, getDictionary];
|
|
58
|
-
return {
|
|
59
|
-
loading,
|
|
60
|
-
getDictionary
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { useDictionary as default };
|
|
1
|
+
import{request as o}from"@cqsjjb/jjb-common-lib/http";import{useState as t}from"react";import{DICTIONARY_APP_KEY_ENUM as e}from"../../enum/dictionary/index.js";function r(r="object"){const[i,n]=t(!1);let c=0;const a=t=>{if(t)return c++,c>0&&n(!0),new Promise((r,i)=>{const{appKey:a=e.DEFAULT,dictValue:s}=t;Object.values(e).includes(a)?s?o("/config/dict-trees/list/by/dictValues","get",{appKey:a,dictValue:s}).then(o=>{r(o.data)}).catch(o=>{i(o)}).finally(()=>{c--,c<=0&&n(!1)}):console.error("请传入 options.dictValue"):console.error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中")});console.error("请传入 options")};return"array"===r?[i,a]:{loading:i,getDictionary:a}}export{r as default};
|
|
@@ -1,80 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 下载Blob流文件
|
|
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
|
+
import{message as e}from"antd";import o from"dayjs";import{useState as n}from"react";function t(t="object"){const[r,a]=n(!1);let c=0;const d=(n,t)=>(c++,c>0&&a(!0),new Promise((r,d)=>{if(!n)return d(new Error("请传入 url"));const{name:s="",type:i="",params:l={}}=t,m=new URL((process.env.app.API_HOST||window.__JJB_ENVIRONMENT__.API_HOST)+n);Object.entries(l).forEach(([e,o])=>{m.searchParams.append(e,o)}),fetch(m,{method:"GET",mode:"cors",headers:{"Content-Type":"application/json",token:window.sessionStorage.token}}).then(e=>{if(e.ok)return e.blob();console.error("网络响应异常")}).then(e=>{const n=new Blob([e],{type:i||"application/vnd.ms-excel"}),t=document.createElement("a"),a=window.URL.createObjectURL(n);t.style.display="none",t.href=a,t.download=s||o().format("YYYY-MM-DD HH:mm:ss"),document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(a),r({data:n})}).catch(o=>{e.error("导出失败"),d(o)}).finally(()=>{c--,c<=0&&a(!1)})}));return"array"===t?[r,d]:{loading:r,downloadBlob:d}}export{t as default};
|
|
@@ -1,78 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { getFileUrl, getFileSuffix, getFileName } from '../../utils/index.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 下载文件
|
|
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
|
+
import{Modal as e,message as o}from"antd";import{useState as t}from"react";import{getFileUrl as n,getFileSuffix as c,getFileName as r}from"../../utils/index.js";function l(l="object"){const[d,a]=t(!1);let i=0;const m=t=>{i++,i>0&&a(!0);const{url:l,name:d}=t;l?e.confirm({title:"提示",content:"确定要下载此文件吗?",onOk:()=>{const e=n();let t=d;t?!c(t)&&c(l)&&(t=`${t}.${c(l)}`):t=r(l),fetch(l.includes(e)?l:e+l).then(e=>e.blob()).then(e=>{const o=document.createElement("a");document.body.appendChild(o),o.style.display="none";const n=window.URL.createObjectURL(e);o.href=n,o.download=`${t}`,o.click(),document.body.removeChild(o),window.URL.revokeObjectURL(n)}).catch(()=>{o.error("下载失败")}).finally(()=>{i--,i<=0&&a(!1)})},onCancel:()=>{i--,i<=0&&a(!1)}}):console.error("请传入 url")};return"array"===l?[d,m]:{loading:d,downloadFile:m}}export{l as default};
|
|
@@ -1,74 +1 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 获取文件
|
|
8
|
-
*/
|
|
9
|
-
function useGetFile(returnType = "object") {
|
|
10
|
-
// loading状态
|
|
11
|
-
const [loading, setLoading] = useState(false);
|
|
12
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
13
|
-
let requestCount = 0;
|
|
14
|
-
|
|
15
|
-
// 获取文件
|
|
16
|
-
const getFile = options => {
|
|
17
|
-
if (!options) {
|
|
18
|
-
console.error("请传入 options");
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 增加请求数量并设置loading状态
|
|
23
|
-
requestCount++;
|
|
24
|
-
if (requestCount > 0) {
|
|
25
|
-
setLoading(true);
|
|
26
|
-
}
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
const {
|
|
29
|
-
eqType,
|
|
30
|
-
eqForeignKey
|
|
31
|
-
} = options;
|
|
32
|
-
if (!eqType) {
|
|
33
|
-
console.error("请传入 options.eqType");
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 检查eqType是否在UPLOAD_FILE_TYPE_ENUM中
|
|
38
|
-
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType)) {
|
|
39
|
-
console.error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (eqForeignKey === undefined || eqForeignKey === null) {
|
|
43
|
-
console.error("请传入 options.eqForeignKey");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 发送请求
|
|
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
|
-
});
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
if (returnType === "array") return [loading, getFile];
|
|
68
|
-
return {
|
|
69
|
-
loading,
|
|
70
|
-
getFile
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { useGetFile as default };
|
|
1
|
+
import{request as e}from"@cqsjjb/jjb-common-lib/http";import{useState as o}from"react";import{UPLOAD_FILE_TYPE_ENUM as r}from"../../enum/uploadFile/gwj/index.js";import{addingPrefixToFile as t}from"../../utils/index.js";function n(n="object"){const[i,l]=o(!1);let s=0;const c=o=>{if(o)return s++,s>0&&l(!0),new Promise((n,i)=>{const{eqType:c,eqForeignKey:p}=o;c?Object.values(r).includes(c)?null!=p?e("/basicInfo/imgFiles/listAll","get",{eqType:c,eqForeignKey:p}).then(e=>{n(t(e.data).map(e=>({...e,type:void 0})))}).catch(e=>{i(e)}).finally(()=>{s--,s<=0&&l(!1)}):console.error("请传入 options.eqForeignKey"):console.error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中"):console.error("请传入 options.eqType")});console.error("请传入 options")};return"array"===n?[i,c]:{loading:i,getFile:c}}export{n as default};
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 获取路由参数
|
|
3
|
-
*/
|
|
4
|
-
function useGetUrlQuery() {
|
|
5
|
-
const urlQuery = new URLSearchParams(window.location.search);
|
|
6
|
-
|
|
7
|
-
// 直接返回包含所有参数的对象
|
|
8
|
-
const queryParams = {};
|
|
9
|
-
for (const [key, value] of urlQuery.entries()) {
|
|
10
|
-
queryParams[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return queryParams;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { useGetUrlQuery as default };
|
|
1
|
+
function n(){const n=new URLSearchParams(window.location.search),o={};for(const[e,r]of n.entries())o[e]=r;return o}export{n as default};
|
|
@@ -1,42 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 获取用户信息
|
|
6
|
-
*/
|
|
7
|
-
function useGetUserInfo(returnType = "object") {
|
|
8
|
-
// loading状态
|
|
9
|
-
const [loading, setLoading] = useState(false);
|
|
10
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
11
|
-
let requestCount = 0;
|
|
12
|
-
|
|
13
|
-
// 获取用户信息
|
|
14
|
-
const getUserInfo = () => {
|
|
15
|
-
// 增加请求数量并设置loading状态
|
|
16
|
-
requestCount++;
|
|
17
|
-
if (requestCount > 0) {
|
|
18
|
-
setLoading(true);
|
|
19
|
-
}
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
// 发送请求
|
|
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
|
-
});
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
if (returnType === "array") return [loading, getUserInfo];
|
|
36
|
-
return {
|
|
37
|
-
loading,
|
|
38
|
-
getUserInfo
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { useGetUserInfo as default };
|
|
1
|
+
import{request as t}from"@cqsjjb/jjb-common-lib/http";import{useState as o}from"react";function e(e="object"){const[n,r]=o(!1);let a=0;const c=()=>(a++,a>0&&r(!0),new Promise((o,e)=>{t("/basicInfo/user/getInfo","get",{}).then(t=>{o(t.data)}).catch(t=>{e(t)}).finally(()=>{a--,a<=0&&r(!1)})}));return"array"===e?[n,c]:{loading:n,getUserInfo:c}}export{e as default};
|
package/hooks/useIdle/index.js
CHANGED
|
@@ -1,65 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 检测用户是否处于空闲状态
|
|
5
|
-
*/
|
|
6
|
-
function useIdle(options = {}) {
|
|
7
|
-
const {
|
|
8
|
-
timeout = 10000,
|
|
9
|
-
events = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"]
|
|
10
|
-
} = options;
|
|
11
|
-
const [isIdle, setIsIdle] = useState(false);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
let idleTimer;
|
|
14
|
-
|
|
15
|
-
// 设置空闲状态
|
|
16
|
-
const setIdle = () => {
|
|
17
|
-
setIsIdle(true);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// 重置为空闲前的状态
|
|
21
|
-
const setActive = () => {
|
|
22
|
-
setIsIdle(false);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// 重置计时器
|
|
26
|
-
const resetTimer = () => {
|
|
27
|
-
clearTimeout(idleTimer);
|
|
28
|
-
idleTimer = setTimeout(setIdle, timeout);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// 初始化计时器(仅在非空闲状态下)
|
|
32
|
-
if (!isIdle) {
|
|
33
|
-
resetTimer();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 事件处理函数
|
|
37
|
-
const handleUserActivity = () => {
|
|
38
|
-
// 如果当前是空闲状态,用户操作后重置为活跃状态
|
|
39
|
-
if (isIdle) {
|
|
40
|
-
setActive();
|
|
41
|
-
} else {
|
|
42
|
-
// 如果当前是活跃状态,重置计时器
|
|
43
|
-
resetTimer();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// 添加事件监听器
|
|
48
|
-
events.forEach(event => {
|
|
49
|
-
window.addEventListener(event, handleUserActivity, {
|
|
50
|
-
passive: true
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// 清理函数
|
|
55
|
-
return () => {
|
|
56
|
-
clearTimeout(idleTimer);
|
|
57
|
-
events.forEach(event => {
|
|
58
|
-
window.removeEventListener(event, handleUserActivity);
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
}, [timeout, events, isIdle]);
|
|
62
|
-
return isIdle;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { useIdle as default };
|
|
1
|
+
import{useState as e,useEffect as t}from"react";function o(o={}){const{timeout:r=1e4,events:n=["mousemove","mousedown","resize","keydown","touchstart","wheel"]}=o,[s,i]=e(!1);return t(()=>{let e;const t=()=>{i(!0)},o=()=>{clearTimeout(e),e=setTimeout(t,r)};s||o();const u=()=>{s?i(!1):o()};return n.forEach(e=>{window.addEventListener(e,u,{passive:!0})}),()=>{clearTimeout(e),n.forEach(e=>{window.removeEventListener(e,u)})}},[r,n,s]),s}export{o as default};
|
|
@@ -1,61 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 导入文件
|
|
6
|
-
*/
|
|
7
|
-
function useImportFile(returnType = "object") {
|
|
8
|
-
// loading状态
|
|
9
|
-
const [loading, setLoading] = useState(false);
|
|
10
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
11
|
-
let requestCount = 0;
|
|
12
|
-
|
|
13
|
-
// 导入文件
|
|
14
|
-
const importFile = (url, options) => {
|
|
15
|
-
// 增加请求数量并设置loading状态
|
|
16
|
-
requestCount++;
|
|
17
|
-
if (requestCount > 0) {
|
|
18
|
-
setLoading(true);
|
|
19
|
-
}
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
if (!url) return reject(new Error("请传入 url"));
|
|
22
|
-
const {
|
|
23
|
-
files = [],
|
|
24
|
-
params = {}
|
|
25
|
-
} = options;
|
|
26
|
-
const formData = new FormData();
|
|
27
|
-
|
|
28
|
-
// 将文件添加到formData中
|
|
29
|
-
files.forEach(f => {
|
|
30
|
-
f.originFileObj && formData.append("file", f.originFileObj);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// 将额外携带的参数添加到formData中
|
|
34
|
-
Object.keys(params).forEach(key => {
|
|
35
|
-
formData.append(key, params[key]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// 发送请求
|
|
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
|
-
});
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
if (returnType === "array") return [loading, importFile];
|
|
55
|
-
return {
|
|
56
|
-
loading,
|
|
57
|
-
importFile
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { useImportFile as default };
|
|
1
|
+
import{request as r}from"@cqsjjb/jjb-common-lib/http";import{useState as t}from"react";function o(o="object"){const[e,n]=t(!1);let a=0;const i=(t,o)=>(a++,a>0&&n(!0),new Promise((e,i)=>{if(!t)return i(new Error("请传入 url"));const{files:c=[],params:l={}}=o,p=new FormData;c.forEach(r=>{r.originFileObj&&p.append("file",r.originFileObj)}),Object.keys(l).forEach(r=>{p.append(r,l[r])}),r(t,"post",p,{"Content-Type":"multipart/form-data"}).then(r=>{e(r)}).catch(r=>{i(r)}).finally(()=>{a--,a<=0&&n(!1)})}));return"array"===o?[e,i]:{loading:e,importFile:i}}export{o as default};
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
import { message }
|
|
2
|
-
import { uniqBy } from 'lodash-es';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 检查数组中是否存在重复项
|
|
6
|
-
*/
|
|
7
|
-
function useIsExistenceDuplicateSelection() {
|
|
8
|
-
const isExistenceDuplicateSelection = options => {
|
|
9
|
-
const {
|
|
10
|
-
data,
|
|
11
|
-
key,
|
|
12
|
-
message: message$1 = "存在重复项,请勿重复选择"
|
|
13
|
-
} = options;
|
|
14
|
-
return new Promise(resolve => {
|
|
15
|
-
if (uniqBy(data, key).length !== data.length) {
|
|
16
|
-
message.error(message$1);
|
|
17
|
-
} else {
|
|
18
|
-
resolve();
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
isExistenceDuplicateSelection
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { useIsExistenceDuplicateSelection as default };
|
|
1
|
+
import{message as e}from"antd";import{uniqBy as t}from"lodash-es";function r(){return{isExistenceDuplicateSelection:r=>{const{data:n,key:o,message:s="存在重复项,请勿重复选择"}=r;return new Promise(r=>{t(n,o).length!==n.length?e.error(s):r()})}}}export{r as default};
|