@hw-component/form 0.0.9-beta-v1 → 0.0.9-beta-v2
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 +13 -1
- package/es/Form/modal.d.ts +1 -0
- package/es/Switch/index.js +0 -1
- package/lib/Form/hooks/useHForm.js +13 -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 +16 -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);
|
|
@@ -82,6 +84,7 @@ var useHForm = (function () {
|
|
|
82
84
|
return {};
|
|
83
85
|
}
|
|
84
86
|
var newValue = _objectSpread({}, value);
|
|
87
|
+
console.log(formatSourceData, "formatSourceData");
|
|
85
88
|
var keys = Object.keys(formatSourceData);
|
|
86
89
|
keys.forEach(function (key) {
|
|
87
90
|
var _formatSourceData$key;
|
|
@@ -93,6 +96,7 @@ var useHForm = (function () {
|
|
|
93
96
|
Reflect.deleteProperty(newValue, key);
|
|
94
97
|
newValue = _objectSpread(_objectSpread({}, newValue), resultValue);
|
|
95
98
|
});
|
|
99
|
+
console.log(newValue, "newVal");
|
|
96
100
|
return newValue;
|
|
97
101
|
},
|
|
98
102
|
dispatch: function dispatch(action) {
|
|
@@ -174,7 +178,6 @@ var useHForm = (function () {
|
|
|
174
178
|
cacheValues = values;
|
|
175
179
|
return;
|
|
176
180
|
}
|
|
177
|
-
console.log("setFieldsValue");
|
|
178
181
|
var newValue = this.formatValues(values);
|
|
179
182
|
form.setFieldsValue(newValue);
|
|
180
183
|
},
|
|
@@ -187,6 +190,15 @@ var useHForm = (function () {
|
|
|
187
190
|
});
|
|
188
191
|
});
|
|
189
192
|
},
|
|
193
|
+
resetFieldsInitValue: function resetFieldsInitValue() {
|
|
194
|
+
var oldValue = form.getFieldsValue();
|
|
195
|
+
var keys = Object.keys(oldValue);
|
|
196
|
+
var newVale = {};
|
|
197
|
+
keys.forEach(function (key) {
|
|
198
|
+
newVale[key] = undefined;
|
|
199
|
+
});
|
|
200
|
+
form.setFieldsValue(_objectSpread(_objectSpread({}, newVale), initSaveValue));
|
|
201
|
+
},
|
|
190
202
|
clear: function clear() {
|
|
191
203
|
form.resetFields();
|
|
192
204
|
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);
|
|
@@ -85,6 +87,7 @@ var useHForm = (function () {
|
|
|
85
87
|
return {};
|
|
86
88
|
}
|
|
87
89
|
var newValue = _objectSpread({}, value);
|
|
90
|
+
console.log(formatSourceData, "formatSourceData");
|
|
88
91
|
var keys = Object.keys(formatSourceData);
|
|
89
92
|
keys.forEach(function (key) {
|
|
90
93
|
var _formatSourceData$key;
|
|
@@ -96,6 +99,7 @@ var useHForm = (function () {
|
|
|
96
99
|
Reflect.deleteProperty(newValue, key);
|
|
97
100
|
newValue = _objectSpread(_objectSpread({}, newValue), resultValue);
|
|
98
101
|
});
|
|
102
|
+
console.log(newValue, "newVal");
|
|
99
103
|
return newValue;
|
|
100
104
|
},
|
|
101
105
|
dispatch: function dispatch(action) {
|
|
@@ -177,7 +181,6 @@ var useHForm = (function () {
|
|
|
177
181
|
cacheValues = values;
|
|
178
182
|
return;
|
|
179
183
|
}
|
|
180
|
-
console.log("setFieldsValue");
|
|
181
184
|
var newValue = this.formatValues(values);
|
|
182
185
|
form.setFieldsValue(newValue);
|
|
183
186
|
},
|
|
@@ -190,6 +193,15 @@ var useHForm = (function () {
|
|
|
190
193
|
});
|
|
191
194
|
});
|
|
192
195
|
},
|
|
196
|
+
resetFieldsInitValue: function resetFieldsInitValue() {
|
|
197
|
+
var oldValue = form.getFieldsValue();
|
|
198
|
+
var keys = Object.keys(oldValue);
|
|
199
|
+
var newVale = {};
|
|
200
|
+
keys.forEach(function (key) {
|
|
201
|
+
newVale[key] = undefined;
|
|
202
|
+
});
|
|
203
|
+
form.setFieldsValue(_objectSpread(_objectSpread({}, newVale), initSaveValue));
|
|
204
|
+
},
|
|
193
205
|
clear: function clear() {
|
|
194
206
|
form.resetFields();
|
|
195
207
|
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);
|
|
@@ -66,6 +67,7 @@ export default () => {
|
|
|
66
67
|
return {};
|
|
67
68
|
}
|
|
68
69
|
let newValue = { ...value };
|
|
70
|
+
console.log(formatSourceData,"formatSourceData")
|
|
69
71
|
const keys = Object.keys(formatSourceData);
|
|
70
72
|
keys.forEach((key) => {
|
|
71
73
|
const format = formatSourceData[key]?.[formatKey];
|
|
@@ -79,6 +81,7 @@ export default () => {
|
|
|
79
81
|
...resultValue,
|
|
80
82
|
};
|
|
81
83
|
});
|
|
84
|
+
console.log(newValue,"newVal")
|
|
82
85
|
return newValue;
|
|
83
86
|
}, //转化方法
|
|
84
87
|
dispatch(action, ...args) {
|
|
@@ -149,7 +152,6 @@ export default () => {
|
|
|
149
152
|
cacheValues = values;
|
|
150
153
|
return;
|
|
151
154
|
}
|
|
152
|
-
console.log("setFieldsValue")
|
|
153
155
|
const newValue = this.formatValues(values);
|
|
154
156
|
form.setFieldsValue(newValue);
|
|
155
157
|
},
|
|
@@ -161,6 +163,18 @@ export default () => {
|
|
|
161
163
|
});
|
|
162
164
|
});
|
|
163
165
|
},
|
|
166
|
+
resetFieldsInitValue:()=>{
|
|
167
|
+
const oldValue=form.getFieldsValue();
|
|
168
|
+
const keys=Object.keys(oldValue);
|
|
169
|
+
const newVale={};
|
|
170
|
+
keys.forEach((key)=>{
|
|
171
|
+
newVale[key]=undefined;
|
|
172
|
+
});
|
|
173
|
+
form.setFieldsValue({
|
|
174
|
+
...newVale,
|
|
175
|
+
...initSaveValue,
|
|
176
|
+
});
|
|
177
|
+
},
|
|
164
178
|
clear: () => {
|
|
165
179
|
form.resetFields();
|
|
166
180
|
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
|
重置
|