@hw-component/form 1.8.1 → 1.8.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/.eslintcache +1 -1
- package/.stylelintrc.js +6 -2
- package/es/Form/Basic.d.ts +1 -1
- package/es/Form/Basic.js +4 -2
- package/es/Form/index.d.ts +1 -1
- package/es/Form/index.js +3 -1
- package/es/Form/modal.d.ts +1 -0
- package/es/config.js +12 -3
- package/es/index.css +3 -3
- package/es/index.d.ts +1 -1
- package/lib/Form/Basic.d.ts +1 -1
- package/lib/Form/Basic.js +4 -2
- package/lib/Form/index.d.ts +1 -1
- package/lib/Form/index.js +3 -1
- package/lib/Form/modal.d.ts +1 -0
- package/lib/config.js +12 -3
- package/lib/index.css +3 -3
- package/lib/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/Form/Basic.tsx +55 -43
- package/src/components/Form/FormItem/BasicItem.tsx +7 -2
- package/src/components/Form/FormItem/hooks.tsx +3 -3
- package/src/components/Form/FormItem/index.tsx +13 -12
- package/src/components/Form/index.less +2 -2
- package/src/components/Form/index.tsx +15 -14
- package/src/components/Form/modal.ts +3 -2
- package/src/components/Input/InputNumberGroup.tsx +8 -8
- package/src/components/Input/index.less +4 -6
- package/src/components/Select/hooks/changeHooks.tsx +31 -29
- package/src/components/Select/hooks/norHooks.ts +1 -1
- package/src/components/Upload/UrlUpload/index.tsx +1 -1
- package/src/components/config.ts +12 -3
- package/src/components/index.tsx +1 -1
- package/src/pages/Form/index.tsx +61 -83
- package/src/pages/Input/index.tsx +7 -5
- package/src/pages/Select/index.tsx +16 -12
- package/src/pages/Upload/index.tsx +1 -2
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
@import "../styles/local.less";
|
|
2
2
|
@all-input-group: ~"@{ant-prefix}-hw-input-group";
|
|
3
3
|
|
|
4
|
-
.@{all-input-group} {
|
|
5
|
-
.@{all-input-group}-disabled {
|
|
6
|
-
background-color: #f5f5f5;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
4
|
.@{all-input-group} {
|
|
10
5
|
display: flex !important;
|
|
11
6
|
width: 100%;
|
|
12
7
|
color: rgba(0, 0, 0, 0.25);
|
|
8
|
+
.@{all-input-group}-disabled {
|
|
9
|
+
background-color: #f5f5f5;
|
|
10
|
+
}
|
|
13
11
|
.@{all-input-group}-body {
|
|
14
12
|
position: relative;
|
|
15
13
|
display: flex !important;
|
|
@@ -44,7 +42,7 @@
|
|
|
44
42
|
display: flex;
|
|
45
43
|
align-items: center;
|
|
46
44
|
padding: 0 4px;
|
|
47
|
-
color:rgba(0, 0, 0, 0.25);
|
|
45
|
+
color: rgba(0, 0, 0, 0.25);
|
|
48
46
|
}
|
|
49
47
|
.@{all-input-group}-one {
|
|
50
48
|
flex: 1;
|
|
@@ -13,26 +13,27 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
13
13
|
fieldNames = {},
|
|
14
14
|
} = params;
|
|
15
15
|
const [val, setVal] = useState<any>();
|
|
16
|
-
const labelInValueItemMaker=(changeVal)=>{
|
|
17
|
-
const {value:fieldValue="value",label:fieldLabel="label"}=
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[
|
|
22
|
-
|
|
16
|
+
const labelInValueItemMaker = (changeVal) => {
|
|
17
|
+
const { value: fieldValue = "value", label: fieldLabel = "label" } =
|
|
18
|
+
fieldNames;
|
|
19
|
+
const { label: changeLabel, value: changeValue, ...oVal } = changeVal;
|
|
20
|
+
return {
|
|
21
|
+
[fieldValue]: changeValue,
|
|
22
|
+
[fieldLabel]: changeLabel,
|
|
23
|
+
...oVal,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const labelInValueMaker = (changeVal) => {
|
|
27
|
+
if (!changeVal) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (!Array.isArray(changeVal)) {
|
|
31
|
+
return labelInValueItemMaker(changeVal);
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (!Array.isArray(changeVal)){
|
|
30
|
-
return labelInValueItemMaker(changeVal)
|
|
31
|
-
}
|
|
32
|
-
return changeVal.map((item)=>{
|
|
33
|
-
return labelInValueItemMaker(item)
|
|
34
|
-
})
|
|
35
|
-
}
|
|
33
|
+
return changeVal.map((item) => {
|
|
34
|
+
return labelInValueItemMaker(item);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
36
37
|
const change = (changeVal, itemOps) => {
|
|
37
38
|
if (!onChange) {
|
|
38
39
|
setVal(changeVal);
|
|
@@ -44,11 +45,11 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
44
45
|
}
|
|
45
46
|
const subItemOps = itemOpProvider(itemOps, fieldNames);
|
|
46
47
|
if (labelInValue) {
|
|
47
|
-
onChange(labelInValueMaker(changeVal),itemOps);
|
|
48
|
+
onChange(labelInValueMaker(changeVal), itemOps);
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
let newChangeVal = changeVal.value;
|
|
51
|
-
if (Array.isArray(changeVal)
|
|
52
|
+
if (Array.isArray(changeVal) && !labelInValue) {
|
|
52
53
|
newChangeVal = changeVal.map((item) => {
|
|
53
54
|
return item.value;
|
|
54
55
|
});
|
|
@@ -60,7 +61,7 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
60
61
|
setVal(undefined);
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
|
-
if (mode === "tags"||labelInValue) {
|
|
64
|
+
if (mode === "tags" || labelInValue) {
|
|
64
65
|
setVal(value);
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
@@ -73,13 +74,14 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
73
74
|
}, [value, options, mode]);
|
|
74
75
|
const itemMaker = (item) => {
|
|
75
76
|
const { value: itemVal, label, noMatch } = item;
|
|
76
|
-
const {value:fieldValue="value",label:fieldLabel="label"}=
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
const { value: fieldValue = "value", label: fieldLabel = "label" } =
|
|
78
|
+
fieldNames;
|
|
79
|
+
if (labelInValue) {
|
|
80
|
+
const { [fieldValue]: changeVal, [fieldLabel]: changeLable } = item;
|
|
81
|
+
return {
|
|
82
|
+
value: changeVal,
|
|
83
|
+
label: changeLable,
|
|
84
|
+
};
|
|
83
85
|
}
|
|
84
86
|
if (noMatch) {
|
|
85
87
|
return {
|
|
@@ -3,7 +3,7 @@ import Input from "antd/es/input/Input";
|
|
|
3
3
|
import Upload from "../index";
|
|
4
4
|
import type { IUploadRefModal, IUrlUploadProps } from "../modal";
|
|
5
5
|
import TypeEle from "../MediaTypeEle/TypeEle";
|
|
6
|
-
import {
|
|
6
|
+
import { useRef, useState } from "react";
|
|
7
7
|
import type { RcFile, UploadFile } from "antd/es/upload/interface";
|
|
8
8
|
import { useDefaultExFiles } from "./hooks";
|
|
9
9
|
const { Text } = Typography;
|
package/src/components/config.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import moment from "moment";
|
|
2
2
|
import type { IFormConfigContextProps } from "./Form/modal";
|
|
3
3
|
import { fileToBase64 } from "./Upload/util";
|
|
4
|
+
const rangeStartDay=(day:number)=>{
|
|
5
|
+
return moment().subtract(day, "days").startOf("days")
|
|
6
|
+
}
|
|
4
7
|
export const baseConfig: IFormConfigContextProps = {
|
|
5
8
|
fieldNames: {
|
|
6
9
|
label: "label",
|
|
@@ -23,9 +26,15 @@ export const baseConfig: IFormConfigContextProps = {
|
|
|
23
26
|
},
|
|
24
27
|
},
|
|
25
28
|
dateRanges: {
|
|
26
|
-
最近三天:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
最近三天: ()=>{
|
|
30
|
+
return [rangeStartDay(2), moment()]
|
|
31
|
+
},
|
|
32
|
+
最近七天: ()=>{
|
|
33
|
+
return [rangeStartDay(6),moment()]
|
|
34
|
+
},
|
|
35
|
+
最近三十天:()=>{
|
|
36
|
+
return [rangeStartDay(29), moment()]
|
|
37
|
+
},
|
|
29
38
|
},
|
|
30
39
|
uploadProps: {
|
|
31
40
|
exFiles: ["JPG", "PNG", "JPEG", "GIF"],
|
package/src/components/index.tsx
CHANGED
|
@@ -6,7 +6,7 @@ export { default as useHForm } from "./Form/hooks/useHForm";
|
|
|
6
6
|
export { useHDialogForm } from "./DialogForm/hooks";
|
|
7
7
|
export { default as HFormConnect } from "./Form/HFormConnect";
|
|
8
8
|
export { default as HFormConfigProvider } from "./Form/Context/FormConfigProvider";
|
|
9
|
-
export {default as HBasicForm} from
|
|
9
|
+
export { default as HBasicForm } from "./Form/Basic";
|
|
10
10
|
|
|
11
11
|
import ModalForm from "./DialogForm/ModalForm";
|
|
12
12
|
import DrawerForm from "./DialogForm/DrawerForm";
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -1,102 +1,79 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
HBasicForm,
|
|
3
|
+
HForm,
|
|
4
|
+
HFormConfigProvider,
|
|
5
|
+
HSwitch,
|
|
6
|
+
useHForm,
|
|
7
|
+
HSelect,
|
|
8
8
|
} from "../../components";
|
|
9
9
|
import { useState } from "react";
|
|
10
|
-
import {Button, DatePicker, Form, Input, Row, Space} from "antd";
|
|
10
|
+
import { Button, DatePicker, Form, Input, Row, Space } from "antd";
|
|
11
11
|
const Test2 = () => {
|
|
12
12
|
return <Row style={{ background: "red" }} />;
|
|
13
13
|
};
|
|
14
|
-
const Test3 = ({ value={}, onChange }) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
const Test3 = ({ value = {}, onChange }) => {
|
|
15
|
+
const { fs, end } = value;
|
|
16
|
+
return (
|
|
17
|
+
<Space>
|
|
18
|
+
<HSelect
|
|
19
|
+
options={[{ value: "1321", key: 1 }]}
|
|
20
|
+
value={fs}
|
|
21
|
+
allowClear
|
|
22
|
+
onChange={() => {
|
|
23
|
+
onChange?.({});
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
<HSelect
|
|
27
|
+
options={[{ value: "112", key: 2 }]}
|
|
28
|
+
allowClear
|
|
29
|
+
value={end}
|
|
30
|
+
onChange={(val) => {
|
|
31
|
+
onChange?.({
|
|
32
|
+
...value,
|
|
33
|
+
end: val,
|
|
34
|
+
});
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
35
37
|
</Space>
|
|
38
|
+
);
|
|
36
39
|
};
|
|
37
|
-
const TestItem=()=>{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
const TestItem = () => {
|
|
41
|
+
return (
|
|
42
|
+
<Form.Item name="name1">
|
|
43
|
+
<Test3 />
|
|
40
44
|
</Form.Item>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const Test3Item = () => {
|
|
48
|
+
return (
|
|
49
|
+
<Form.List name="users">
|
|
50
|
+
{(fields, { add, remove }) => (
|
|
45
51
|
<>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
name={name}
|
|
50
|
-
key={key}
|
|
51
|
-
>
|
|
52
|
-
<Test3/>
|
|
53
|
-
</Form.Item>
|
|
54
|
-
))}
|
|
55
|
-
<Form.Item>
|
|
56
|
-
<Button type="dashed" onClick={() => add({})} block>
|
|
57
|
-
Add field
|
|
58
|
-
</Button>
|
|
52
|
+
{fields.map(({ key, name, ...restField }) => (
|
|
53
|
+
<Form.Item {...restField} name={name} key={key}>
|
|
54
|
+
<Test3 />
|
|
59
55
|
</Form.Item>
|
|
56
|
+
))}
|
|
57
|
+
<Form.Item>
|
|
58
|
+
<Button type="dashed" onClick={() => add({})} block>
|
|
59
|
+
Add field
|
|
60
|
+
</Button>
|
|
61
|
+
</Form.Item>
|
|
60
62
|
</>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
63
|
+
)}
|
|
64
|
+
</Form.List>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
65
67
|
const formData = (options) => {
|
|
66
68
|
return [
|
|
67
69
|
{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
configData={[
|
|
71
|
-
{
|
|
72
|
-
label: "下拉123",
|
|
73
|
-
className: "xiala",
|
|
74
|
-
render:()=>{
|
|
75
|
-
return <TestItem/>
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
]}/>
|
|
79
|
-
}
|
|
70
|
+
name:"name",
|
|
71
|
+
label:"输入框"
|
|
80
72
|
},
|
|
81
73
|
{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
style: {
|
|
86
|
-
marginBottom: 0,
|
|
87
|
-
},
|
|
88
|
-
render:()=>{
|
|
89
|
-
return <HBasicForm
|
|
90
|
-
configData={[
|
|
91
|
-
{
|
|
92
|
-
label: "333",
|
|
93
|
-
className: "xiala",
|
|
94
|
-
render:()=>{
|
|
95
|
-
return <Test3Item/>
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
]}/>
|
|
99
|
-
}
|
|
74
|
+
name:"url",
|
|
75
|
+
type:"urlUpload",
|
|
76
|
+
label:"文本"
|
|
100
77
|
},
|
|
101
78
|
];
|
|
102
79
|
};
|
|
@@ -140,6 +117,7 @@ export default () => {
|
|
|
140
117
|
<HForm
|
|
141
118
|
configData={formData(options)}
|
|
142
119
|
labelWidth={300}
|
|
120
|
+
dismissOnPressEnter={false}
|
|
143
121
|
form={form}
|
|
144
122
|
labelAlign={"left"}
|
|
145
123
|
onFinish={(value) => {
|
|
@@ -149,7 +127,7 @@ export default () => {
|
|
|
149
127
|
console.log(val, "onValuesChange");
|
|
150
128
|
}}
|
|
151
129
|
initialValues={{
|
|
152
|
-
|
|
130
|
+
name1: {},
|
|
153
131
|
}}
|
|
154
132
|
request={(params) => {
|
|
155
133
|
return new Promise<any>((resolve) => {
|
|
@@ -26,11 +26,13 @@ export default () => {
|
|
|
26
26
|
return Promise.resolve({ code: 200 });
|
|
27
27
|
}}
|
|
28
28
|
/>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
<HInputNumberGroup
|
|
30
|
+
inputNumberProps={[
|
|
31
|
+
{
|
|
32
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
33
|
+
},
|
|
34
|
+
]}
|
|
35
|
+
/>
|
|
34
36
|
</Space>
|
|
35
37
|
);
|
|
36
38
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HSelect } from "../../components";
|
|
2
|
-
import { Space
|
|
2
|
+
import { Space, Select } from "antd";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
export default () => {
|
|
5
|
-
const [selectVal, setSelectVal] = useState([{name:"11",id
|
|
5
|
+
const [selectVal, setSelectVal] = useState([{ name: "11", id: -100 }]);
|
|
6
6
|
return (
|
|
7
7
|
<Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
|
|
8
8
|
<HSelect
|
|
@@ -11,12 +11,12 @@ export default () => {
|
|
|
11
11
|
allowClear={true}
|
|
12
12
|
labelInValue
|
|
13
13
|
fieldNames={{
|
|
14
|
-
label:"name",
|
|
15
|
-
value:"id"
|
|
14
|
+
label: "name",
|
|
15
|
+
value: "id",
|
|
16
16
|
}}
|
|
17
17
|
value={selectVal}
|
|
18
|
-
onChange={(val,item)=>{
|
|
19
|
-
|
|
18
|
+
onChange={(val, item) => {
|
|
19
|
+
setSelectVal(val);
|
|
20
20
|
}}
|
|
21
21
|
request={async (params) => {
|
|
22
22
|
const { page, size } = params;
|
|
@@ -24,15 +24,19 @@ export default () => {
|
|
|
24
24
|
for (let i = 0; i < 100; i += 1) {
|
|
25
25
|
op.push({ name: `第${page}页第${i}条`, id: i + page });
|
|
26
26
|
}
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
})
|
|
27
|
+
return Promise.resolve({
|
|
28
|
+
page,
|
|
29
|
+
size: 100,
|
|
30
|
+
total: 1000,
|
|
31
|
+
data: op,
|
|
32
|
+
});
|
|
33
33
|
}}
|
|
34
34
|
isList
|
|
35
35
|
/>
|
|
36
|
+
<HSelect
|
|
37
|
+
value={1}
|
|
38
|
+
options={null}
|
|
39
|
+
/>
|
|
36
40
|
</Space>
|
|
37
41
|
);
|
|
38
42
|
};
|
|
@@ -24,13 +24,12 @@ export default () => {
|
|
|
24
24
|
maxCount={3}
|
|
25
25
|
maxSize={Number.MAX_SAFE_INTEGER}
|
|
26
26
|
/>
|
|
27
|
-
<
|
|
27
|
+
<HUpload
|
|
28
28
|
value={files1}
|
|
29
29
|
mediaType={MediaTypeEnum.file}
|
|
30
30
|
showUploadList={{
|
|
31
31
|
showPreviewIcon: false,
|
|
32
32
|
}}
|
|
33
|
-
exFiles={["TXT", "EXE"]}
|
|
34
33
|
onChange={setFiles1}
|
|
35
34
|
/>
|
|
36
35
|
</Space>
|