zy-react-library 1.1.1 → 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/README.md +5 -1
- package/components/Cascader/Area/index.js +1 -20
- package/components/Cascader/Basic/index.js +1 -64
- package/components/Cascader/Dictionary/index.js +1 -42
- package/components/Cascader/Industry/index.js +1 -20
- package/components/Editor/index.js +1 -102
- package/components/FormBuilder/FormBuilder.js +1 -87
- package/components/FormBuilder/FormItemsRenderer.js +1 -591
- package/components/FormBuilder/index.js +1 -3
- package/components/HeaderBack/index.js +1 -37
- package/components/HiddenInfo/gwj/index.js +1 -518
- 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 -91
- package/components/LeftTree/Area/index.js +1 -15
- package/components/LeftTree/Basic/index.js +1 -171
- package/components/LeftTree/Department/Gwj/index.js +1 -32
- package/components/LeftTree/Dictionary/index.js +1 -42
- package/components/Map/MapSelector.js +1 -254
- package/components/Map/index.js +1 -77
- package/components/Page/index.js +1 -50
- package/components/Pdf/index.js +1 -134
- package/components/PreviewImg/index.js +1 -32
- package/components/PreviewPdf/index.js +1 -86
- package/components/Search/index.js +1 -141
- package/components/Select/Basic/index.js +1 -76
- package/components/Select/Dictionary/index.js +1 -42
- package/components/Select/Personnel/Gwj/index.js +1 -49
- package/components/SelectCreate/index.js +1 -55
- package/components/SelectTree/Area/index.js +1 -26
- package/components/SelectTree/Basic/index.js +1 -102
- package/components/SelectTree/Department/Gwj/index.js +1 -46
- package/components/SelectTree/Dictionary/index.js +1 -42
- package/components/SelectTree/HiddenLevel/Gwj/index.js +1 -72
- package/components/SelectTree/HiddenPart/Gwj/index.js +1 -39
- package/components/SelectTree/Industry/index.js +1 -27
- package/components/Signature/index.js +1 -94
- package/components/Table/index.js +1 -73
- package/components/Table/index.less +7 -1
- package/components/TooltipPreviewImg/index.js +1 -27
- package/components/Upload/index.js +1 -275
- package/components/Video/AliPlayer.js +1 -160
- package/components/Video/index.js +1 -90
- package/css/common.less +4 -0
- package/enum/dictionary/index.js +1 -7
- package/enum/formItemRender/index.js +1 -37
- package/enum/hidden/gwj/index.js +1 -31
- package/enum/uploadFile/gwj/index.js +1 -176
- package/hooks/useDeleteFile/index.js +1 -101
- package/hooks/useDictionary/index.js +1 -66
- package/hooks/useDownloadBlob/index.js +1 -79
- package/hooks/useDownloadFile/index.js +1 -81
- package/hooks/useGetFile/index.js +1 -74
- package/hooks/useGetUrlQuery/index.js +1 -16
- package/hooks/useGetUserInfo/index.js +1 -49
- package/hooks/useIdle/index.js +1 -67
- package/hooks/useImportFile/index.js +1 -59
- package/hooks/useIsExistenceDuplicateSelection/index.js +1 -20
- package/hooks/useTable/index.js +1 -113
- package/hooks/useUploadFile/index.js +1 -149
- package/hooks/useUrlQueryCriteria/index.js +1 -77
- package/package.json +18 -1
- package/regular/index.js +1 -61
- package/utils/index.js +1 -587
package/hooks/useIdle/index.js
CHANGED
|
@@ -1,67 +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
|
-
|
|
12
|
-
const [isIdle, setIsIdle] = useState(false);
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
let idleTimer;
|
|
16
|
-
|
|
17
|
-
// 设置空闲状态
|
|
18
|
-
const setIdle = () => {
|
|
19
|
-
setIsIdle(true);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// 重置为空闲前的状态
|
|
23
|
-
const setActive = () => {
|
|
24
|
-
setIsIdle(false);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// 重置计时器
|
|
28
|
-
const resetTimer = () => {
|
|
29
|
-
clearTimeout(idleTimer);
|
|
30
|
-
idleTimer = setTimeout(setIdle, timeout);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// 初始化计时器(仅在非空闲状态下)
|
|
34
|
-
if (!isIdle) {
|
|
35
|
-
resetTimer();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 事件处理函数
|
|
39
|
-
const handleUserActivity = () => {
|
|
40
|
-
// 如果当前是空闲状态,用户操作后重置为活跃状态
|
|
41
|
-
if (isIdle) {
|
|
42
|
-
setActive();
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
// 如果当前是活跃状态,重置计时器
|
|
46
|
-
resetTimer();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// 添加事件监听器
|
|
51
|
-
events.forEach((event) => {
|
|
52
|
-
window.addEventListener(event, handleUserActivity, { passive: true });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// 清理函数
|
|
56
|
-
return () => {
|
|
57
|
-
clearTimeout(idleTimer);
|
|
58
|
-
events.forEach((event) => {
|
|
59
|
-
window.removeEventListener(event, handleUserActivity);
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
}, [timeout, events, isIdle]);
|
|
63
|
-
|
|
64
|
-
return isIdle;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default useIdle;
|
|
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,59 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 导入文件
|
|
6
|
-
*/
|
|
7
|
-
export default 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
|
-
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
if (!url)
|
|
23
|
-
return reject(new Error("请传入 url"));
|
|
24
|
-
|
|
25
|
-
const { files = [], params = {} } = 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, { "Content-Type": "multipart/form-data" })
|
|
40
|
-
.then((res) => {
|
|
41
|
-
resolve(res);
|
|
42
|
-
})
|
|
43
|
-
.catch((err) => {
|
|
44
|
-
reject(err);
|
|
45
|
-
})
|
|
46
|
-
.finally(() => {
|
|
47
|
-
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
48
|
-
requestCount--;
|
|
49
|
-
if (requestCount <= 0) {
|
|
50
|
-
setLoading(false);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
if (returnType === "array")
|
|
57
|
-
return [loading, importFile];
|
|
58
|
-
return { loading, importFile };
|
|
59
|
-
}
|
|
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,20 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { uniqBy } from "lodash-es";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 检查数组中是否存在重复项
|
|
6
|
-
*/
|
|
7
|
-
export default function useIsExistenceDuplicateSelection() {
|
|
8
|
-
const isExistenceDuplicateSelection = (options) => {
|
|
9
|
-
const { data, key, message = "存在重复项,请勿重复选择" } = options;
|
|
10
|
-
return new Promise((resolve) => {
|
|
11
|
-
if (uniqBy(data, key).length !== data.length) {
|
|
12
|
-
antdMessage.error(message);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
resolve();
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
return { isExistenceDuplicateSelection };
|
|
20
|
-
}
|
|
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};
|
package/hooks/useTable/index.js
CHANGED
|
@@ -1,113 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import useUrlQueryCriteria from "../useUrlQueryCriteria";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 获取数据
|
|
6
|
-
*/
|
|
7
|
-
function getService(service, getExtraParams = {}, transform, usePermission) {
|
|
8
|
-
// 获取额外的参数
|
|
9
|
-
const extraParams = (typeof getExtraParams === "function" ? getExtraParams() : getExtraParams) || {};
|
|
10
|
-
// 获取数据
|
|
11
|
-
return async ({ current, pageSize }, formData = {}) => {
|
|
12
|
-
// 如果提供了 transform 函数,则在请求之前调用它
|
|
13
|
-
let transformedFormData = formData;
|
|
14
|
-
if (typeof transform === "function") {
|
|
15
|
-
const transformResult = transform(formData);
|
|
16
|
-
// 如果 transform 函数有返回值,则将其与原始表单数据合并,transform 的优先级更高
|
|
17
|
-
if (transformResult && typeof transformResult === "object") {
|
|
18
|
-
transformedFormData = { ...formData, ...transformResult };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const params = {
|
|
23
|
-
pageIndex: current,
|
|
24
|
-
pageSize,
|
|
25
|
-
...transformedFormData,
|
|
26
|
-
...extraParams,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (usePermission)
|
|
30
|
-
params.menuPath = window.location.pathname;
|
|
31
|
-
|
|
32
|
-
// 发起请求
|
|
33
|
-
const res = await service(params);
|
|
34
|
-
// 返回数据
|
|
35
|
-
return {
|
|
36
|
-
list: res.data || [],
|
|
37
|
-
total: res.totalCount || 0,
|
|
38
|
-
...res,
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 自定义 useTable,继承 ahooks 的 useAntdTable,根据需求进行扩展
|
|
45
|
-
*/
|
|
46
|
-
function useTable(service, options) {
|
|
47
|
-
if (!service) {
|
|
48
|
-
console.error("请传入 service")
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 获取额外参数和转换函数
|
|
53
|
-
const { params: extraParams, transform, ...restOptions } = options || {};
|
|
54
|
-
|
|
55
|
-
// 获取配置项
|
|
56
|
-
const {
|
|
57
|
-
useStorageQueryCriteria = true,
|
|
58
|
-
usePagination = true,
|
|
59
|
-
usePermission = true,
|
|
60
|
-
defaultType = "advance",
|
|
61
|
-
defaultCurrent = 1,
|
|
62
|
-
defaultPageSize = 20,
|
|
63
|
-
defaultPagination = { current: defaultCurrent, pageSize: defaultPageSize },
|
|
64
|
-
...restRestOptions
|
|
65
|
-
} = restOptions;
|
|
66
|
-
|
|
67
|
-
const { setUrlCriteriaQuery, getUrlCriteriaQuery } = useUrlQueryCriteria();
|
|
68
|
-
|
|
69
|
-
// 获取存储的查询条件
|
|
70
|
-
const storageQueryCriteriaSearchForm = useStorageQueryCriteria ? getUrlCriteriaQuery("searchFormKeys", "searchFormValues") : {};
|
|
71
|
-
const storageQueryCriteriaPagination = useStorageQueryCriteria && usePagination ? getUrlCriteriaQuery("paginationKeys", "paginationValues") : {};
|
|
72
|
-
|
|
73
|
-
// 确定实际使用的搜索表单和分页参数
|
|
74
|
-
const actualSearchForm = Object.keys(storageQueryCriteriaSearchForm).length > 0 ? storageQueryCriteriaSearchForm : {};
|
|
75
|
-
/** @type {{current: number, pageSize: number}} */
|
|
76
|
-
const actualPagination = usePagination ? Object.keys(storageQueryCriteriaPagination).length > 0 ? storageQueryCriteriaPagination : defaultPagination : {};
|
|
77
|
-
|
|
78
|
-
// 调用 ahooks 的 useAntdTable
|
|
79
|
-
const res = useAntdTable(
|
|
80
|
-
getService(service, extraParams, transform, usePermission),
|
|
81
|
-
{
|
|
82
|
-
...restRestOptions,
|
|
83
|
-
defaultParams: [actualPagination, actualSearchForm],
|
|
84
|
-
defaultType,
|
|
85
|
-
onSuccess: (data, params) => {
|
|
86
|
-
// 执行成功回调,为了保留 ahooks 的 onSuccess 回调
|
|
87
|
-
restOptions.onSuccess && restOptions.onSuccess(data, params);
|
|
88
|
-
// 存储查询条件和分页到 URL
|
|
89
|
-
useStorageQueryCriteria && setUrlCriteriaQuery(
|
|
90
|
-
params[1] ?? {},
|
|
91
|
-
usePagination
|
|
92
|
-
? { current: res.tableProps.pagination.current, pageSize: res.tableProps.pagination.pageSize }
|
|
93
|
-
: {},
|
|
94
|
-
);
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// 执行回调函数
|
|
100
|
-
restOptions.callback && restOptions.callback(res?.data?.list || [], res?.data || {});
|
|
101
|
-
|
|
102
|
-
// 返回结果
|
|
103
|
-
return {
|
|
104
|
-
...res,
|
|
105
|
-
tableProps: {
|
|
106
|
-
...res.tableProps,
|
|
107
|
-
pagination: usePagination ? { ...res.tableProps.pagination, showQuickJumper: true, showSizeChanger: true } : false,
|
|
108
|
-
},
|
|
109
|
-
getData: res.search.submit,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export default useTable;
|
|
1
|
+
import{useAntdTable as e}from"ahooks";import a from"../useUrlQueryCriteria/index.js";function t(t,r){if(!t)return void console.error("请传入 service");const{params:n,transform:o,...i}=r||{},{useStorageQueryCriteria:s=!0,usePagination:u=!0,usePermission:c=!0,defaultType:l="advance",defaultCurrent:p=1,defaultPageSize:g=20,defaultPagination:f={current:p,pageSize:g},...d}=i,{setUrlCriteriaQuery:m,getUrlCriteriaQuery:y}=a(),b=s?y("searchFormKeys","searchFormValues"):{},h=s&&u?y("paginationKeys","paginationValues"):{},P=Object.keys(b).length>0?b:{},S=u?Object.keys(h).length>0?h:f:{},z=e(function(e,a={},t,r){const n=("function"==typeof a?a():a)||{};return async({current:a,pageSize:o},i={})=>{let s=i;if("function"==typeof t){const e=t(i);e&&"object"==typeof e&&(s={...i,...e})}const u={pageIndex:a,pageSize:o,...s,...n};r&&(u.menuPath=window.location.pathname);const c=await e(u);return{list:c.data||[],total:c.totalCount||0,...c}}}(t,n,o,c),{...d,defaultParams:[S,P],defaultType:l,onSuccess:(e,a)=>{i.onSuccess&&i.onSuccess(e,a),s&&m(a[1]??{},u?{current:z.tableProps.pagination.current,pageSize:z.tableProps.pagination.pageSize}:{})}});return i.callback&&i.callback(z?.data?.list||[],z?.data||{}),{...z,tableProps:{...z.tableProps,pagination:!!u&&{...z.tableProps.pagination,showQuickJumper:!0,showSizeChanger:!0}},getData:z.search.submit}}export{t as default};
|
|
@@ -1,149 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { UPLOAD_FILE_PATH_ENUM, UPLOAD_FILE_TYPE_ENUM } from "../../enum/uploadFile/gwj";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 上传文件
|
|
7
|
-
*/
|
|
8
|
-
function useUploadFile(returnType = "object") {
|
|
9
|
-
// loading状态
|
|
10
|
-
const [loading, setLoading] = useState(false);
|
|
11
|
-
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
-
let requestCount = 0;
|
|
13
|
-
|
|
14
|
-
// 上传文件
|
|
15
|
-
const uploadFile = (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
|
-
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
const { files = [], single = true, params } = options;
|
|
29
|
-
|
|
30
|
-
if (!files) {
|
|
31
|
-
console.error("请传入 files");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (!Array.isArray(files)) {
|
|
35
|
-
console.error("请传入有效的 files");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (!params) {
|
|
39
|
-
console.error("请传入 options.params");
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (!params.type) {
|
|
43
|
-
console.error("请传入 options.params.type");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 检查type是否在UPLOAD_FILE_TYPE_ENUM中
|
|
48
|
-
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(params.type)) {
|
|
49
|
-
console.error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 根据type获取对应的path
|
|
54
|
-
const path = UPLOAD_FILE_PATH_ENUM[params.type];
|
|
55
|
-
if (!path) {
|
|
56
|
-
console.error(`未找到 type ${params.type} 对应的 path `);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 当single为false时,foreignKey是必需的
|
|
61
|
-
if (!single) {
|
|
62
|
-
if (!params.hasOwnProperty("foreignKey")) {
|
|
63
|
-
console.error("请传入 options.params.foreignKey");
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
// 如果 foreignKey 是 undefined,设置默认值为空字符串
|
|
67
|
-
if (params.foreignKey === undefined || params.foreignKey === null)
|
|
68
|
-
params.foreignKey = "";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 如果没有文件则直接返回
|
|
72
|
-
if (files.length === 0) {
|
|
73
|
-
requestCount--;
|
|
74
|
-
if (requestCount <= 0) {
|
|
75
|
-
setLoading(false);
|
|
76
|
-
}
|
|
77
|
-
resolve(
|
|
78
|
-
single
|
|
79
|
-
? { filePath: "" }
|
|
80
|
-
: { id: params.foreignKey },
|
|
81
|
-
);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const formData = new FormData();
|
|
86
|
-
|
|
87
|
-
// 将文件添加到formData中
|
|
88
|
-
files.forEach((f) => {
|
|
89
|
-
f.originFileObj && formData.append("files", f.originFileObj);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// 将额外携带的参数添加到formData中
|
|
93
|
-
Object.keys(params).forEach((key) => {
|
|
94
|
-
formData.append(key, params[key]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// 添加path参数
|
|
98
|
-
formData.append("path", path);
|
|
99
|
-
|
|
100
|
-
// 获取待上传的文件
|
|
101
|
-
const filesLength = formData.getAll("files").length;
|
|
102
|
-
|
|
103
|
-
// 如果没有文件则返回老文件
|
|
104
|
-
if (filesLength === 0) {
|
|
105
|
-
requestCount--;
|
|
106
|
-
if (requestCount <= 0) {
|
|
107
|
-
setLoading(false);
|
|
108
|
-
}
|
|
109
|
-
resolve(
|
|
110
|
-
single
|
|
111
|
-
? { filePath: files[0].filePath }
|
|
112
|
-
: { id: params.foreignKey },
|
|
113
|
-
);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 发送请求
|
|
118
|
-
request(
|
|
119
|
-
single ? "/basicInfo/imgFiles/save" : "/basicInfo/imgFiles/batchSave",
|
|
120
|
-
"post",
|
|
121
|
-
formData,
|
|
122
|
-
{ "Content-Type": "multipart/form-data" },
|
|
123
|
-
)
|
|
124
|
-
.then((res) => {
|
|
125
|
-
resolve(
|
|
126
|
-
single
|
|
127
|
-
? { filePath: res.data.filePath }
|
|
128
|
-
: { id: res.data.foreignKey },
|
|
129
|
-
);
|
|
130
|
-
})
|
|
131
|
-
.catch((err) => {
|
|
132
|
-
reject(err);
|
|
133
|
-
})
|
|
134
|
-
.finally(() => {
|
|
135
|
-
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
136
|
-
requestCount--;
|
|
137
|
-
if (requestCount <= 0) {
|
|
138
|
-
setLoading(false);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
if (returnType === "array")
|
|
145
|
-
return [loading, uploadFile];
|
|
146
|
-
return { loading, uploadFile };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export default useUploadFile;
|
|
1
|
+
import{request as e}from"@cqsjjb/jjb-common-lib/http";import{useState as r}from"react";import{UPLOAD_FILE_TYPE_ENUM as o,UPLOAD_FILE_PATH_ENUM as i}from"../../enum/uploadFile/gwj/index.js";function t(t="object"){const[n,a]=r(!1);let l=0;const s=r=>{if(r)return l++,l>0&&a(!0),new Promise((t,n)=>{const{files:s=[],single:f=!0,params:p}=r;if(!s)return void console.error("请传入 files");if(!Array.isArray(s))return void console.error("请传入有效的 files");if(!p)return void console.error("请传入 options.params");if(!p.type)return void console.error("请传入 options.params.type");if(!Object.values(o).includes(p.type))return void console.error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中");const c=i[p.type];if(!c)return void console.error(`未找到 type ${p.type} 对应的 path `);if(!f){if(!p.hasOwnProperty("foreignKey"))return void console.error("请传入 options.params.foreignKey");void 0!==p.foreignKey&&null!==p.foreignKey||(p.foreignKey="")}if(0===s.length)return l--,l<=0&&a(!1),void t(f?{filePath:""}:{id:p.foreignKey});const d=new FormData;if(s.forEach(e=>{e.originFileObj&&d.append("files",e.originFileObj)}),Object.keys(p).forEach(e=>{d.append(e,p[e])}),d.append("path",c),0===d.getAll("files").length)return l--,l<=0&&a(!1),void t(f?{filePath:s[0].filePath}:{id:p.foreignKey});e(f?"/basicInfo/imgFiles/save":"/basicInfo/imgFiles/batchSave","post",d,{"Content-Type":"multipart/form-data"}).then(e=>{t(f?{filePath:e.data.filePath}:{id:e.data.foreignKey})}).catch(e=>{n(e)}).finally(()=>{l--,l<=0&&a(!1)})});console.error("请传入 options")};return"array"===t?[n,s]:{loading:n,uploadFile:s}}export{t as default};
|
|
@@ -1,77 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 处理搜索条件缓存到 URL
|
|
5
|
-
*/
|
|
6
|
-
export default function useUrlQueryCriteria() {
|
|
7
|
-
const [state, setState] = useUrlState({
|
|
8
|
-
searchFormKeys: "",
|
|
9
|
-
searchFormValues: "",
|
|
10
|
-
paginationKeys: "",
|
|
11
|
-
paginationValues: "",
|
|
12
|
-
}, { navigateMode: "replace" });
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 将搜索表单项和分页参数缓存到 URL 中
|
|
16
|
-
*/
|
|
17
|
-
function setUrlCriteriaQuery(searchForm, pagination) {
|
|
18
|
-
// 将对象转换为键值对字符串格式
|
|
19
|
-
const getJoinString = (data) => {
|
|
20
|
-
const keys = [];
|
|
21
|
-
const values = [];
|
|
22
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
23
|
-
if (value) {
|
|
24
|
-
keys.push(key);
|
|
25
|
-
if (Array.isArray(value)) {
|
|
26
|
-
// 数组值使用方括号包裹,并用竖线分隔
|
|
27
|
-
values.push(`[${value.join("|")}]`);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
values.push(value);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return { keys: keys.join(","), values: values.join(",") };
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// 获取搜索表单和分页数据的键值对字符串
|
|
38
|
-
const searchFormData = getJoinString(searchForm);
|
|
39
|
-
const paginationData = getJoinString(pagination);
|
|
40
|
-
|
|
41
|
-
// 将数据存储到 URL 查询参数中
|
|
42
|
-
setState({
|
|
43
|
-
searchFormKeys: searchFormData.keys || undefined,
|
|
44
|
-
searchFormValues: searchFormData.values || undefined,
|
|
45
|
-
paginationKeys: paginationData.keys || undefined,
|
|
46
|
-
paginationValues: paginationData.values || undefined,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 从 URL 中获取缓存的查询参数
|
|
52
|
-
*/
|
|
53
|
-
function getUrlCriteriaQuery(keysStr, valuesStr) {
|
|
54
|
-
// 将键值字符串分割为数组
|
|
55
|
-
const keys = state[keysStr] ? state[keysStr].split(",") : [];
|
|
56
|
-
const values = state[valuesStr] ? state[valuesStr].split(",") : [];
|
|
57
|
-
|
|
58
|
-
// 构建结果对象
|
|
59
|
-
const resultMap = {};
|
|
60
|
-
keys.forEach((key, index) => {
|
|
61
|
-
if (values[index]) {
|
|
62
|
-
// 处理数组值(方括号包裹的值)
|
|
63
|
-
if (values[index].startsWith("[") && values[index].endsWith("]")) {
|
|
64
|
-
const arrayContent = values[index].substring(1, values[index].length - 1);
|
|
65
|
-
resultMap[key] = arrayContent ? arrayContent.split("|") : [];
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
// 处理普通值
|
|
69
|
-
resultMap[key] = values[index];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return resultMap;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return { setUrlCriteriaQuery, getUrlCriteriaQuery };
|
|
77
|
-
}
|
|
1
|
+
import s from"@ahooksjs/use-url-state";function e(){const[e,r]=s({searchFormKeys:"",searchFormValues:"",paginationKeys:"",paginationValues:""},{navigateMode:"replace"});return{setUrlCriteriaQuery:function(s,e){const t=s=>{const e=[],r=[];return Object.entries(s).forEach(([s,t])=>{t&&(e.push(s),Array.isArray(t)?r.push(`[${t.join("|")}]`):r.push(t))}),{keys:e.join(","),values:r.join(",")}},i=t(s),a=t(e);r({searchFormKeys:i.keys||void 0,searchFormValues:i.values||void 0,paginationKeys:a.keys||void 0,paginationValues:a.values||void 0})},getUrlCriteriaQuery:function(s,r){const t=e[s]?e[s].split(","):[],i=e[r]?e[r].split(","):[],a={};return t.forEach((s,e)=>{if(i[e])if(i[e].startsWith("[")&&i[e].endsWith("]")){const r=i[e].substring(1,i[e].length-1);a[s]=r?r.split("|"):[]}else a[s]=i[e]}),a}}}export{e as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zy-react-library",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "LiuJiaNan",
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
"node": ">=18.0.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
+
"build": "rollup -c",
|
|
24
|
+
"build:watch": "rollup -c -w",
|
|
25
|
+
"prepublishOnly": "npm run build",
|
|
26
|
+
"patch": "npm version patch",
|
|
27
|
+
"minor": "npm version minor",
|
|
28
|
+
"publish": "npm publish",
|
|
23
29
|
"postinstall": "echo 'Thanks for using our component library!'"
|
|
24
30
|
},
|
|
25
31
|
"dependencies": {
|
|
@@ -37,5 +43,16 @@
|
|
|
37
43
|
"react": "^18.3.1",
|
|
38
44
|
"react-pdf": "^10.2.0",
|
|
39
45
|
"react-signature-canvas": "^1.1.0-alpha.2"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@babel/core": "^7.28.5",
|
|
49
|
+
"@babel/preset-react": "^7.28.5",
|
|
50
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
51
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
52
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
53
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
54
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
55
|
+
"glob": "^13.0.0",
|
|
56
|
+
"rollup": "^4.54.0"
|
|
40
57
|
}
|
|
41
58
|
}
|
package/regular/index.js
CHANGED
|
@@ -1,61 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 匹配中国手机号码,可包含国家代码86,支持各种运营商号段。
|
|
3
|
-
*/
|
|
4
|
-
export const PHONE
|
|
5
|
-
= /^(?:(?:\+|00)86)?1(?:3\d|4[5-7|9]|5[0-3|5-9]|6[5-7]|7[0-8]|8\d|9[1|89])\d{8}$/;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 匹配中国大陆的统一社会信用代码。
|
|
9
|
-
*/
|
|
10
|
-
export const UNIFIED_SOCIAL_CREDIT_CODE
|
|
11
|
-
= /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 匹配中国大陆的身份证号码,包括15位和18位号码,并验证最后一位校验码。
|
|
15
|
-
*/
|
|
16
|
-
export const ID_NUMBER
|
|
17
|
-
= /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[12]\d|30|31)\d{3}[\dX]$/i;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 匹配中国大陆的移动电话号码,不包含国家代码。
|
|
21
|
-
*/
|
|
22
|
-
export const MOBILE_PHONE
|
|
23
|
-
= /^(13\d|14[579]|15[0-3,5-9]|166|17[0135-8]|18\d|19[89])\d{8}$/;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 匹配浮点数,允许整数、一位或两位小数,以及零的情况。
|
|
27
|
-
*/
|
|
28
|
-
export const FLOATING_POINT_NUMBER
|
|
29
|
-
= /(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0)$)|(^\d\.\d(\d)?$)/;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 两位小数。
|
|
33
|
-
*/
|
|
34
|
-
export const TWO_DECIMAL_PLACES = /^\d+\.\d{2}$/;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 一位小数(非必须)。
|
|
38
|
-
*/
|
|
39
|
-
export const ONE_DECIMAL_PLACES = /^\d+(\.\d?)?$/;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 匹配中国大陆的车牌号码。
|
|
43
|
-
*/
|
|
44
|
-
export const LICENSE_PLATE_NUMBER
|
|
45
|
-
= /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z][A-Z0-9]{4}[A-Z0-9挂学警港澳])$/;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 匹配强密码,要求至少8个字符,包含大小写字母、数字和特殊字符。
|
|
49
|
-
*/
|
|
50
|
-
export const STRONG_PASSWORD
|
|
51
|
-
= /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d]).{8,}$/;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 匹配完整的HTML标签,包括开始标签和结束标签。
|
|
55
|
-
*/
|
|
56
|
-
export const HTML_TAG = /<[^>]*>/g;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 匹配中国大陆的邮政编码。
|
|
60
|
-
*/
|
|
61
|
-
export const POSTAL_CODE = /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/g;
|
|
1
|
+
const d=/^(?:(?:\+|00)86)?1(?:3\d|4[5-7|9]|5[0-3|5-9]|6[5-7]|7[0-8]|8\d|9[1|89])\d{8}$/,$=/^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/,A=/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[12]\d|30|31)\d{3}[\dX]$/i,Z=/^(13\d|14[579]|15[0-3,5-9]|166|17[0135-8]|18\d|19[89])\d{8}$/,X=/(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0)$)|(^\d\.\d(\d)?$)/,a=/^\d+\.\d{2}$/,g=/^\d+(\.\d?)?$/,o=/^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z][A-Z0-9]{4}[A-Z0-9挂学警港澳])$/,t=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d]).{8,}$/,z=/<[^>]*>/g,H=/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/g;export{X as FLOATING_POINT_NUMBER,z as HTML_TAG,A as ID_NUMBER,o as LICENSE_PLATE_NUMBER,Z as MOBILE_PHONE,g as ONE_DECIMAL_PLACES,d as PHONE,H as POSTAL_CODE,t as STRONG_PASSWORD,a as TWO_DECIMAL_PLACES,$ as UNIFIED_SOCIAL_CREDIT_CODE};
|