@hw-component/form 0.0.8-beta-v9 → 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.
@@ -46,12 +46,16 @@ var useModifyProps = function useModifyProps(_ref) {
46
46
  _useState10 = _slicedToArray(_useState9, 2),
47
47
  modalTitle = _useState10[0],
48
48
  setModalTitle = _useState10[1];
49
+ var saveOldParamsObj = useMemo(function () {
50
+ return {
51
+ old: {}
52
+ };
53
+ }, []);
49
54
  var onAfterClose = function onAfterClose() {
50
55
  onCancel === null || onCancel === void 0 || onCancel();
56
+ saveOldParamsObj.old = dialogForm.outputValues();
51
57
  setTimeout(function () {
52
- if (autoClear) {
53
- dialogForm.clear();
54
- }
58
+ dialogForm.clear();
55
59
  afterClose === null || afterClose === void 0 || afterClose();
56
60
  }, 100);
57
61
  };
@@ -86,14 +90,15 @@ var useModifyProps = function useModifyProps(_ref) {
86
90
  if (!!changeTitle) {
87
91
  setModalTitle(changeTitle);
88
92
  }
89
- setInitValue(changeInitialValues);
93
+ var relChangeInitVal = autoClear ? changeInitialValues : _objectSpread(_objectSpread({}, saveOldParamsObj.old), changeInitialValues);
94
+ setInitValue(relChangeInitVal);
90
95
  setModalVisible(true);
91
96
  };
92
97
  dialogForm.hide = function () {
93
98
  setModalVisible(false);
94
99
  onAfterClose();
95
100
  };
96
- }, [afterClose]);
101
+ }, [afterClose, autoClear]);
97
102
  return {
98
103
  modalFormData: modalFormData,
99
104
  modalVisible: modalVisible,
@@ -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) {
@@ -186,6 +190,15 @@ var useHForm = (function () {
186
190
  });
187
191
  });
188
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
+ },
189
202
  clear: function clear() {
190
203
  form.resetFields();
191
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) {
@@ -47,12 +47,16 @@ var useModifyProps = function useModifyProps(_ref) {
47
47
  _useState10 = _slicedToArray(_useState9, 2),
48
48
  modalTitle = _useState10[0],
49
49
  setModalTitle = _useState10[1];
50
+ var saveOldParamsObj = React.useMemo(function () {
51
+ return {
52
+ old: {}
53
+ };
54
+ }, []);
50
55
  var onAfterClose = function onAfterClose() {
51
56
  onCancel === null || onCancel === void 0 || onCancel();
57
+ saveOldParamsObj.old = dialogForm.outputValues();
52
58
  setTimeout(function () {
53
- if (autoClear) {
54
- dialogForm.clear();
55
- }
59
+ dialogForm.clear();
56
60
  afterClose === null || afterClose === void 0 || afterClose();
57
61
  }, 100);
58
62
  };
@@ -87,14 +91,15 @@ var useModifyProps = function useModifyProps(_ref) {
87
91
  if (!!changeTitle) {
88
92
  setModalTitle(changeTitle);
89
93
  }
90
- setInitValue(changeInitialValues);
94
+ var relChangeInitVal = autoClear ? changeInitialValues : _objectSpread(_objectSpread({}, saveOldParamsObj.old), changeInitialValues);
95
+ setInitValue(relChangeInitVal);
91
96
  setModalVisible(true);
92
97
  };
93
98
  dialogForm.hide = function () {
94
99
  setModalVisible(false);
95
100
  onAfterClose();
96
101
  };
97
- }, [afterClose]);
102
+ }, [afterClose, autoClear]);
98
103
  return {
99
104
  modalFormData: modalFormData,
100
105
  modalVisible: modalVisible,
@@ -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) {
@@ -189,6 +193,15 @@ var useHForm = (function () {
189
193
  });
190
194
  });
191
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
+ },
192
205
  clear: function clear() {
193
206
  form.resetFields();
194
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.8-beta-v9",
3
+ "version": "0.0.9-beta-v2",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,12 +23,16 @@ 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
31
  const onAfterClose = () => {
27
32
  onCancel?.();
33
+ saveOldParamsObj.old = dialogForm.outputValues();
28
34
  setTimeout(() => {
29
- if (autoClear) {
30
- dialogForm.clear();
31
- }
35
+ dialogForm.clear();
32
36
  afterClose?.();
33
37
  }, 100);
34
38
  };
@@ -64,14 +68,17 @@ export const useModifyProps = ({
64
68
  if (!!changeTitle) {
65
69
  setModalTitle(changeTitle);
66
70
  }
67
- setInitValue(changeInitialValues);
71
+ const relChangeInitVal = autoClear
72
+ ? changeInitialValues
73
+ : { ...saveOldParamsObj.old, ...changeInitialValues };
74
+ setInitValue(relChangeInitVal);
68
75
  setModalVisible(true);
69
76
  };
70
77
  dialogForm.hide = () => {
71
78
  setModalVisible(false);
72
79
  onAfterClose();
73
80
  };
74
- }, [afterClose]);
81
+ }, [afterClose, autoClear]);
75
82
  return {
76
83
  modalFormData,
77
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) {
@@ -160,6 +163,18 @@ export default () => {
160
163
  });
161
164
  });
162
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
+ },
163
178
  clear: () => {
164
179
  form.resetFields();
165
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
111
  export default () => {
111
112
  const modalForm = useHDialogForm();
112
113
  return (
113
114
  <>
114
115
  <Button
115
116
  onClick={() => {
117
+ num++;
116
118
  modalForm.show({
117
119
  initialValues: {
118
120
  check1: 1,
119
- testStart: "1694747960",
120
- testEnd: "1693538359",
121
121
  op: 1,
122
- opInput: "12121",
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
  重置
@@ -165,7 +165,6 @@ export default () => {
165
165
  <HFormConfigProvider
166
166
  uploadProps={{
167
167
  request: () => {
168
- console.log("request,request,request,request");
169
168
  return Promise.resolve({
170
169
  url: "https://gw.alicdn.com/imgextra/i2/O1CN01MYuwJQ1GXVBWryCFJ_!!6000000000632-2-tps-1125-570.png_468x468q75.jpg_.webp",
171
170
  });
@@ -175,7 +174,6 @@ export default () => {
175
174
  <HModalForm
176
175
  configData={data}
177
176
  labelWidth={88}
178
- autoClear={false}
179
177
  contentRender={(node, form) => {
180
178
  return (
181
179
  <div>
@@ -184,9 +182,6 @@ export default () => {
184
182
  </div>
185
183
  );
186
184
  }}
187
- request={(val, params) => {
188
- console.log(val, params);
189
- }}
190
185
  dialogForm={modalForm}
191
186
  title="测试"
192
187
  />