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.
Files changed (75) hide show
  1. package/README.md +5 -1
  2. package/components/Cascader/Area/index.js +1 -20
  3. package/components/Cascader/Basic/index.js +1 -64
  4. package/components/Cascader/Dictionary/index.js +1 -42
  5. package/components/Cascader/Industry/index.js +1 -20
  6. package/components/Editor/index.js +1 -102
  7. package/components/FormBuilder/FormBuilder.js +1 -87
  8. package/components/FormBuilder/FormItemsRenderer.js +1 -591
  9. package/components/FormBuilder/index.js +1 -3
  10. package/components/HeaderBack/index.js +1 -37
  11. package/components/HiddenInfo/gwj/index.js +1 -518
  12. package/components/Icon/AddIcon/index.js +1 -9
  13. package/components/Icon/BackIcon/index.js +1 -9
  14. package/components/Icon/DeleteIcon/index.js +1 -9
  15. package/components/Icon/DownloadIcon/index.js +1 -9
  16. package/components/Icon/EditIcon/index.js +1 -9
  17. package/components/Icon/ExportIcon/index.js +1 -9
  18. package/components/Icon/ImportIcon/index.js +1 -9
  19. package/components/Icon/LocationIcon/index.js +1 -9
  20. package/components/Icon/PrintIcon/index.js +1 -9
  21. package/components/Icon/ResetIcon/index.js +1 -9
  22. package/components/Icon/SearchIcon/index.js +1 -9
  23. package/components/Icon/VideoIcon/index.js +1 -9
  24. package/components/Icon/ViewIcon/index.js +1 -9
  25. package/components/ImportFile/index.js +1 -91
  26. package/components/LeftTree/Area/index.js +1 -15
  27. package/components/LeftTree/Basic/index.js +1 -171
  28. package/components/LeftTree/Department/Gwj/index.js +1 -32
  29. package/components/LeftTree/Dictionary/index.js +1 -42
  30. package/components/Map/MapSelector.js +1 -254
  31. package/components/Map/index.js +1 -77
  32. package/components/Page/index.js +1 -50
  33. package/components/Pdf/index.js +1 -134
  34. package/components/PreviewImg/index.js +1 -32
  35. package/components/PreviewPdf/index.js +1 -86
  36. package/components/Search/index.js +1 -141
  37. package/components/Select/Basic/index.js +1 -76
  38. package/components/Select/Dictionary/index.js +1 -42
  39. package/components/Select/Personnel/Gwj/index.js +1 -49
  40. package/components/SelectCreate/index.js +1 -55
  41. package/components/SelectTree/Area/index.js +1 -26
  42. package/components/SelectTree/Basic/index.js +1 -102
  43. package/components/SelectTree/Department/Gwj/index.js +1 -46
  44. package/components/SelectTree/Dictionary/index.js +1 -42
  45. package/components/SelectTree/HiddenLevel/Gwj/index.js +1 -72
  46. package/components/SelectTree/HiddenPart/Gwj/index.js +1 -39
  47. package/components/SelectTree/Industry/index.js +1 -27
  48. package/components/Signature/index.js +1 -94
  49. package/components/Table/index.js +1 -73
  50. package/components/Table/index.less +7 -1
  51. package/components/TooltipPreviewImg/index.js +1 -27
  52. package/components/Upload/index.js +1 -275
  53. package/components/Video/AliPlayer.js +1 -160
  54. package/components/Video/index.js +1 -90
  55. package/css/common.less +4 -0
  56. package/enum/dictionary/index.js +1 -7
  57. package/enum/formItemRender/index.js +1 -37
  58. package/enum/hidden/gwj/index.js +1 -31
  59. package/enum/uploadFile/gwj/index.js +1 -176
  60. package/hooks/useDeleteFile/index.js +1 -101
  61. package/hooks/useDictionary/index.js +1 -66
  62. package/hooks/useDownloadBlob/index.js +1 -79
  63. package/hooks/useDownloadFile/index.js +1 -81
  64. package/hooks/useGetFile/index.js +1 -74
  65. package/hooks/useGetUrlQuery/index.js +1 -16
  66. package/hooks/useGetUserInfo/index.js +1 -49
  67. package/hooks/useIdle/index.js +1 -67
  68. package/hooks/useImportFile/index.js +1 -59
  69. package/hooks/useIsExistenceDuplicateSelection/index.js +1 -20
  70. package/hooks/useTable/index.js +1 -113
  71. package/hooks/useUploadFile/index.js +1 -149
  72. package/hooks/useUrlQueryCriteria/index.js +1 -77
  73. package/package.json +18 -1
  74. package/regular/index.js +1 -61
  75. package/utils/index.js +1 -587
