@hw-component/form 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/Form/HFormConnect.js +13 -3
- package/es/Form/hooks/useHForm.js +4 -1
- package/lib/Form/HFormConnect.js +13 -3
- package/lib/Form/hooks/useHForm.js +4 -1
- package/package.json +1 -1
- package/src/components/Form/HFormConnect.tsx +12 -1
- package/src/components/Form/hooks/useHForm.ts +4 -1
- package/src/components/Switch/index.tsx +1 -1
- package/src/pages/Form/index.tsx +11 -99
- package/src/pages/ModalForm/index.tsx +11 -3
package/es/Form/HFormConnect.js
CHANGED
|
@@ -41,20 +41,30 @@ var HFormConnect = (function (component) {
|
|
|
41
41
|
var _config$format = config.format,
|
|
42
42
|
format = _config$format === void 0 ? {} : _config$format;
|
|
43
43
|
var Index = function Index(props, ref) {
|
|
44
|
-
var _props$name = props.name,
|
|
45
|
-
name = _props$name === void 0 ? "" : _props$name,
|
|
46
|
-
dispatch = props.dispatch;
|
|
47
44
|
var _useFormContext = useFormContext(),
|
|
48
45
|
form = _useFormContext.form,
|
|
49
46
|
_useFormContext$value = _useFormContext.valueType,
|
|
50
47
|
valueType = _useFormContext$value === void 0 ? "float" : _useFormContext$value;
|
|
51
48
|
useEffect(function () {
|
|
49
|
+
var name = props.name;
|
|
50
|
+
if (!name) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
52
53
|
form === null || form === void 0 || form.addFormat(name, formatMaker(props, format[valueType]));
|
|
53
54
|
}, [valueType, props]);
|
|
54
55
|
var addFormat = function addFormat(aFormat) {
|
|
56
|
+
var name = props.name;
|
|
57
|
+
if (!name) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
55
60
|
form === null || form === void 0 || form.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
56
61
|
};
|
|
57
62
|
var addDispatchListener = function addDispatchListener(key, fn) {
|
|
63
|
+
var name = props.name,
|
|
64
|
+
dispatch = props.dispatch;
|
|
65
|
+
if (!name) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
58
68
|
form === null || form === void 0 || form.addDispatchListener({
|
|
59
69
|
key: key,
|
|
60
70
|
name: name,
|
|
@@ -69,6 +69,7 @@ var useHForm = (function () {
|
|
|
69
69
|
if (!format) {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
+
console.log(name, "nnnnnnnn");
|
|
72
73
|
var inputValue = format.inputValue,
|
|
73
74
|
outputValue = format.outputValue;
|
|
74
75
|
formatSourceData[name] = {
|
|
@@ -184,10 +185,12 @@ var useHForm = (function () {
|
|
|
184
185
|
},
|
|
185
186
|
validateFields: function validateFields(nameList) {
|
|
186
187
|
var _this = this;
|
|
187
|
-
return new Promise(function (resolve) {
|
|
188
|
+
return new Promise(function (resolve, reject) {
|
|
188
189
|
form.validateFields(nameList).then(function (value) {
|
|
189
190
|
var result = _this.formatValues(value, "outputValue");
|
|
190
191
|
return resolve(result);
|
|
192
|
+
}).catch(function (e) {
|
|
193
|
+
reject(e);
|
|
191
194
|
});
|
|
192
195
|
});
|
|
193
196
|
},
|
package/lib/Form/HFormConnect.js
CHANGED
|
@@ -44,20 +44,30 @@ var HFormConnect = (function (component) {
|
|
|
44
44
|
var _config$format = config.format,
|
|
45
45
|
format = _config$format === void 0 ? {} : _config$format;
|
|
46
46
|
var Index = function Index(props, ref) {
|
|
47
|
-
var _props$name = props.name,
|
|
48
|
-
name = _props$name === void 0 ? "" : _props$name,
|
|
49
|
-
dispatch = props.dispatch;
|
|
50
47
|
var _useFormContext = index.useFormContext(),
|
|
51
48
|
form = _useFormContext.form,
|
|
52
49
|
_useFormContext$value = _useFormContext.valueType,
|
|
53
50
|
valueType = _useFormContext$value === void 0 ? "float" : _useFormContext$value;
|
|
54
51
|
React.useEffect(function () {
|
|
52
|
+
var name = props.name;
|
|
53
|
+
if (!name) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
55
56
|
form === null || form === void 0 || form.addFormat(name, formatMaker(props, format[valueType]));
|
|
56
57
|
}, [valueType, props]);
|
|
57
58
|
var addFormat = function addFormat(aFormat) {
|
|
59
|
+
var name = props.name;
|
|
60
|
+
if (!name) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
58
63
|
form === null || form === void 0 || form.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
59
64
|
};
|
|
60
65
|
var addDispatchListener = function addDispatchListener(key, fn) {
|
|
66
|
+
var name = props.name,
|
|
67
|
+
dispatch = props.dispatch;
|
|
68
|
+
if (!name) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
61
71
|
form === null || form === void 0 || form.addDispatchListener({
|
|
62
72
|
key: key,
|
|
63
73
|
name: name,
|
|
@@ -72,6 +72,7 @@ var useHForm = (function () {
|
|
|
72
72
|
if (!format) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
+
console.log(name, "nnnnnnnn");
|
|
75
76
|
var inputValue = format.inputValue,
|
|
76
77
|
outputValue = format.outputValue;
|
|
77
78
|
formatSourceData[name] = {
|
|
@@ -187,10 +188,12 @@ var useHForm = (function () {
|
|
|
187
188
|
},
|
|
188
189
|
validateFields: function validateFields(nameList) {
|
|
189
190
|
var _this = this;
|
|
190
|
-
return new Promise(function (resolve) {
|
|
191
|
+
return new Promise(function (resolve, reject) {
|
|
191
192
|
form.validateFields(nameList).then(function (value) {
|
|
192
193
|
var result = _this.formatValues(value, "outputValue");
|
|
193
194
|
return resolve(result);
|
|
195
|
+
}).catch(function (e) {
|
|
196
|
+
reject(e);
|
|
194
197
|
});
|
|
195
198
|
});
|
|
196
199
|
},
|
package/package.json
CHANGED
|
@@ -43,17 +43,28 @@ export default (
|
|
|
43
43
|
props: HFormItemProps,
|
|
44
44
|
ref
|
|
45
45
|
) => {
|
|
46
|
-
const { name = "", dispatch } = props;
|
|
47
46
|
|
|
48
47
|
const { form, valueType = "float" } = useFormContext();
|
|
49
48
|
|
|
50
49
|
useEffect(() => {
|
|
50
|
+
const {name}=props;
|
|
51
|
+
if (!name){
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
51
54
|
form?.addFormat(name, formatMaker(props, format[valueType]));
|
|
52
55
|
}, [valueType, props]);
|
|
53
56
|
const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
|
|
57
|
+
const {name}=props;
|
|
58
|
+
if (!name){
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
54
61
|
form?.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
55
62
|
};
|
|
56
63
|
const addDispatchListener = (key: string, fn: argsFn) => {
|
|
64
|
+
const { name , dispatch } = props;
|
|
65
|
+
if (!name){
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
57
68
|
form?.addDispatchListener({ key, name, dispatch }, fn);
|
|
58
69
|
};
|
|
59
70
|
const Component = component as React.ForwardRefRenderFunction<
|
|
@@ -55,6 +55,7 @@ export default () => {
|
|
|
55
55
|
if (!format) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
+
console.log(name,"nnnnnnnn")
|
|
58
59
|
const { inputValue, outputValue } = format;
|
|
59
60
|
formatSourceData[name] = {
|
|
60
61
|
inputValue,
|
|
@@ -157,10 +158,12 @@ export default () => {
|
|
|
157
158
|
form.setFieldsValue(newValue);
|
|
158
159
|
},
|
|
159
160
|
validateFields(nameList) {
|
|
160
|
-
return new Promise((resolve) => {
|
|
161
|
+
return new Promise((resolve,reject) => {
|
|
161
162
|
form.validateFields(nameList).then((value) => {
|
|
162
163
|
const result = this.formatValues(value, "outputValue");
|
|
163
164
|
return resolve(result);
|
|
165
|
+
}).catch((e)=>{
|
|
166
|
+
reject(e);
|
|
164
167
|
});
|
|
165
168
|
});
|
|
166
169
|
},
|
|
@@ -43,7 +43,7 @@ const Index: React.FC<HSwitchProps> = ({
|
|
|
43
43
|
float: {
|
|
44
44
|
inputValue: (item, initValue) => {
|
|
45
45
|
const { close } = valueSwitchMap;
|
|
46
|
-
const { name: valueName
|
|
46
|
+
const { name: valueName="" } = item;
|
|
47
47
|
let val = initValue[valueName];
|
|
48
48
|
if (typeof val === "undefined" || val === null) {
|
|
49
49
|
val = close;
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {HForm, HFormConfigProvider, HSwitch, useHForm} from "../../components";
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
import { Button, DatePicker, Form, Input } from "antd";
|
|
4
|
-
|
|
4
|
+
const Test2=()=>{
|
|
5
|
+
return <HSwitch/>
|
|
6
|
+
}
|
|
5
7
|
const formData = (options) => {
|
|
6
8
|
const op = [
|
|
7
9
|
{
|
|
@@ -17,101 +19,10 @@ const formData = (options) => {
|
|
|
17
19
|
{
|
|
18
20
|
label: "测试12312",
|
|
19
21
|
className: "hdjd",
|
|
20
|
-
name:"test"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
type: "select",
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
label: "测试1",
|
|
28
|
-
type: "inputNumber",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
noStyle: true,
|
|
32
|
-
render: () => {
|
|
33
|
-
return <div>你好a</div>;
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
label: "时间",
|
|
38
|
-
type: "rangePicker",
|
|
39
|
-
name: "rangePicker",
|
|
40
|
-
itemProps: {
|
|
41
|
-
subProvider: () => {
|
|
42
|
-
return {
|
|
43
|
-
hdj: "fff",
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
label: "选择",
|
|
50
|
-
name: "checkboxGroup",
|
|
51
|
-
type: "checkboxGroup",
|
|
52
|
-
rules: [{ required: true }],
|
|
53
|
-
helper: "帮助我",
|
|
54
|
-
options: [
|
|
55
|
-
{ value: "选择1", key: "check1" },
|
|
56
|
-
{ value: "选择2", key: "check2" },
|
|
57
|
-
],
|
|
58
|
-
direction: "vertical",
|
|
59
|
-
labelAlign: "topLeft",
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
label: "file",
|
|
63
|
-
name: "file",
|
|
64
|
-
type: "upload",
|
|
65
|
-
direction: "vertical",
|
|
66
|
-
labelAlign: "topLeft",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
label: "开关",
|
|
70
|
-
name: "switch",
|
|
71
|
-
type: "switch",
|
|
72
|
-
rules: [{ required: true }],
|
|
73
|
-
itemProps: {
|
|
74
|
-
valueMap: {
|
|
75
|
-
open: 1,
|
|
76
|
-
close: 0,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
type: "submit",
|
|
82
|
-
itemProps: {
|
|
83
|
-
extraList: [
|
|
84
|
-
<Button
|
|
85
|
-
key="wh"
|
|
86
|
-
onClick={() => {
|
|
87
|
-
console.log("起飞");
|
|
88
|
-
}}
|
|
89
|
-
>
|
|
90
|
-
芜湖
|
|
91
|
-
</Button>,
|
|
92
|
-
"666",
|
|
93
|
-
"reset",
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
type: "submit",
|
|
99
|
-
itemProps: {
|
|
100
|
-
extraList: [
|
|
101
|
-
<Button
|
|
102
|
-
key="wh"
|
|
103
|
-
onClick={() => {
|
|
104
|
-
console.log("起飞");
|
|
105
|
-
}}
|
|
106
|
-
>
|
|
107
|
-
芜湖
|
|
108
|
-
</Button>,
|
|
109
|
-
<Ttta key="aa" />,
|
|
110
|
-
"666",
|
|
111
|
-
"submit",
|
|
112
|
-
"reset",
|
|
113
|
-
],
|
|
114
|
-
},
|
|
22
|
+
name:"test",
|
|
23
|
+
render:()=>{
|
|
24
|
+
return <Test2/>
|
|
25
|
+
}
|
|
115
26
|
},
|
|
116
27
|
];
|
|
117
28
|
};
|
|
@@ -183,8 +94,9 @@ export default () => {
|
|
|
183
94
|
/>
|
|
184
95
|
</HFormConfigProvider>
|
|
185
96
|
<div
|
|
186
|
-
onClick={() => {
|
|
187
|
-
|
|
97
|
+
onClick={async () => {
|
|
98
|
+
const result=await form.validateFields();
|
|
99
|
+
console.log(result);
|
|
188
100
|
}}
|
|
189
101
|
>
|
|
190
102
|
点我
|
|
@@ -2,10 +2,14 @@ import { Button } from "antd";
|
|
|
2
2
|
import {
|
|
3
3
|
HModalForm,
|
|
4
4
|
useHDialogForm,
|
|
5
|
-
HFormConfigProvider,
|
|
5
|
+
HFormConfigProvider, HUrlUpload,
|
|
6
6
|
} from "../../components";
|
|
7
7
|
import { useState } from "react";
|
|
8
8
|
import { ShowParamsModal } from "@/components/DialogForm/modal";
|
|
9
|
+
|
|
10
|
+
const Test=(props)=>{
|
|
11
|
+
return <HUrlUpload {...props}/>
|
|
12
|
+
}
|
|
9
13
|
const data = [
|
|
10
14
|
{
|
|
11
15
|
label: "输入框",
|
|
@@ -105,8 +109,9 @@ const data = [
|
|
|
105
109
|
{
|
|
106
110
|
label: "地址文件",
|
|
107
111
|
name: "urlUpload",
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
render:()=>{
|
|
113
|
+
return <Test/>
|
|
114
|
+
}
|
|
110
115
|
},
|
|
111
116
|
{
|
|
112
117
|
label: "下拉框",
|
|
@@ -149,6 +154,9 @@ export default () => {
|
|
|
149
154
|
params: {
|
|
150
155
|
name: num,
|
|
151
156
|
},
|
|
157
|
+
initialValues:{
|
|
158
|
+
urlUpload:"ffff"
|
|
159
|
+
}
|
|
152
160
|
});
|
|
153
161
|
}}
|
|
154
162
|
>
|