@hw-component/form 1.9.33 → 1.9.35

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.
@@ -91,7 +91,7 @@ var useInfoReq = function useInfoReq(_ref) {
91
91
  return initReq(reqParams);
92
92
  case 5:
93
93
  result = _context2.sent;
94
- form === null || form === void 0 || form.setFieldsValue(result);
94
+ form === null || form === void 0 || form.setFieldsValueFull(result);
95
95
  return _context2.abrupt("return", result || {});
96
96
  case 8:
97
97
  if (!(typeof initialValues === "undefined")) {
@@ -100,7 +100,7 @@ var useInfoReq = function useInfoReq(_ref) {
100
100
  }
101
101
  return _context2.abrupt("return", {});
102
102
  case 10:
103
- form === null || form === void 0 || form.setFieldsValue(initialValues);
103
+ form === null || form === void 0 || form.setFieldsValueFull(initialValues);
104
104
  return _context2.abrupt("return", initialValues);
105
105
  case 12:
106
106
  case "end":
@@ -33,6 +33,14 @@ var useHForm = (function () {
33
33
  defaultFn: []
34
34
  };
35
35
  };
36
+ var clearObj = function clearObj(val) {
37
+ var newVal = _objectSpread({}, val);
38
+ var keys = Object.keys(val);
39
+ keys.forEach(function (key) {
40
+ newVal[key] = undefined;
41
+ });
42
+ return newVal;
43
+ };
36
44
  var formatValuesFn = function formatValuesFn() {
37
45
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
38
46
  var formatKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "inputValue";
@@ -177,6 +185,17 @@ var useHForm = (function () {
177
185
  var newValue = formatValuesFn(values);
178
186
  form.setFieldsValue(newValue);
179
187
  },
188
+ setFieldsValueFull: function setFieldsValueFull(values) {
189
+ if (!isLoading) {
190
+ cacheValues = values;
191
+ return;
192
+ }
193
+ var oldFormVal = form.getFieldsValue(true);
194
+ var formatVal = formatValuesFn(oldFormVal, "outputValue");
195
+ var newValue = formatValuesFn(values);
196
+ var clearData = clearObj(_objectSpread(_objectSpread({}, formatVal), oldFormVal));
197
+ form.setFieldsValue(_objectSpread(_objectSpread({}, clearData), newValue));
198
+ },
180
199
  validateFields: function validateFields(nameList) {
181
200
  return new Promise(function (resolve, reject) {
182
201
  form.validateFields(nameList).then(function (value) {
@@ -141,6 +141,7 @@ export interface HFormInstance extends FormInstance {
141
141
  clear: VoidFunction;
142
142
  resetFieldsInitValue: VoidFunction;
143
143
  clearFormat: (name: string) => void;
144
+ setFieldsValueFull: (values: Record<string, any>) => void;
144
145
  }
145
146
  export interface ConnectConfigModal {
146
147
  format?: Record<string, addFormatItemModal>;
@@ -92,7 +92,7 @@ var useInfoReq = function useInfoReq(_ref) {
92
92
  return initReq(reqParams);
93
93
  case 5:
94
94
  result = _context2.sent;
95
- form === null || form === void 0 || form.setFieldsValue(result);
95
+ form === null || form === void 0 || form.setFieldsValueFull(result);
96
96
  return _context2.abrupt("return", result || {});
97
97
  case 8:
98
98
  if (!(typeof initialValues === "undefined")) {
@@ -101,7 +101,7 @@ var useInfoReq = function useInfoReq(_ref) {
101
101
  }
102
102
  return _context2.abrupt("return", {});
103
103
  case 10:
104
- form === null || form === void 0 || form.setFieldsValue(initialValues);
104
+ form === null || form === void 0 || form.setFieldsValueFull(initialValues);
105
105
  return _context2.abrupt("return", initialValues);
106
106
  case 12:
107
107
  case "end":
@@ -36,6 +36,14 @@ var useHForm = (function () {
36
36
  defaultFn: []
37
37
  };
38
38
  };
39
+ var clearObj = function clearObj(val) {
40
+ var newVal = _objectSpread({}, val);
41
+ var keys = Object.keys(val);
42
+ keys.forEach(function (key) {
43
+ newVal[key] = undefined;
44
+ });
45
+ return newVal;
46
+ };
39
47
  var formatValuesFn = function formatValuesFn() {
40
48
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
41
49
  var formatKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "inputValue";
@@ -180,6 +188,17 @@ var useHForm = (function () {
180
188
  var newValue = formatValuesFn(values);
181
189
  form.setFieldsValue(newValue);
182
190
  },
191
+ setFieldsValueFull: function setFieldsValueFull(values) {
192
+ if (!isLoading) {
193
+ cacheValues = values;
194
+ return;
195
+ }
196
+ var oldFormVal = form.getFieldsValue(true);
197
+ var formatVal = formatValuesFn(oldFormVal, "outputValue");
198
+ var newValue = formatValuesFn(values);
199
+ var clearData = clearObj(_objectSpread(_objectSpread({}, formatVal), oldFormVal));
200
+ form.setFieldsValue(_objectSpread(_objectSpread({}, clearData), newValue));
201
+ },
183
202
  validateFields: function validateFields(nameList) {
184
203
  return new Promise(function (resolve, reject) {
185
204
  form.validateFields(nameList).then(function (value) {
@@ -141,6 +141,7 @@ export interface HFormInstance extends FormInstance {
141
141
  clear: VoidFunction;
142
142
  resetFieldsInitValue: VoidFunction;
143
143
  clearFormat: (name: string) => void;
144
+ setFieldsValueFull: (values: Record<string, any>) => void;
144
145
  }
145
146
  export interface ConnectConfigModal {
146
147
  format?: Record<string, addFormatItemModal>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "1.9.33",
3
+ "version": "1.9.35",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -61,13 +61,13 @@ export const useInfoReq = ({
61
61
  reqData.params = reqParams;
62
62
  if (initReq) {
63
63
  const result = await initReq(reqParams);
64
- form?.setFieldsValue(result);
64
+ form?.setFieldsValueFull(result);
65
65
  return result || {};
66
66
  }
67
67
  if (typeof initialValues === "undefined") {
68
68
  return {};
69
69
  }
70
- form?.setFieldsValue(initialValues);
70
+ form?.setFieldsValueFull(initialValues);
71
71
  return initialValues;
72
72
  },options);
73
73
  const { run, mutate } = infoControl;
@@ -34,6 +34,14 @@ export default () => {
34
34
  defaultFn: [],
35
35
  };
36
36
  };
37
+ const clearObj=(val)=>{
38
+ const newVal={...val};
39
+ const keys=Object.keys(val);
40
+ keys.forEach((key)=>{
41
+ newVal[key]=undefined;
42
+ });
43
+ return newVal;
44
+ }
37
45
  const formatValuesFn = (value = {}, formatKey = "inputValue") => {
38
46
  const valKeys = Object.keys(value).length;
39
47
  if (!valKeys) {
@@ -160,6 +168,23 @@ export default () => {
160
168
  const newValue = formatValuesFn(values);
161
169
  form.setFieldsValue(newValue);
162
170
  },
171
+ setFieldsValueFull(values){
172
+ if (!isLoading) {
173
+ cacheValues = values;
174
+ return;
175
+ }
176
+ const oldFormVal=form.getFieldsValue(true);
177
+ const formatVal=formatValuesFn(oldFormVal, "outputValue")
178
+ const newValue = formatValuesFn(values);
179
+ const clearData=clearObj({
180
+ ...formatVal,
181
+ ...oldFormVal
182
+ });
183
+ form.setFieldsValue({
184
+ ...clearData,
185
+ ...newValue
186
+ });
187
+ },
163
188
  validateFields(nameList) {
164
189
  return new Promise((resolve, reject) => {
165
190
  form
@@ -199,6 +199,7 @@ export interface HFormInstance extends FormInstance {
199
199
  clear: VoidFunction;
200
200
  resetFieldsInitValue: VoidFunction;
201
201
  clearFormat: (name: string) => void;
202
+ setFieldsValueFull:(values: Record<string, any>)=>void;
202
203
  }
203
204
 
204
205
  export interface ConnectConfigModal {
@@ -69,7 +69,7 @@ const formData = (options) => {
69
69
  return [
70
70
  {
71
71
  name: "name",
72
- label: "输入框",
72
+ label: "name",
73
73
  rules: [
74
74
  {
75
75
  validator: () => {
@@ -82,103 +82,7 @@ const formData = (options) => {
82
82
  addonAfter: "后面",
83
83
  },
84
84
  },
85
- {
86
- name: "inputNumberGroup",
87
- label: "输入框",
88
- rules: [
89
- {
90
- validator: () => {
91
- return Promise.reject(new Error("错误"));
92
- },
93
- },
94
- ],
95
- type: "inputNumberGroup",
96
- itemProps: {
97
- addonBefore: "前面",
98
- addonAfter: "后面",
99
- },
100
- },
101
- {
102
- name: "url",
103
- type: "urlUpload",
104
- label: "文本",
105
- hideLabel: true,
106
- rules: [
107
- {
108
- validator: () => {
109
- return Promise.reject(new Error("错误"));
110
- },
111
- },
112
- ],
113
- itemProps: {
114
- initValueProvider: (props, val) => {
115
- console.log(props, val, "fff");
116
- return {
117
- ...val,
118
- name: "ffffsfsadasda",
119
- };
120
- },
121
- },
122
- },
123
- {
124
- nameKey: "name1",
125
- label: "输入框",
126
- render: () => {
127
- return (
128
- <Basic
129
- configData={[
130
- {
131
- label: "1",
132
- },
133
- {
134
- label: "2",
135
- },
136
- ]}
137
- />
138
- );
139
- },
140
- },
141
- {
142
- name: "treeSelect",
143
- label: "treeSelect",
144
- type: "treeSelect",
145
- itemProps: {
146
- multiple:true,
147
- request: async () => {
148
- return [
149
- {
150
- name: "父亲",
151
- key: "1",
152
- child: [
153
- {
154
- name: "儿子",
155
- key: "1-1",
156
- },
157
- ],
158
- },
159
- ];
160
- },
161
- fieldNames: {
162
- label: "name",
163
- value: "key",
164
- children: "child",
165
- },
166
- },
167
- },
168
- {
169
- label: "输入框",
170
- type: "checkboxGroup",
171
- name: "check",
172
- hover: "你好",
173
- itemProps: {
174
- options: [
175
- {
176
- key: "vv",
177
- value: "测试",
178
- },
179
- ],
180
- },
181
- },
85
+
182
86
  ];
183
87
  };
184
88
  function Ttta({ form }) {
@@ -198,6 +102,7 @@ const Test = (props) => {
198
102
  };
199
103
  export default () => {
200
104
  const form = useHForm();
105
+ const [id,setId]=useState(1);
201
106
  const [options, setOptions] = useState([{ label: "1", value: 1 }]);
202
107
  const [aForm] = Form.useForm();
203
108
  return (
@@ -218,11 +123,29 @@ export default () => {
218
123
  value: "key",
219
124
  }}
220
125
  >
126
+ <div onClick={()=>{
127
+ setId(2);
128
+ }}>
129
+ 点我
130
+ </div>
221
131
  <HForm
222
132
  configData={formData(options)}
223
133
  dismissOnPressEnter={false}
224
134
  labelWidth={88}
225
135
  form={form}
136
+ infoRequest={{
137
+ request:async ()=>{
138
+ if (id===1){
139
+ return {
140
+ name:"你好"
141
+ };
142
+ }
143
+ return {
144
+
145
+ }
146
+ },
147
+ refreshDeps:[id]
148
+ }}
226
149
  labelAlign={"left"}
227
150
  onFinish={(value) => {
228
151
  console.log(value, "onFinish");
@@ -230,9 +153,6 @@ export default () => {
230
153
  onValuesChange={(val) => {
231
154
  console.log(val, "onValuesChange");
232
155
  }}
233
- initialValues={{
234
- name1: {},
235
- }}
236
156
  request={(params) => {
237
157
  return new Promise<any>((resolve) => {
238
158
  setTimeout(() => {