@@ -1,77 +1 @@
1
- import { Button, Col, Form, Input, Row } from "antd";
2
- import { useState } from "react";
3
- import MapSelector from "./MapSelector";
4
-
5
- /**
6
- * 定位组件
7
- */
8
- const Map = (props) => {
9
- const {
10
- longitudeProps = "longitude",
11
- latitudeProps = "latitude",
12
- onConfirm,
13
- required = true,
14
- area = "",
15
- showArea = false,
16
- } = props;
17
-
18
- const form = Form.useFormInstance();
19
- const [mapVisible, setMapVisible] = useState(false);
20
- const [currentLongitude, setCurrentLongitude] = useState("");
21
- const [currentLatitude, setCurrentLatitude] = useState("");
22
-
23
- const handleMapConfirm = (longitudeValue, latitudeValue, extra) => {
24
- setCurrentLongitude(longitudeValue);
25
- setCurrentLatitude(latitudeValue);
26
- form.setFieldsValue({
27
- [longitudeProps]: longitudeValue,
28
- [latitudeProps]: latitudeValue,
29
- });
30
- onConfirm?.(longitudeValue, latitudeValue, extra);
31
- setMapVisible(false);
32
- };
33
-
34
- return (
35
- <>
36
- <Row gutter={24}>
37
- <Col span={12}>
38
- <Form.Item label="经度" name={longitudeProps} rules={[{ required, message: "请选择经度" }]}>
39
- <Input disabled />
40
- </Form.Item>
41
- </Col>
42
- <Col span={12}>
43
- <Form.Item label="纬度" required={required}>
44
- <div style={{ display: "flex", gap: 10 }}>
45
- <Form.Item name={latitudeProps} noStyle rules={[{ required, message: "请选择纬度" }]}>
46
- <Input disabled />
47
- </Form.Item>
48
- <Button
49
- type="primary"
50
- onClick={() => {
51
- setMapVisible(true);
52
- setCurrentLongitude(form.getFieldValue(longitudeProps));
53
- setCurrentLatitude(form.getFieldValue(latitudeProps));
54
- }}
55
- >
56
- 地图定位
57
- </Button>
58
- </div>
59
- </Form.Item>
60
- </Col>
61
- </Row>
62
- <MapSelector
63
- visible={mapVisible}
64
- onClose={() => setMapVisible(false)}
65
- longitude={currentLongitude}
66
- latitude={currentLatitude}
67
- area={area}
68
- showArea={showArea}
69
- onConfirm={handleMapConfirm}
70
- />
71
- </>
72
- );
73
- };
74
-
75
- Map.displayName = "Map";
76
-
77
- export default Map;
1
+ import{Form as e,Row as r,Col as l,Input as i,Button as a}from"antd";import{useState as t}from"react";import d from"./MapSelector.js";import{jsxs as n,Fragment as o,jsx as s}from"react/jsx-runtime";const m=m=>{const{longitudeProps:u="longitude",latitudeProps:c="latitude",onConfirm:p,required:h=!0,area:g="",showArea:f=!1}=m,y=e.useFormInstance(),[b,q]=t(!1),[C,F]=t(""),[I,x]=t("");return n(o,{children:[n(r,{gutter:24,children:[s(l,{span:12,children:s(e.Item,{label:"经度",name:u,rules:[{required:h,message:"请选择经度"}],children:s(i,{disabled:!0})})}),s(l,{span:12,children:s(e.Item,{label:"纬度",required:h,children:n("div",{style:{display:"flex",gap:10},children:[s(e.Item,{name:c,noStyle:!0,rules:[{required:h,message:"请选择纬度"}],children:s(i,{disabled:!0})}),s(a,{type:"primary",onClick:()=>{q(!0),F(y.getFieldValue(u)),x(y.getFieldValue(c))},children:"地图定位"})]})})})]}),s(d,{visible:b,onClose:()=>q(!1),longitude:C,latitude:I,area:g,showArea:f,onConfirm:(e,r,l)=>{F(e),x(r),y.setFieldsValue({[u]:e,[c]:r}),p?.(e,r,l),q(!1)}})]})};m.displayName="Map";export{m as default};
@@ -1,50 +1 @@
1
- import { Button, Space } from "antd";
2
- import HeaderBack from "../HeaderBack";
3
-
4
- /**
5
- * 页面布局组件
6
- */
7
- function Page(props) {
8
- const {
9
- headerTitle,
10
- history,
11
- isShowHeader = true,
12
- headerPrevious = true,
13
- isShowFooter = true,
14
- isShowAllAction = true,
15
- backButtonText = "关闭",
16
- contentPadding = "20px",
17
- customActionButtons,
18
- extraActionButtons,
19
- } = props;
20
-
21
- return (
22
- <div className="page">
23
- {(isShowAllAction && isShowHeader) && <HeaderBack title={headerTitle} history={history} previous={headerPrevious} />}
24
- <div style={{ padding: contentPadding }}>
25
- {props.children}
26
- </div>
27
- {
28
- (isShowAllAction && isShowFooter) && (
29
- <>
30
- <div style={{ height: "52px" }}></div>
31
- <div style={{ textAlign: "center", backgroundColor: "rgb(241, 241, 242)", margin: "0 -20px", padding: "10px 0", position: "fixed", bottom: "0", width: "100%" }}>
32
- {customActionButtons || (
33
- <Space>
34
- {extraActionButtons}
35
- <Button onClick={() => history?.goBack?.() || window.history.back()}>
36
- {backButtonText}
37
- </Button>
38
- </Space>
39
- )}
40
- </div>
41
- </>
42
- )
43
- }
44
- </div>
45
- );
46
- }
47
-
48
- Page.displayName = "Page";
49
-
50
- export default Page;
1
+ import{Space as e,Button as t}from"antd";import{useState as i,useEffect as o}from"react";import r from"../HeaderBack/index.js";import{jsxs as n,jsx as d,Fragment as s}from"react/jsx-runtime";function a(a){const{headerTitle:c,history:l,isShowHeader:h=!0,headerPrevious:m=!0,isShowFooter:p=!0,isShowAllAction:u=!0,backButtonText:g="关闭",contentPadding:w="20px",customActionButtons:x,extraActionButtons:f}=a,[v,y]=i(window.innerWidth),k=()=>{const e=document.querySelector("#page");e&&y(e.offsetWidth)};return o(()=>{const e=setTimeout(()=>{k()},0);return window.addEventListener("resize",k),()=>{window.removeEventListener("resize",k),clearTimeout(e)}},[]),n("div",{className:"page",id:"page",children:[u&&h&&d(r,{title:c,history:l,previous:m}),d("div",{style:{padding:w},children:a.children}),u&&p&&n(s,{children:[d("div",{style:{height:"32px"}}),d("div",{style:{textAlign:"center",backgroundColor:"rgb(241, 241, 242)",padding:"10px 0",position:"fixed",bottom:"0",width:v,margin:"0px -44px"},children:x||n(e,{children:[f,d(t,{onClick:()=>l?.goBack?.()||window.history.back(),children:g})]})})]})]})}a.displayName="Page";export{a as default};
@@ -1,134 +1 @@
1
- import { useFullscreen } from "ahooks";
2
- import { Button, message, Modal, Spin } from "antd";
3
- import { useRef, useState } from "react";
4
- import { Document, Page, pdfjs } from "react-pdf";
5
- import useDownloadFile from "../../hooks/useDownloadFile";
6
- import { getFileUrl } from "../../utils";
7
- import "react-pdf/dist/Page/AnnotationLayer.css";
8
- import "react-pdf/dist/Page/TextLayer.css";
9
- import "./index.less";
10
-
11
- /**
12
- * PDF查看组件
13
- */
14
- function Pdf(props) {
15
- const {
16
- visible = false,
17
- onCancel,
18
- file,
19
- name,
20
- inline = false,
21
- style = {},
22
- } = props;
23
-
24
- const fileUrl = getFileUrl();
25
- const [numPages, setNumPages] = useState(0);
26
- const [pdfWidth, setPdfWidth] = useState(600);
27
- const [loading, setLoading] = useState(true);
28
-
29
- const fullscreenRef = useRef(null);
30
-
31
- const [isFullscreen, { enterFullscreen, exitFullscreen }] = useFullscreen(fullscreenRef);
32
- const { downloadFile } = useDownloadFile();
33
-
34
- pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
35
-
36
- const onDocumentLoadSuccess = ({ numPages }) => {
37
- setNumPages(numPages);
38
- setLoading(false);
39
- };
40
-
41
- const onDocumentLoadError = () => {
42
- setLoading(false);
43
- message.error("加载 PDF 文件失败");
44
- if (onCancel)
45
- onCancel();
46
- };
47
-
48
- const onPageLoadSuccess = ({ width }) => {
49
- setPdfWidth(width);
50
- };
51
-
52
- // 内联模式的PDF内容
53
- const renderPdfContent = () => (
54
- <>
55
- {loading && (
56
- <div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: "72vh" }}>
57
- <Spin size="large" />
58
- </div>
59
- )}
60
- <div style={{ height: isFullscreen ? "calc(100vh - 40px - 24px - 8px - 32px - 12px)" : "72vh", overflowY: "auto", padding: "24px", ...style }}>
61
- <Document
62
- file={!file.includes(fileUrl) ? fileUrl + file : file}
63
- onLoadSuccess={onDocumentLoadSuccess}
64
- onLoadError={onDocumentLoadError}
65
- >
66
- {
67
- Array.from({ length: numPages }).map((_, index) => (
68
- <Page key={`page_${index + 1}`} pageNumber={index + 1} onLoadSuccess={onPageLoadSuccess} />
69
- ))
70
- }
71
- </Document>
72
- </div>
73
- </>
74
- );
75
-
76
- // 如果是内联模式,直接返回PDF内容
77
- if (inline) {
78
- return renderPdfContent();
79
- }
80
-
81
- const onDownloadFile = () => {
82
- isFullscreen && exitFullscreen();
83
- downloadFile({
84
- url: file,
85
- name,
86
- });
87
- };
88
-
89
- // 默认弹窗模式
90
- return (
91
- <div ref={fullscreenRef}>
92
- <Modal
93
- style={{ top: isFullscreen ? 0 : 100, maxWidth: isFullscreen ? "100vw" : "calc(100vw - 32px)", paddingBottom: isFullscreen ? 0 : 24 }}
94
- open={visible}
95
- maskClosable={false}
96
- width={isFullscreen ? "100vw" : pdfWidth + 100}
97
- title="PDF预览"
98
- onCancel={() => {
99
- isFullscreen && exitFullscreen();
100
- onCancel();
101
- }}
102
- getContainer={false}
103
- footer={[
104
- <Button
105
- key="cancel"
106
- onClick={() => {
107
- isFullscreen && exitFullscreen();
108
- onCancel();
109
- }}
110
- >
111
- 关闭
112
- </Button>,
113
- !loading && (
114
- <Button
115
- key="fullScreen"
116
- onClick={() => {
117
- isFullscreen ? exitFullscreen() : enterFullscreen();
118
- }}
119
- >
120
- {isFullscreen ? "退出全屏" : "全屏"}
121
- </Button>
122
- ),
123
- <Button key="download" type="primary" onClick={onDownloadFile}>下载</Button>,
124
- ]}
125
- >
126
- {renderPdfContent()}
127
- </Modal>
128
- </div>
129
- );
130
- }
131
-
132
- Pdf.displayName = "Pdf";
133
-
134
- export default Pdf;
1
+ import{useFullscreen as e}from"ahooks";import{Modal as r,Button as o,Spin as i,message as n}from"antd";import{useState as t,useRef as l}from"react";import{pdfjs as a,Document as d,Page as s}from"react-pdf";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as p}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsxs as m,jsx as f,Fragment as h}from"react/jsx-runtime";function u(u){const{visible:x=!1,onCancel:g,file:v,name:y,inline:w=!1,style:k={}}=u,C=p(),[j,F]=t(0),[P,b]=t(600),[L,S]=t(!0),D=l(null),[A,{enterFullscreen:N,exitFullscreen:W}]=e(D),{downloadFile:$}=c();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.version}/build/pdf.worker.min.mjs`;const z=({numPages:e})=>{F(e),S(!1)},B=()=>{S(!1),n.error("加载 PDF 文件失败"),g&&g()},E=({width:e})=>{b(e)},G=()=>m(h,{children:[L&&f("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"72vh"},children:f(i,{size:"large"})}),f("div",{style:{height:A?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...k},children:f(d,{file:v.includes(C)?v:C+v,onLoadSuccess:z,onLoadError:B,children:Array.from({length:j}).map((e,r)=>f(s,{pageNumber:r+1,onLoadSuccess:E},`page_${r+1}`))})})]});return w?G():f("div",{ref:D,children:f(r,{style:{top:A?0:100,maxWidth:A?"100vw":"calc(100vw - 32px)",paddingBottom:A?0:24},open:x,maskClosable:!1,width:A?"100vw":P+100,title:"PDF预览",onCancel:()=>{A&&W(),g()},getContainer:!1,footer:[f(o,{onClick:()=>{A&&W(),g()},children:"关闭"},"cancel"),!L&&f(o,{onClick:()=>{A?W():N()},children:A?"退出全屏":"全屏"},"fullScreen"),f(o,{type:"primary",onClick:()=>{A&&W(),$({url:v,name:y})},children:"下载"},"download")],children:G()})})}u.displayName="Pdf";export{u as default};
@@ -1,32 +1 @@
1
- import { Image } from "antd";
2
- import { getFileUrl } from "../../utils/index";
3
-
4
- /**
5
- * 在查看页面中图片预览组件
6
- */
7
- const PreviewImg = (props) => {
8
- const { files = [], fileUrlKey = "filePath" } = props;
9
-
10
- const fileUrl = getFileUrl();
11
-
12
- return (
13
- <Image.PreviewGroup>
14
- {
15
- files.filter(Boolean).map(item => (
16
- <Image
17
- key={item[fileUrlKey] || item}
18
- src={item[fileUrlKey] ? fileUrl + item[fileUrlKey] : fileUrl + item}
19
- wrapperStyle={{ marginRight: 10, marginBottom: 10 }}
20
- width={100}
21
- height={100}
22
- alt=""
23
- />
24
- ))
25
- }
26
- </Image.PreviewGroup>
27
- );
28
- };
29
-
30
- PreviewImg.displayName = "PreviewImg";
31
-
32
- export default PreviewImg;
1
+ import{Image as r}from"antd";import{getFileUrl as e}from"../../utils/index.js";import{jsx as t}from"react/jsx-runtime";const i=i=>{const{files:o=[],fileUrlKey:a="filePath"}=i,m=e();return t(r.PreviewGroup,{children:o.filter(Boolean).map(e=>t(r,{src:e[a]?m+e[a]:m+e,wrapperStyle:{marginRight:10,marginBottom:10},width:100,height:100,alt:""},e[a]||e))})};i.displayName="PreviewImg";export{i as default};
@@ -1,86 +1 @@
1
- import { Button, Space } from "antd";
2
- import { useState } from "react";
3
- import Pdf from "../Pdf";
4
-
5
- /**
6
- * 在查看页面中PDF查看组件
7
- */
8
- const PreviewPdf = (props) => {
9
- const {
10
- files = [],
11
- nameKey = "",
12
- urlKey = "",
13
- name = "",
14
- url = "",
15
- } = props;
16
-
17
- const [visible, setVisible] = useState(false);
18
- const [currentSrc, setCurrentSrc] = useState("");
19
- const [currentName, setCurrentName] = useState("");
20
-
21
- const previewPdf = (src, name) => {
22
- setVisible(true);
23
- setCurrentSrc(src);
24
- setCurrentName(name);
25
- };
26
-
27
- const onCancel = () => {
28
- setVisible(false);
29
- setCurrentSrc("");
30
- setCurrentName("");
31
- };
32
-
33
- // 单个文件预览模式
34
- if (files.length === 0 && name && url) {
35
- return (
36
- <>
37
- <Space>
38
- <span>{name}</span>
39
- <Button type="primary" size="small" onClick={() => previewPdf(url, name)}>
40
- 预览
41
- </Button>
42
- </Space>
43
- <Pdf
44
- visible={visible}
45
- file={currentSrc}
46
- name={currentName}
47
- onCancel={onCancel}
48
- />
49
- </>
50
- );
51
- }
52
-
53
- // 多文件预览模式
54
- if (files.length > 0 && !name && !url) {
55
- return (
56
- <>
57
- {files.map(item => (
58
- <div key={item.filePath || item[urlKey]} style={{ marginTop: 5 }}>
59
- <Space>
60
- <span>{item.name || item.fileName || item[nameKey]}</span>
61
- <Button
62
- type="primary"
63
- size="small"
64
- onClick={() => previewPdf(item.filePath || item[urlKey], item.name || item.fileName || item[nameKey])}
65
- >
66
- 预览
67
- </Button>
68
- </Space>
69
- </div>
70
- ))}
71
- <Pdf
72
- visible={visible}
73
- file={currentSrc}
74
- name={currentName}
75
- onCancel={onCancel}
76
- />
77
- </>
78
- );
79
- }
80
-
81
- return null;
82
- };
83
-
84
- PreviewPdf.displayName = "PreviewPdf";
85
-
86
- export default PreviewPdf;
1
+ import{Space as e,Button as i}from"antd";import{useState as l}from"react";import n from"../Pdf/index.js";import{jsxs as r,Fragment as a,jsx as m}from"react/jsx-runtime";const t=t=>{const{files:c=[],nameKey:d="",urlKey:o="",name:s="",url:f=""}=t,[p,h]=l(!1),[y,u]=l(""),[P,v]=l(""),C=(e,i)=>{h(!0),u(e),v(i)},g=()=>{h(!1),u(""),v("")};return 0===c.length&&s&&f?r(a,{children:[r(e,{children:[m("span",{children:s}),m(i,{type:"primary",size:"small",onClick:()=>C(f,s),children:"预览"})]}),m(n,{visible:p,file:y,name:P,onCancel:g})]}):c.length>0&&!s&&!f?r(a,{children:[c.map(l=>m("div",{style:{marginTop:5},children:r(e,{children:[m("span",{children:l.name||l.fileName||l[d]}),m(i,{type:"primary",size:"small",onClick:()=>C(l.filePath||l[o],l.name||l.fileName||l[d]),children:"预览"})]})},l.filePath||l[o])),m(n,{visible:p,file:y,name:P,onCancel:g})]}):null};t.displayName="PreviewPdf";export{t as default};
@@ -1,141 +1 @@
1
- import { DownOutlined, UpOutlined } from "@ant-design/icons";
2
- import { Button, Col, Form, Row } from "antd";
3
- import { useEffect, useRef, useState } from "react";
4
- import FormItemsRenderer from "../FormBuilder/FormItemsRenderer";
5
- import ResetIcon from "../Icon/ResetIcon";
6
- import SearchIcon from "../Icon/SearchIcon";
7
-
8
- /**
9
- * 搜索表单组件
10
- */
11
- const Search = (props) => {
12
- const {
13
- labelCol = { span: 6 },
14
- options = [],
15
- values = {},
16
- onFinish,
17
- onSubmit,
18
- onReset,
19
- searchText = "搜索",
20
- resetText = "重置",
21
- showSearchButton = true,
22
- showResetButton = true,
23
- extraButtons,
24
- form,
25
- ...restProps
26
- } = props;
27
-
28
- const [collapse, setCollapse] = useState(true);
29
- const [span, setSpan] = useState(6);
30
- const [showCollapseButton, setShowCollapseButton] = useState(false);
31
- const classNameRef = useRef(`search-${Date.now()}`);
32
-
33
- // 计算是否需要显示展开/收起按钮
34
- useEffect(() => {
35
- if (!options || options.length === 0)
36
- return;
37
-
38
- const calculateLayout = () => {
39
- const colEl = document.querySelectorAll(
40
- `.${classNameRef.current}>.${window.process.env.app.antd["ant-prefix"]}-col`,
41
- );
42
- const colElLength = colEl.length;
43
- const excludeLast = colElLength - (extraButtons ? 2 : 1);
44
-
45
- const spanMap = { 0: 24, 1: 18, 2: 12, 3: 6 };
46
- setSpan(spanMap[excludeLast % 4] || 6);
47
-
48
- setShowCollapseButton(excludeLast > 3);
49
- };
50
-
51
- // 延迟执行以确保 DOM 已渲染
52
- setTimeout(calculateLayout, 0);
53
- }, [options, extraButtons]);
54
-
55
- // 处理表单提交
56
- const handleSubmit = () => {
57
- const values = form.getFieldsValue();
58
- onFinish?.(values, "submit");
59
- onSubmit?.(values);
60
- };
61
-
62
- // 处理重置
63
- const handleReset = () => {
64
- // form.resetFields();
65
- // const values = form.getFieldsValue();
66
- // onFinish?.(values, "reset");
67
- // onReset?.(values);
68
-
69
- const currentValues = form.getFieldsValue();
70
- const resetValues = {};
71
- Object.keys(currentValues).forEach((key) => {
72
- resetValues[key] = values.hasOwnProperty(key) ? values[key] : undefined;
73
- });
74
-
75
- form.setFieldsValue(resetValues);
76
- onFinish?.(values, "reset");
77
- onReset?.(values);
78
- };
79
-
80
- // 切换展开/收起
81
- const toggleCollapse = () => {
82
- setCollapse(!collapse);
83
- };
84
-
85
- return (
86
- <div className="search-layout card-layout">
87
- <Form
88
- form={form}
89
- labelCol={labelCol}
90
- initialValues={values}
91
- {...restProps}
92
- >
93
- <Row className={classNameRef.current}>
94
- <FormItemsRenderer
95
- options={options}
96
- labelCol={labelCol}
97
- span={6}
98
- collapse={collapse}
99
- useAutoGenerateRequired={false}
100
- initialValues={values}
101
- />
102
- <Col span={showCollapseButton ? (collapse ? 6 : span) : span}>
103
- <Form.Item label=" " labelCol={{ span: 2 }} colon={false} style={{ textAlign: "right" }}>
104
- {showSearchButton && (
105
- <Button type="primary" icon={<SearchIcon />} onClick={handleSubmit}>
106
- {searchText}
107
- </Button>
108
- )}
109
- {showResetButton && (
110
- <Button style={{ marginLeft: 8 }} icon={<ResetIcon />} onClick={handleReset}>
111
- {resetText}
112
- </Button>
113
- )}
114
- {showCollapseButton && (
115
- <Button
116
- type="link"
117
- icon={collapse ? <DownOutlined /> : <UpOutlined />}
118
- onClick={toggleCollapse}
119
- style={{ marginLeft: 8 }}
120
- >
121
- {collapse ? "展开" : "收起"}
122
- </Button>
123
- )}
124
- </Form.Item>
125
- </Col>
126
- {extraButtons && (
127
- <Col span={24}>
128
- <Form.Item label=" " colon={false} labelCol={{ span: 0 }}>
129
- {extraButtons}
130
- </Form.Item>
131
- </Col>
132
- )}
133
- </Row>
134
- </Form>
135
- </div>
136
- );
137
- };
138
-
139
- Search.displayName = "Search";
140
-
141
- export default Search;
1
+ import{DownOutlined as e,UpOutlined as t}from"@ant-design/icons";import{Form as o,Row as n,Col as l,Button as r}from"antd";import{useState as i,useRef as s,useEffect as a}from"react";import c from"../FormBuilder/FormItemsRenderer.js";import m from"../Icon/ResetIcon/index.js";import d from"../Icon/SearchIcon/index.js";import{jsx as p,jsxs as u}from"react/jsx-runtime";const h=h=>{const{labelCol:f={span:6},options:y=[],values:b={},onFinish:g,onSubmit:x,onReset:C,searchText:I="搜索",resetText:w="重置",showSearchButton:F=!0,showResetButton:j=!0,extraButtons:k,form:R,...S}=h,[V,v]=i(!0),[B,A]=i(6),[N,T]=i(!1),$=s(`search-${Date.now()}`);return a(()=>{y&&0!==y.length&&setTimeout(()=>{const e=document.querySelectorAll(`.${$.current}>.${window.process.env.app.antd["ant-prefix"]}-col`).length-(k?2:1);A({0:24,1:18,2:12,3:6}[e%4]||6),T(e>3)},0)},[y,k]),p("div",{className:"search-layout card-layout",children:p(o,{form:R,labelCol:f,initialValues:b,...S,children:u(n,{className:$.current,children:[p(c,{options:y,labelCol:f,span:6,collapse:V,useAutoGenerateRequired:!1,initialValues:b}),p(l,{span:N&&V?6:B,children:u(o.Item,{label:" ",labelCol:{span:2},colon:!1,style:{textAlign:"right"},children:[F&&p(r,{type:"primary",icon:p(d,{}),onClick:()=>{const e=R.getFieldsValue();g?.(e,"submit"),x?.(e)},children:I}),j&&p(r,{style:{marginLeft:8},icon:p(m,{}),onClick:()=>{const e=R.getFieldsValue(),t={};Object.keys(e).forEach(e=>{t[e]=b.hasOwnProperty(e)?b[e]:void 0}),R.setFieldsValue(t),g?.(b,"reset"),C?.(b)},children:w}),N&&p(r,{type:"link",icon:p(V?e:t,{}),onClick:()=>{v(!V)},style:{marginLeft:8},children:V?"展开":"收起"})]})}),k&&p(l,{span:24,children:p(o.Item,{label:" ",colon:!1,labelCol:{span:0},children:k})})]})})})};h.displayName="Search";export{h as default};
@@ -1,76 +1 @@
1
- import { Select } from "antd";
2
- import { useEffect } from "react";
3
-
4
- /**
5
- * 基础下拉组件(不建议直接使用此组件,二次继承使用)
6
- */
7
- function BasicSelect(props) {
8
- const {
9
- onGetData,
10
- onChange,
11
- onGetLabel,
12
- onGetOption,
13
- placeholder = "",
14
- data = [],
15
- nameKey = "name",
16
- idKey = "id",
17
- labelRender,
18
- ...restProps
19
- } = props;
20
-
21
- const handleChange = (event, option) => {
22
- if (Array.isArray(event)) {
23
- if (event.length > 0) {
24
- const findItems = [];
25
- const names = [];
26
- event.forEach((item) => {
27
- const findItem = data.find(dataItem => dataItem[idKey] === item);
28
- if (findItem) {
29
- findItems.push(findItem);
30
- names.push(findItem[nameKey]);
31
- }
32
- });
33
- onGetLabel?.(names);
34
- onGetOption?.(findItems);
35
- }
36
- else {
37
- onGetLabel?.([]);
38
- onGetOption?.([]);
39
- }
40
- }
41
- else {
42
- if (event) {
43
- const findItem = data.find(item => item[idKey] === event);
44
- onGetLabel?.(findItem[nameKey]);
45
- onGetOption?.(findItem);
46
- }
47
- else {
48
- onGetLabel?.("");
49
- onGetOption?.({});
50
- }
51
- }
52
- onChange?.(event, option);
53
- };
54
-
55
- useEffect(() => {
56
- onGetData?.(data);
57
- }, [data]);
58
-
59
- return (
60
- <Select placeholder={`请选择${placeholder}`} showSearch allowClear optionFilterProp="children" onChange={handleChange} {...restProps}>
61
- {data.map((item) => {
62
- const value = item[idKey];
63
- const label = labelRender ? labelRender(item) : item[nameKey];
64
- return (
65
- <Select.Option key={value} value={value}>
66
- {label}
67
- </Select.Option>
68
- );
69
- })}
70
- </Select>
71
- );
72
- }
73
-
74
- BasicSelect.displayName = "BasicSelect";
75
-
76
- export default BasicSelect;
1
+ import{Select as e}from"antd";import{useEffect as n}from"react";import{jsx as r}from"react/jsx-runtime";function a(a){const{onGetData:o,onChange:t,onGetLabel:i,onGetOption:l,placeholder:c="",data:s=[],nameKey:d="name",idKey:p="id",labelRender:h,...f}=a;return n(()=>{o?.(s)},[s]),r(e,{placeholder:`请选择${c}`,showSearch:!0,allowClear:!0,optionFilterProp:"children",onChange:(e,n)=>{if(Array.isArray(e))if(e.length>0){const n=[],r=[];e.forEach(e=>{const a=s.find(n=>n[p]===e);a&&(n.push(a),r.push(a[d]))}),i?.(r),l?.(n)}else i?.([]),l?.([]);else if(e){const n=s.find(n=>n[p]===e);i?.(n[d]),l?.(n)}else i?.(""),l?.({});t?.(e,n)},...f,children:s.map(n=>{const a=n[p],o=h?h(n):n[d];return r(e.Option,{value:a,children:o},a)})})}a.displayName="BasicSelect";export{a as default};
@@ -1,42 +1 @@
1
- import { request } from "@cqsjjb/jjb-common-lib/http";
2
- import { useEffect, useState } from "react";
3
- import { DICTIONARY_APP_KEY_ENUM } from "../../../enum/dictionary";
4
- import BasicSelect from "../Basic";
5
-
6
- /**
7
- * 数据字典下拉组件
8
- */
9
- function DictionarySelect(props) {
10
- const {
11
- appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT,
12
- dictValue = "",
13
- nameKey = "dictLabel",
14
- idKey = "dictValue",
15
- ...restProps
16
- } = props;
17
-
18
- const [data, setData] = useState([]);
19
-
20
- const getData = async () => {
21
- if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
22
- console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
23
- return;
24
- }
25
-
26
- setData([]);
27
- const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });
28
- setData(data);
29
- };
30
-
31
- useEffect(() => {
32
- dictValue && getData();
33
- }, [dictValue]);
34
-
35
- return (
36
- <BasicSelect data={data} nameKey={nameKey} idKey={idKey} {...restProps} />
37
- );
38
- }
39
-
40
- DictionarySelect.displayName = "DictionarySelect";
41
-
42
- export default DictionarySelect;
1
+ import{request as e}from"@cqsjjb/jjb-common-lib/http";import{useState as t,useEffect as i}from"react";import{DICTIONARY_APP_KEY_ENUM as a}from"../../../enum/dictionary/index.js";import r from"../Basic/index.js";import{jsx as o}from"react/jsx-runtime";function c(c){const{appKey:n=a.DEFAULT,dictValue:d="",nameKey:m="dictLabel",idKey:s="dictValue",...p}=c,[l,u]=t([]);return i(()=>{d&&(async()=>{if(!Object.values(a).includes(n))return void console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");u([]);const{data:t}=await e("/config/dict-trees/list/by/dictValues","get",{appKey:n,dictValue:d});u(t)})()},[d]),o(r,{data:l,nameKey:m,idKey:s,...p})}c.displayName="DictionarySelect";export{c as default};