@hw-component/form 0.0.9-beta-v1 → 0.0.9-beta-v3
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/hooks/useHForm.js +11 -1
- package/es/Form/modal.d.ts +1 -0
- package/es/Switch/index.js +0 -1
- package/lib/Form/hooks/useHForm.js +11 -1
- package/lib/Form/modal.d.ts +1 -0
- package/lib/Switch/index.js +0 -1
- package/package.json +1 -1
- package/src/components/DialogForm/hooks.ts +10 -8
- package/src/components/Form/hooks/useHForm.ts +14 -2
- package/src/components/Form/modal.ts +1 -0
- package/src/components/Switch/index.tsx +0 -1
- package/src/pages/DrawerForm/index.tsx +3 -3
- package/src/pages/Form/index.tsx +9 -10
|
@@ -29,6 +29,7 @@ var useHForm = (function () {
|
|
|
29
29
|
var initDispatch = {};
|
|
30
30
|
var cacheValues = {};
|
|
31
31
|
var isLoading = false;
|
|
32
|
+
var initSaveValue = {};
|
|
32
33
|
var norAddItemDispatch = function norAddItemDispatch(name, manual, fn) {
|
|
33
34
|
if (manual === false && name) {
|
|
34
35
|
initDispatch[name] = fn;
|
|
@@ -52,6 +53,7 @@ var useHForm = (function () {
|
|
|
52
53
|
var newValue = {};
|
|
53
54
|
if (cacheValues) {
|
|
54
55
|
newValue = this.formatValues(cacheValues);
|
|
56
|
+
initSaveValue = newValue;
|
|
55
57
|
form.setFieldsValue(newValue);
|
|
56
58
|
}
|
|
57
59
|
var initKeys = Object.keys(initDispatch);
|
|
@@ -174,7 +176,6 @@ var useHForm = (function () {
|
|
|
174
176
|
cacheValues = values;
|
|
175
177
|
return;
|
|
176
178
|
}
|
|
177
|
-
console.log("setFieldsValue");
|
|
178
179
|
var newValue = this.formatValues(values);
|
|
179
180
|
form.setFieldsValue(newValue);
|
|
180
181
|
},
|
|
@@ -187,6 +188,15 @@ var useHForm = (function () {
|
|
|
187
188
|
});
|
|
188
189
|
});
|
|
189
190
|
},
|
|
191
|
+
resetFieldsInitValue: function resetFieldsInitValue() {
|
|
192
|
+
var oldValue = form.getFieldsValue();
|
|
193
|
+
var keys = Object.keys(oldValue);
|
|
194
|
+
var newVale = {};
|
|
195
|
+
keys.forEach(function (key) {
|
|
196
|
+
newVale[key] = undefined;
|
|
197
|
+
});
|
|
198
|
+
form.setFieldsValue(_objectSpread(_objectSpread({}, newVale), initSaveValue));
|
|
199
|
+
},
|
|
190
200
|
clear: function clear() {
|
|
191
201
|
form.resetFields();
|
|
192
202
|
isLoading = false;
|
package/es/Form/modal.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ export interface HFormInstance extends FormInstance {
|
|
|
106
106
|
removeDispatchListener: (action?: ActionModal, fn?: argsFn) => void;
|
|
107
107
|
reload: PromiseFnResult;
|
|
108
108
|
clear: VoidFunction;
|
|
109
|
+
resetFieldsInitValue: VoidFunction;
|
|
109
110
|
}
|
|
110
111
|
export interface ConnectConfigModal {
|
|
111
112
|
format?: Record<string, addFormatItemModal>;
|
package/es/Switch/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var useHForm = (function () {
|
|
|
32
32
|
var initDispatch = {};
|
|
33
33
|
var cacheValues = {};
|
|
34
34
|
var isLoading = false;
|
|
35
|
+
var initSaveValue = {};
|
|
35
36
|
var norAddItemDispatch = function norAddItemDispatch(name, manual, fn) {
|
|
36
37
|
if (manual === false && name) {
|
|
37
38
|
initDispatch[name] = fn;
|
|
@@ -55,6 +56,7 @@ var useHForm = (function () {
|
|
|
55
56
|
var newValue = {};
|
|
56
57
|
if (cacheValues) {
|
|
57
58
|
newValue = this.formatValues(cacheValues);
|
|
59
|
+
initSaveValue = newValue;
|
|
58
60
|
form.setFieldsValue(newValue);
|
|
59
61
|
}
|
|
60
62
|
var initKeys = Object.keys(initDispatch);
|
|
@@ -177,7 +179,6 @@ var useHForm = (function () {
|
|
|
177
179
|
cacheValues = values;
|
|
178
180
|
return;
|
|
179
181
|
}
|
|
180
|
-
console.log("setFieldsValue");
|
|
181
182
|
var newValue = this.formatValues(values);
|
|
182
183
|
form.setFieldsValue(newValue);
|
|
183
184
|
},
|
|
@@ -190,6 +191,15 @@ var useHForm = (function () {
|
|
|
190
191
|
});
|
|
191
192
|
});
|
|
192
193
|
},
|
|
194
|
+
resetFieldsInitValue: function resetFieldsInitValue() {
|
|
195
|
+
var oldValue = form.getFieldsValue();
|
|
196
|
+
var keys = Object.keys(oldValue);
|
|
197
|
+
var newVale = {};
|
|
198
|
+
keys.forEach(function (key) {
|
|
199
|
+
newVale[key] = undefined;
|
|
200
|
+
});
|
|
201
|
+
form.setFieldsValue(_objectSpread(_objectSpread({}, newVale), initSaveValue));
|
|
202
|
+
},
|
|
193
203
|
clear: function clear() {
|
|
194
204
|
form.resetFields();
|
|
195
205
|
isLoading = false;
|
package/lib/Form/modal.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ export interface HFormInstance extends FormInstance {
|
|
|
106
106
|
removeDispatchListener: (action?: ActionModal, fn?: argsFn) => void;
|
|
107
107
|
reload: PromiseFnResult;
|
|
108
108
|
clear: VoidFunction;
|
|
109
|
+
resetFieldsInitValue: VoidFunction;
|
|
109
110
|
}
|
|
110
111
|
export interface ConnectConfigModal {
|
|
111
112
|
format?: Record<string, addFormatItemModal>;
|
package/lib/Switch/index.js
CHANGED
package/package.json
CHANGED
|
@@ -23,14 +23,14 @@ export const useModifyProps = ({
|
|
|
23
23
|
const [initValue, setInitValue] = useState(initialValues);
|
|
24
24
|
const [formParams, setFormParams] = useState(params);
|
|
25
25
|
const [modalTitle, setModalTitle] = useState(title);
|
|
26
|
-
const saveOldParamsObj=useMemo(()=>{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},[]);
|
|
26
|
+
const saveOldParamsObj = useMemo(() => {
|
|
27
|
+
return {
|
|
28
|
+
old: {},
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
31
|
const onAfterClose = () => {
|
|
32
32
|
onCancel?.();
|
|
33
|
-
saveOldParamsObj.old=dialogForm.outputValues();
|
|
33
|
+
saveOldParamsObj.old = dialogForm.outputValues();
|
|
34
34
|
setTimeout(() => {
|
|
35
35
|
dialogForm.clear();
|
|
36
36
|
afterClose?.();
|
|
@@ -68,7 +68,9 @@ export const useModifyProps = ({
|
|
|
68
68
|
if (!!changeTitle) {
|
|
69
69
|
setModalTitle(changeTitle);
|
|
70
70
|
}
|
|
71
|
-
const relChangeInitVal=autoClear
|
|
71
|
+
const relChangeInitVal = autoClear
|
|
72
|
+
? changeInitialValues
|
|
73
|
+
: { ...saveOldParamsObj.old, ...changeInitialValues };
|
|
72
74
|
setInitValue(relChangeInitVal);
|
|
73
75
|
setModalVisible(true);
|
|
74
76
|
};
|
|
@@ -76,7 +78,7 @@ export const useModifyProps = ({
|
|
|
76
78
|
setModalVisible(false);
|
|
77
79
|
onAfterClose();
|
|
78
80
|
};
|
|
79
|
-
}, [afterClose,autoClear]);
|
|
81
|
+
}, [afterClose, autoClear]);
|
|
80
82
|
return {
|
|
81
83
|
modalFormData,
|
|
82
84
|
modalVisible,
|
|
@@ -16,7 +16,7 @@ export default () => {
|
|
|
16
16
|
const initDispatch: Record<string, argsFn> = {};
|
|
17
17
|
let cacheValues: Record<string, any> = {};
|
|
18
18
|
let isLoading = false;
|
|
19
|
-
|
|
19
|
+
let initSaveValue={};
|
|
20
20
|
const norAddItemDispatch = (name, manual, fn) => {
|
|
21
21
|
if (manual === false && name) {
|
|
22
22
|
initDispatch[name] = fn;
|
|
@@ -42,6 +42,7 @@ export default () => {
|
|
|
42
42
|
let newValue = {};
|
|
43
43
|
if (cacheValues) {
|
|
44
44
|
newValue = this.formatValues(cacheValues);
|
|
45
|
+
initSaveValue=newValue;
|
|
45
46
|
form.setFieldsValue(newValue);
|
|
46
47
|
}
|
|
47
48
|
const initKeys = Object.keys(initDispatch);
|
|
@@ -149,7 +150,6 @@ export default () => {
|
|
|
149
150
|
cacheValues = values;
|
|
150
151
|
return;
|
|
151
152
|
}
|
|
152
|
-
console.log("setFieldsValue")
|
|
153
153
|
const newValue = this.formatValues(values);
|
|
154
154
|
form.setFieldsValue(newValue);
|
|
155
155
|
},
|
|
@@ -161,6 +161,18 @@ export default () => {
|
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
163
|
},
|
|
164
|
+
resetFieldsInitValue:()=>{
|
|
165
|
+
const oldValue=form.getFieldsValue();
|
|
166
|
+
const keys=Object.keys(oldValue);
|
|
167
|
+
const newVale={};
|
|
168
|
+
keys.forEach((key)=>{
|
|
169
|
+
newVale[key]=undefined;
|
|
170
|
+
});
|
|
171
|
+
form.setFieldsValue({
|
|
172
|
+
...newVale,
|
|
173
|
+
...initSaveValue,
|
|
174
|
+
});
|
|
175
|
+
},
|
|
164
176
|
clear: () => {
|
|
165
177
|
form.resetFields();
|
|
166
178
|
isLoading = false;
|
|
@@ -160,6 +160,7 @@ export interface HFormInstance extends FormInstance {
|
|
|
160
160
|
removeDispatchListener: (action?: ActionModal, fn?: argsFn) => void;
|
|
161
161
|
reload: PromiseFnResult;
|
|
162
162
|
clear: VoidFunction;
|
|
163
|
+
resetFieldsInitValue:VoidFunction;
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
export interface ConnectConfigModal {
|
|
@@ -107,19 +107,19 @@ const data = [
|
|
|
107
107
|
},
|
|
108
108
|
},
|
|
109
109
|
];
|
|
110
|
-
let num=0
|
|
110
|
+
let num = 0;
|
|
111
111
|
export default () => {
|
|
112
112
|
const modalForm = useHDialogForm();
|
|
113
113
|
return (
|
|
114
114
|
<>
|
|
115
115
|
<Button
|
|
116
116
|
onClick={() => {
|
|
117
|
-
num
|
|
117
|
+
num++;
|
|
118
118
|
modalForm.show({
|
|
119
119
|
initialValues: {
|
|
120
120
|
check1: 1,
|
|
121
121
|
op: 1,
|
|
122
|
-
opInput:num,
|
|
122
|
+
opInput: num,
|
|
123
123
|
},
|
|
124
124
|
});
|
|
125
125
|
}}
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HForm, HFormConfigProvider, useHForm } from "../../components";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import {Button, DatePicker, Form, Input} from "antd";
|
|
4
4
|
|
|
5
5
|
const formData = (options) => {
|
|
6
6
|
const op = [
|
|
@@ -102,12 +102,6 @@ const formData = (options) => {
|
|
|
102
102
|
datePicker: "fakfjkfjsklfjskljsak",
|
|
103
103
|
};
|
|
104
104
|
},
|
|
105
|
-
initValueProvider: (item, val) => {
|
|
106
|
-
console.log(val, "vvv");
|
|
107
|
-
return {
|
|
108
|
-
datePicker: 1706510695,
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
105
|
},
|
|
112
106
|
rules: [{ required: true }],
|
|
113
107
|
},
|
|
@@ -247,9 +241,14 @@ const Test = (props) => {
|
|
|
247
241
|
export default () => {
|
|
248
242
|
const form = useHForm();
|
|
249
243
|
const [options, setOptions] = useState([{ label: "1", value: 1 }]);
|
|
250
|
-
|
|
244
|
+
const [aForm]=Form.useForm();
|
|
251
245
|
return (
|
|
252
246
|
<div style={{ overflow: "auto", height: "90vh" }}>
|
|
247
|
+
<Form form={aForm} initialValues={{ttim:"132123"}}>
|
|
248
|
+
<Form.Item name="ttim" rules={[{required:true}]}>
|
|
249
|
+
<Input/>
|
|
250
|
+
</Form.Item>
|
|
251
|
+
</Form>
|
|
253
252
|
<HFormConfigProvider
|
|
254
253
|
valueSwitchMap={{ open: 1, close: 2 }}
|
|
255
254
|
valueCheckMap={{ noChecked: 0, checked: 1 }}
|
|
@@ -304,14 +303,14 @@ export default () => {
|
|
|
304
303
|
</HFormConfigProvider>
|
|
305
304
|
<div
|
|
306
305
|
onClick={() => {
|
|
307
|
-
|
|
306
|
+
aForm.resetFields();
|
|
308
307
|
}}
|
|
309
308
|
>
|
|
310
309
|
点我
|
|
311
310
|
</div>
|
|
312
311
|
<div
|
|
313
312
|
onClick={() => {
|
|
314
|
-
form.
|
|
313
|
+
form.resetFieldsInitValue();
|
|
315
314
|
}}
|
|
316
315
|
>
|
|
317
316
|
重置
|