@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.
@@ -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;
@@ -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>;
@@ -56,7 +56,6 @@ var Index = function Index(_ref) {
56
56
  if (typeof val === "undefined" || val === null) {
57
57
  val = close;
58
58
  }
59
- console.log(val, "");
60
59
  return _defineProperty({}, valueName, val);
61
60
  },
62
61
  outputValue: function outputValue(item, _outputValue) {
@@ -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;
@@ -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>;
@@ -59,7 +59,6 @@ var Index = function Index(_ref) {
59
59
  if (typeof val === "undefined" || val === null) {
60
60
  val = close;
61
61
  }
62
- console.log(val, "");
63
62
  return _defineProperty({}, valueName, val);
64
63
  },
65
64
  outputValue: function outputValue(item, _outputValue) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "0.0.9-beta-v1",
3
+ "version": "0.0.9-beta-v2",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
- return {
28
- old:{}
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?changeInitialValues:{...saveOldParamsObj.old,...changeInitialValues};
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 {
@@ -47,7 +47,6 @@ const Index: React.FC<HSwitchProps> = ({
47
47
  if (typeof val === "undefined" || val === null) {
48
48
  val = close;
49
49
  }
50
- console.log(val, "");
51
50
  return {
52
51
  [valueName]: val,
53
52
  };
@@ -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
  }}
@@ -1,6 +1,6 @@
1
1
  import { HForm, HFormConfigProvider, useHForm } from "../../components";
2
2
  import { useState } from "react";
3
- import { Button } from "antd";
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
- form.setFieldsValue({ name: "123" });
306
+ aForm.resetFields();
308
307
  }}
309
308
  >
310
309
  点我
311
310
  </div>
312
311
  <div
313
312
  onClick={() => {
314
- form.resetFields();
313
+ form.resetFieldsInitValue();
315
314
  }}
316
315
  >
317
316
  重置