@teamix/pro 1.2.34 → 1.2.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.
- package/dist/pro.css +1 -1
- package/dist/pro.js +301 -195
- package/dist/pro.min.css +1 -1
- package/dist/pro.min.js +1 -1
- package/es/form/Filter/index.js +185 -121
- package/es/form/Filter/useSpecialProps.d.ts +1 -1
- package/es/form/Filter/useSpecialProps.js +9 -9
- package/es/form/SchemaForm/index.js +2 -2
- package/es/form/SchemaForm/initializeDataSource.d.ts +1 -1
- package/es/form/SchemaForm/initializeDataSource.js +2 -2
- package/es/form/SchemaForm/reactions.d.ts +1 -1
- package/es/form/SchemaForm/reactions.js +28 -15
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/page-header/index.js +3 -3
- package/es/table/index.js +14 -9
- package/es/table/typing.d.ts +2 -0
- package/lib/form/Filter/index.js +184 -120
- package/lib/form/Filter/useSpecialProps.d.ts +1 -1
- package/lib/form/Filter/useSpecialProps.js +8 -8
- package/lib/form/SchemaForm/index.js +2 -2
- package/lib/form/SchemaForm/initializeDataSource.d.ts +1 -1
- package/lib/form/SchemaForm/initializeDataSource.js +2 -2
- package/lib/form/SchemaForm/reactions.d.ts +1 -1
- package/lib/form/SchemaForm/reactions.js +28 -15
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/page-header/index.js +2 -2
- package/lib/table/index.js +14 -9
- package/lib/table/typing.d.ts +2 -0
- package/package.json +1 -1
package/es/form/Filter/index.js
CHANGED
@@ -40,7 +40,7 @@ import debounce from 'lodash.debounce';
|
|
40
40
|
import { Tag } from '@alicloudfe/components';
|
41
41
|
import { createForm, onFormReact, onFormInputChange } from '@formily/core';
|
42
42
|
import { toJS } from '@formily/reactive';
|
43
|
-
import { usePrefixCls,
|
43
|
+
import { usePrefixCls, isUsable, isNum, getValidValues } from '@teamix/utils';
|
44
44
|
import ProField from '../../field/index';
|
45
45
|
import fieldTypeMap from '../fieldTypeMap';
|
46
46
|
import { getFormDisplayValues } from '../ProForm/useFormDisplayValues';
|
@@ -67,16 +67,43 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
67
67
|
onInit = props.onInit,
|
68
68
|
onReset = props.onReset,
|
69
69
|
onExpand = props.onExpand,
|
70
|
-
otherProps = _objectWithoutProperties(props, _excluded);
|
70
|
+
otherProps = _objectWithoutProperties(props, _excluded);
|
71
71
|
|
72
|
+
var _useSpecialProps = useSpecialProps(props),
|
73
|
+
hasDefault = _useSpecialProps.hasDefault,
|
74
|
+
hasChangeDefault = _useSpecialProps.hasChangeDefault,
|
75
|
+
hasRequired = _useSpecialProps.hasRequired;
|
76
|
+
|
77
|
+
var hasDefaultOrRequired = hasDefault || hasRequired;
|
78
|
+
|
79
|
+
var _useState = useState(!!expand),
|
80
|
+
_useState2 = _slicedToArray(_useState, 2),
|
81
|
+
panelVisible = _useState2[0],
|
82
|
+
setPanelVisible = _useState2[1];
|
83
|
+
|
84
|
+
var _useState3 = useState([]),
|
85
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
86
|
+
tagDataSource = _useState4[0],
|
87
|
+
setTagDataSource = _useState4[1];
|
88
|
+
|
89
|
+
var filterItem = useRef([]);
|
90
|
+
var defaultForm = mode === 'panel' ? hasDefaultOrRequired || panelVisible ? 'advanced' : 'light' : 'simple';
|
91
|
+
var currentForm = useRef(defaultForm);
|
92
|
+
var prefixCls = usePrefixCls('', {
|
93
|
+
prefix: 'teamix-pro-form-query-filter'
|
94
|
+
});
|
95
|
+
/**
|
96
|
+
* 处理onInit与onFilter事件的触发问题
|
97
|
+
*/
|
72
98
|
|
73
|
-
var
|
99
|
+
var filterEnable = useRef('waiting');
|
100
|
+
|
101
|
+
var _onFormInit = function onFormInit(form, _ref) {
|
74
102
|
var initialRequest = _ref.initialRequest,
|
75
|
-
initialValues = _ref.initialValues
|
76
|
-
onInit = _ref.onInit;
|
103
|
+
initialValues = _ref.initialValues;
|
77
104
|
|
78
105
|
if (!form.mounted) {
|
79
|
-
// form
|
106
|
+
// 在form上自定义loading属性使用
|
80
107
|
form.setState({
|
81
108
|
loading: !!initialRequest || !!initialValues
|
82
109
|
});
|
@@ -84,32 +111,27 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
84
111
|
|
85
112
|
var loadingField = Object.values(form.fields).filter(function (field) {
|
86
113
|
return !!field.loading;
|
87
|
-
});
|
114
|
+
}); // 等待表单mounted + 字段loading结束 + form的loading结束 => 表单初始化完成
|
88
115
|
|
89
|
-
if (form.mounted) {
|
116
|
+
if (form.mounted && loadingField.length === 0 && !form.loading) {
|
90
117
|
if (loadingField.length === 0 && !form.loading) {
|
91
|
-
//
|
92
|
-
_onFormInit = function onFormInit() {};
|
118
|
+
_onFormInit = function onFormInit() {}; // init后销毁 isFormInit 方法
|
93
119
|
|
94
|
-
var onInitResult = onInit === null || onInit === void 0 ? void 0 : onInit(toJS(form.values));
|
95
120
|
|
96
|
-
|
97
|
-
// 根据onInit返回值,判断是否使用该事件执行筛选,使用过则添加筛选标签
|
98
|
-
configFilterItem === null || configFilterItem === void 0 ? void 0 : configFilterItem(form);
|
99
|
-
configTag();
|
100
|
-
} // 防止onInit前后的无效onFilter
|
121
|
+
var values = getValidValues(form.values);
|
101
122
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
123
|
+
if (!isUsable(values) || !hasChangeDefault) {
|
124
|
+
// 表单无默认值 或 无触发onChange的默认值配置,不会触发onFilter内的onInit,所以主动触发onInit
|
125
|
+
setTimeout(function () {
|
126
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(toJS(form.values));
|
127
|
+
}, 0);
|
128
|
+
filterEnable.current = 'filter';
|
106
129
|
} else {
|
107
|
-
|
108
|
-
filterEnable.current = form.initialValues;
|
130
|
+
filterEnable.current = 'initialized';
|
109
131
|
}
|
110
132
|
}
|
111
133
|
}
|
112
|
-
}; //
|
134
|
+
}; // 配置当前激活的form实例
|
113
135
|
|
114
136
|
|
115
137
|
var setCurrentForm = function setCurrentForm(formName) {
|
@@ -131,7 +153,9 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
131
153
|
validateFirst: true,
|
132
154
|
effects: function effects() {
|
133
155
|
onFormReact(function (form) {
|
134
|
-
|
156
|
+
if (defaultForm === 'simple') {
|
157
|
+
_onFormInit(form, props);
|
158
|
+
}
|
135
159
|
});
|
136
160
|
}
|
137
161
|
});
|
@@ -141,8 +165,13 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
141
165
|
return createForm({
|
142
166
|
validateFirst: true,
|
143
167
|
effects: function effects() {
|
168
|
+
onFormReact(function (form) {
|
169
|
+
if (defaultForm === 'light') {
|
170
|
+
_onFormInit(form, props);
|
171
|
+
}
|
172
|
+
});
|
144
173
|
onFormInputChange(function () {
|
145
|
-
setCurrentForm('light');
|
174
|
+
setCurrentForm('light'); // 主动修改轻量筛选值
|
146
175
|
});
|
147
176
|
}
|
148
177
|
});
|
@@ -153,11 +182,12 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
153
182
|
validateFirst: true,
|
154
183
|
effects: function effects() {
|
155
184
|
onFormReact(function (form) {
|
156
|
-
|
185
|
+
if (defaultForm === 'advanced') {
|
186
|
+
_onFormInit(form, props);
|
187
|
+
}
|
157
188
|
});
|
158
189
|
onFormInputChange(function (form) {
|
159
|
-
// 主动修改高级筛选值
|
160
|
-
setCurrentForm('advanced');
|
190
|
+
setCurrentForm('advanced'); // 主动修改高级筛选值
|
161
191
|
});
|
162
192
|
}
|
163
193
|
});
|
@@ -166,35 +196,7 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
166
196
|
simple: simpleForm,
|
167
197
|
light: lightForm,
|
168
198
|
advanced: advancedForm
|
169
|
-
};
|
170
|
-
|
171
|
-
var _useSpecialProps = useSpecialProps(props),
|
172
|
-
hasDefault = _useSpecialProps.hasDefault,
|
173
|
-
hasAsyncDefault = _useSpecialProps.hasAsyncDefault,
|
174
|
-
hasRequired = _useSpecialProps.hasRequired;
|
175
|
-
|
176
|
-
var hasDefaultOrRequired = hasDefault || hasAsyncDefault || hasRequired;
|
177
|
-
|
178
|
-
var _useState = useState(!!expand),
|
179
|
-
_useState2 = _slicedToArray(_useState, 2),
|
180
|
-
advancedFilterVisible = _useState2[0],
|
181
|
-
setAdvancedFilterVisible = _useState2[1];
|
182
|
-
|
183
|
-
var _useState3 = useState([]),
|
184
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
185
|
-
tagDataSource = _useState4[0],
|
186
|
-
setTagDataSource = _useState4[1];
|
187
|
-
|
188
|
-
var filterItem = useRef([]);
|
189
|
-
var currentForm = useRef(mode === 'panel' ? advancedFilterVisible ? 'advanced' : 'light' : 'simple');
|
190
|
-
var filterEnable = useRef(false);
|
191
|
-
var prefixCls = usePrefixCls('', {
|
192
|
-
prefix: 'teamix-pro-form-query-filter'
|
193
|
-
}); // 设置筛选数据
|
194
|
-
|
195
|
-
var configFilterItem = useCallback(function (form) {
|
196
|
-
filterItem.current = getFilterDisplayValues(form);
|
197
|
-
}, []); // 获取筛选数据Label
|
199
|
+
}; // 获取筛选数据Label
|
198
200
|
|
199
201
|
var getFilterDisplayValues = useCallback(function (form) {
|
200
202
|
var displayValues = getFormDisplayValues(form);
|
@@ -222,7 +224,7 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
222
224
|
index: index
|
223
225
|
});
|
224
226
|
});
|
225
|
-
} else if (
|
227
|
+
} else if (isUsable(value)) {
|
226
228
|
filterData.push({
|
227
229
|
key: key,
|
228
230
|
type: fieldTypeMap[component] || 'text',
|
@@ -232,63 +234,58 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
232
234
|
}
|
233
235
|
});
|
234
236
|
return filterData;
|
237
|
+
}, []); // 设置筛选数据
|
238
|
+
|
239
|
+
var configFilterItem = useCallback(function (form) {
|
240
|
+
filterItem.current = getFilterDisplayValues(form);
|
235
241
|
}, []); // 设置标签数据
|
236
242
|
|
237
243
|
var configTag = useCallback(function () {
|
238
244
|
setTagDataSource(filterItem.current);
|
239
|
-
}, [
|
245
|
+
}, []); // 展开收起高级筛选
|
240
246
|
|
241
247
|
var toggleAdvancedFilter = useCallback(function () {
|
242
|
-
var result = !
|
248
|
+
var result = !panelVisible;
|
243
249
|
|
244
250
|
if (result) {
|
245
251
|
// 展开高级筛选,Light回填Advanced
|
246
252
|
if (currentForm.current === 'light') {
|
247
|
-
|
253
|
+
Object.entries(lightForm.values || {}).map(function (_ref4) {
|
254
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
255
|
+
key = _ref5[0],
|
256
|
+
value = _ref5[1];
|
257
|
+
|
258
|
+
// 有效值值回填,防止全部值回填改变,触发不必要的 reactions
|
259
|
+
advancedForm.setValuesIn(key, value);
|
260
|
+
});
|
248
261
|
}
|
249
262
|
} else {
|
250
263
|
// 收起高级筛选,配置标签数据
|
251
264
|
configTag();
|
252
265
|
}
|
253
266
|
|
254
|
-
|
267
|
+
setPanelVisible(result);
|
255
268
|
onExpand === null || onExpand === void 0 ? void 0 : onExpand(result);
|
256
|
-
}, [
|
257
|
-
|
258
|
-
var enableFilter = function enableFilter(values) {
|
259
|
-
var initialValues = JSON.stringify(getValidValues(filterEnable.current));
|
260
|
-
var changeValues = JSON.stringify(getValidValues(values));
|
261
|
-
|
262
|
-
if (filterEnable.current === true) {
|
263
|
-
return true;
|
264
|
-
} else if (initialValues === changeValues) {
|
265
|
-
filterEnable.current = true;
|
266
|
-
return false;
|
267
|
-
}
|
268
|
-
|
269
|
-
return false;
|
270
|
-
}; // 简单搜索Filter
|
271
|
-
|
269
|
+
}, [panelVisible, configTag]); // 简单搜索Filter
|
272
270
|
|
273
271
|
var onSimpleFilter = useCallback( /*#__PURE__*/function () {
|
274
|
-
var
|
272
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(values) {
|
275
273
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
276
274
|
while (1) {
|
277
275
|
switch (_context.prev = _context.next) {
|
278
276
|
case 0:
|
279
|
-
if (
|
280
|
-
_context.next =
|
277
|
+
if (!(currentForm.current === 'simple')) {
|
278
|
+
_context.next = 14;
|
281
279
|
break;
|
282
280
|
}
|
283
281
|
|
284
|
-
|
285
|
-
|
286
|
-
case 2:
|
287
|
-
if (!(currentForm.current === 'simple')) {
|
288
|
-
_context.next = 7;
|
282
|
+
if (!(filterEnable.current === 'initialized')) {
|
283
|
+
_context.next = 9;
|
289
284
|
break;
|
290
285
|
}
|
291
286
|
|
287
|
+
filterEnable.current = 'filter';
|
288
|
+
|
292
289
|
if (!hasRequired) {
|
293
290
|
_context.next = 6;
|
294
291
|
break;
|
@@ -298,9 +295,28 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
298
295
|
return simpleForm.validate();
|
299
296
|
|
300
297
|
case 6:
|
298
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(values);
|
299
|
+
_context.next = 14;
|
300
|
+
break;
|
301
|
+
|
302
|
+
case 9:
|
303
|
+
if (!(filterEnable.current === 'filter')) {
|
304
|
+
_context.next = 14;
|
305
|
+
break;
|
306
|
+
}
|
307
|
+
|
308
|
+
if (!hasRequired) {
|
309
|
+
_context.next = 13;
|
310
|
+
break;
|
311
|
+
}
|
312
|
+
|
313
|
+
_context.next = 13;
|
314
|
+
return simpleForm.validate();
|
315
|
+
|
316
|
+
case 13:
|
301
317
|
onFilter === null || onFilter === void 0 ? void 0 : onFilter(values);
|
302
318
|
|
303
|
-
case
|
319
|
+
case 14:
|
304
320
|
case "end":
|
305
321
|
return _context.stop();
|
306
322
|
}
|
@@ -309,39 +325,49 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
309
325
|
}));
|
310
326
|
|
311
327
|
return function (_x) {
|
312
|
-
return
|
328
|
+
return _ref6.apply(this, arguments);
|
313
329
|
};
|
314
|
-
}(), [onFilter,
|
330
|
+
}(), [onFilter, hasRequired, onInit]); // 轻量搜索Filter
|
315
331
|
|
316
332
|
var onLightFilter = useCallback( /*#__PURE__*/function () {
|
317
|
-
var
|
333
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(values) {
|
318
334
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
319
335
|
while (1) {
|
320
336
|
switch (_context2.prev = _context2.next) {
|
321
337
|
case 0:
|
322
|
-
if (
|
323
|
-
_context2.next =
|
338
|
+
if (!(currentForm.current === 'light')) {
|
339
|
+
_context2.next = 14;
|
324
340
|
break;
|
325
341
|
}
|
326
342
|
|
327
|
-
|
328
|
-
|
329
|
-
case 2:
|
330
|
-
if (!(currentForm.current === 'light')) {
|
343
|
+
if (!(filterEnable.current === 'initialized')) {
|
331
344
|
_context2.next = 8;
|
332
345
|
break;
|
333
346
|
}
|
334
347
|
|
348
|
+
filterEnable.current = 'filter';
|
349
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(values);
|
350
|
+
configFilterItem(advancedForm);
|
351
|
+
configTag();
|
352
|
+
_context2.next = 14;
|
353
|
+
break;
|
354
|
+
|
355
|
+
case 8:
|
356
|
+
if (!(filterEnable.current === 'filter')) {
|
357
|
+
_context2.next = 14;
|
358
|
+
break;
|
359
|
+
}
|
360
|
+
|
335
361
|
onFilter === null || onFilter === void 0 ? void 0 : onFilter(values);
|
336
|
-
_context2.next =
|
362
|
+
_context2.next = 12;
|
337
363
|
return advancedForm.reset();
|
338
364
|
|
339
|
-
case
|
365
|
+
case 12:
|
340
366
|
// 不会触发高级筛选的onReset回调函数
|
341
367
|
configFilterItem(advancedForm);
|
342
368
|
configTag();
|
343
369
|
|
344
|
-
case
|
370
|
+
case 14:
|
345
371
|
case "end":
|
346
372
|
return _context2.stop();
|
347
373
|
}
|
@@ -350,33 +376,70 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
350
376
|
}));
|
351
377
|
|
352
378
|
return function (_x2) {
|
353
|
-
return
|
379
|
+
return _ref7.apply(this, arguments);
|
354
380
|
};
|
355
|
-
}(), [onFilter,
|
381
|
+
}(), [onFilter, onInit]); // 高级搜索Filter by Submit
|
356
382
|
|
357
383
|
var onAdvancedFilter = useCallback(function (values) {
|
358
|
-
if (!enableFilter(values)) {
|
359
|
-
return;
|
360
|
-
}
|
361
|
-
|
362
384
|
setCurrentForm('advanced');
|
363
385
|
onFilter === null || onFilter === void 0 ? void 0 : onFilter(values);
|
364
386
|
configFilterItem(advancedForm);
|
365
387
|
lightForm.reset();
|
366
|
-
}, [onFilter
|
367
|
-
|
368
|
-
var onAdvancedChange = useCallback(function (values) {
|
369
|
-
if (!enableFilter(values)) {
|
370
|
-
return;
|
371
|
-
}
|
372
|
-
}, [enableFilter]); // 高级搜索Reset
|
388
|
+
}, [onFilter]); // 高级搜索Reset
|
373
389
|
|
374
390
|
var onAdvancedReset = useCallback(function () {
|
375
391
|
setCurrentForm('advanced');
|
376
392
|
onReset === null || onReset === void 0 ? void 0 : onReset(toJS(advancedForm.values));
|
377
393
|
configFilterItem(advancedForm);
|
378
394
|
lightForm.reset();
|
379
|
-
}, [onReset]); //
|
395
|
+
}, [onReset]); // 高级搜索Filter by Change
|
396
|
+
|
397
|
+
var onAdvancedChange = useCallback( /*#__PURE__*/function () {
|
398
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(values) {
|
399
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
400
|
+
while (1) {
|
401
|
+
switch (_context3.prev = _context3.next) {
|
402
|
+
case 0:
|
403
|
+
if (!(currentForm.current === 'advanced')) {
|
404
|
+
_context3.next = 9;
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
|
408
|
+
if (!(filterEnable.current === 'initialized')) {
|
409
|
+
_context3.next = 9;
|
410
|
+
break;
|
411
|
+
}
|
412
|
+
|
413
|
+
filterEnable.current = 'filter';
|
414
|
+
|
415
|
+
if (!hasRequired) {
|
416
|
+
_context3.next = 6;
|
417
|
+
break;
|
418
|
+
}
|
419
|
+
|
420
|
+
_context3.next = 6;
|
421
|
+
return advancedForm.validate();
|
422
|
+
|
423
|
+
case 6:
|
424
|
+
onInit === null || onInit === void 0 ? void 0 : onInit(values);
|
425
|
+
configFilterItem(advancedForm);
|
426
|
+
|
427
|
+
if (!panelVisible) {
|
428
|
+
configTag();
|
429
|
+
}
|
430
|
+
|
431
|
+
case 9:
|
432
|
+
case "end":
|
433
|
+
return _context3.stop();
|
434
|
+
}
|
435
|
+
}
|
436
|
+
}, _callee3);
|
437
|
+
}));
|
438
|
+
|
439
|
+
return function (_x3) {
|
440
|
+
return _ref8.apply(this, arguments);
|
441
|
+
};
|
442
|
+
}(), [hasRequired, onInit]); // 关闭标签清空表单字段值
|
380
443
|
|
381
444
|
var onTagClose = useCallback(function (key, index) {
|
382
445
|
var newValue = undefined;
|
@@ -396,7 +459,8 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
396
459
|
form.setState({
|
397
460
|
loading: false
|
398
461
|
});
|
399
|
-
}, []);
|
462
|
+
}, []); // 组件挂载
|
463
|
+
|
400
464
|
useEffect(function () {
|
401
465
|
setCurrentForm(currentForm.current);
|
402
466
|
}, []);
|
@@ -404,7 +468,7 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
404
468
|
className: cls(prefixCls, props.className),
|
405
469
|
addonBefore: addonBefore,
|
406
470
|
addonAfter: addonAfter,
|
407
|
-
expand:
|
471
|
+
expand: panelVisible,
|
408
472
|
onExpand: toggleAdvancedFilter,
|
409
473
|
count: tagDataSource.length,
|
410
474
|
inlineContent: mode === 'panel' ? /*#__PURE__*/React.createElement("div", {
|
@@ -428,12 +492,12 @@ var QueryFilter = /*#__PURE__*/memo(function (props) {
|
|
428
492
|
onReset: onAdvancedReset,
|
429
493
|
onInitialComplete: onInitialComplete
|
430
494
|
})) : null
|
431
|
-
}, mode === 'panel' && !
|
432
|
-
var key =
|
433
|
-
label =
|
434
|
-
value =
|
435
|
-
type =
|
436
|
-
index =
|
495
|
+
}, mode === 'panel' && !panelVisible ? /*#__PURE__*/React.createElement(Tag.Group, null, tagDataSource.map(function (_ref9) {
|
496
|
+
var key = _ref9.key,
|
497
|
+
label = _ref9.label,
|
498
|
+
value = _ref9.value,
|
499
|
+
type = _ref9.type,
|
500
|
+
index = _ref9.index;
|
437
501
|
return /*#__PURE__*/React.createElement(Tag.Closeable, {
|
438
502
|
key: isNum(index) ? key + label : key,
|
439
503
|
afterClose: function afterClose() {
|
@@ -1,10 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { isUsable, isStr, isPureObj } from '@teamix/utils'; // 获取Schema是否包含默认值、异步默认值、必选校验等
|
2
2
|
|
3
3
|
var useSpecialProps = function useSpecialProps(props) {
|
4
4
|
var initialValues = props.initialValues,
|
5
5
|
initialRequest = props.initialRequest;
|
6
|
-
var
|
7
|
-
|
6
|
+
var hasChangeDefault = !!initialValues || !!initialRequest; // 会触发onChange的默认值
|
7
|
+
|
8
|
+
var hasDefault = hasChangeDefault;
|
8
9
|
var hasRequired = false;
|
9
10
|
|
10
11
|
var hasDefaultOrRule = function hasDefaultOrRule(schema) {
|
@@ -12,13 +13,12 @@ var useSpecialProps = function useSpecialProps(props) {
|
|
12
13
|
var value = item.default,
|
13
14
|
required = item.required,
|
14
15
|
rules = item.rules,
|
15
|
-
request = item.request,
|
16
16
|
dataSource = item.dataSource,
|
17
|
-
children = item.children;
|
18
|
-
|
17
|
+
children = item.children; // 字符串变量配置default值会触发onChange
|
18
|
+
|
19
|
+
hasChangeDefault = hasChangeDefault || !!(isPureObj(dataSource) && isStr(value) && value.indexOf('.dataSource'));
|
20
|
+
hasDefault = hasDefault || isUsable(value);
|
19
21
|
hasRequired = hasRequired || required || !!rules;
|
20
|
-
hasAsyncDefault = hasAsyncDefault || !!request || // 如果dataSource是异步且default取自dataSource
|
21
|
-
!!(isPlainObj(dataSource) && isStr(value) && value.indexOf('.dataSource'));
|
22
22
|
|
23
23
|
if (children === null || children === void 0 ? void 0 : children.length) {
|
24
24
|
hasDefaultOrRule(children);
|
@@ -29,7 +29,7 @@ var useSpecialProps = function useSpecialProps(props) {
|
|
29
29
|
hasDefaultOrRule(props.schema);
|
30
30
|
return {
|
31
31
|
hasDefault: hasDefault,
|
32
|
-
|
32
|
+
hasChangeDefault: hasChangeDefault,
|
33
33
|
hasRequired: hasRequired
|
34
34
|
};
|
35
35
|
};
|
@@ -200,10 +200,10 @@ export default /*#__PURE__*/memo(function (_ref) {
|
|
200
200
|
|
201
201
|
var _initializeRequest = initializeRequest(request, "".concat(suffix, "r")),
|
202
202
|
requestReactions = _initializeRequest.reactions,
|
203
|
-
requestScope = _initializeRequest.scope; // 初始化dataSource
|
203
|
+
requestScope = _initializeRequest.scope; // 初始化dataSource,如果readPretty为字符串表达式将失去loading等状态,仍可配置dataSource
|
204
204
|
|
205
205
|
|
206
|
-
var _initializeDataSource = initializeDataSource(dataSource, "".concat(suffix, "d")),
|
206
|
+
var _initializeDataSource = initializeDataSource(dataSource, "".concat(suffix, "d"), newItem.readPretty),
|
207
207
|
defaultDataSource = _initializeDataSource.dataSource,
|
208
208
|
dataSourceReactions = _initializeDataSource.reactions,
|
209
209
|
dataSourceScope = _initializeDataSource.scope; // 初始化rules validator
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ProFormRequestConfig } from '../typing';
|
2
2
|
interface IInitializeDataSource {
|
3
|
-
(requestConfig?: ProFormRequestConfig | any, suffix?: string): {
|
3
|
+
(requestConfig?: ProFormRequestConfig | any, suffix?: string, readPretty?: string | boolean): {
|
4
4
|
dataSource?: any[];
|
5
5
|
reactions: any[];
|
6
6
|
scope: {
|
@@ -2,12 +2,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
2
2
|
|
3
3
|
import { isPlainObj } from '@teamix/utils';
|
4
4
|
|
5
|
-
var initializeDataSource = function initializeDataSource(dataSource, suffix) {
|
5
|
+
var initializeDataSource = function initializeDataSource(dataSource, suffix, readPretty) {
|
6
6
|
if (isPlainObj(dataSource)) {
|
7
7
|
var requestConfig = dataSource;
|
8
8
|
var requestConfigName = "$requestConfig_".concat(suffix);
|
9
9
|
return {
|
10
|
-
reactions: ["{{$dataSource($request,".concat(requestConfigName, ",context)}}")],
|
10
|
+
reactions: ["{{$dataSource($request,".concat(requestConfigName, ",context,").concat(readPretty, ")}}")],
|
11
11
|
scope: _defineProperty({}, requestConfigName, requestConfig)
|
12
12
|
};
|
13
13
|
}
|
@@ -2,5 +2,5 @@ import type { ProFormRequestConfig } from '../typing';
|
|
2
2
|
declare const $request: (field: any, requestConfig: ProFormRequestConfig, context: any, type: string | number) => Promise<unknown>;
|
3
3
|
declare const $common: (services: any, requestConfig: ProFormRequestConfig, context: any, index: string) => (field: any) => any;
|
4
4
|
declare const $validator: (services: any, requestConfig: ProFormRequestConfig, context: any) => (value: any, rules: any, { field }: any) => any;
|
5
|
-
declare const $dataSource: (services: any, requestConfig: ProFormRequestConfig, context: any) => (field: any) => any;
|
5
|
+
declare const $dataSource: (services: any, requestConfig: ProFormRequestConfig, context: any, readPretty: any) => (field: any) => any;
|
6
6
|
export { $request, $common, $dataSource, $validator };
|
@@ -52,28 +52,41 @@ var $validator = function $validator(services, requestConfig, context) {
|
|
52
52
|
}; // 配置DataSource
|
53
53
|
|
54
54
|
|
55
|
-
var $dataSource = function $dataSource(services, requestConfig, context) {
|
55
|
+
var $dataSource = function $dataSource(services, requestConfig, context, readPretty) {
|
56
56
|
return function (field) {
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
if (!readPretty) {
|
58
|
+
field.setState({
|
59
|
+
loading: true,
|
60
|
+
readOnly: true
|
61
|
+
});
|
62
|
+
}
|
63
|
+
|
64
|
+
return services(field, requestConfig, context).then(function (res) {
|
62
65
|
var isValueInDataSource = getValueByValue(res, field.value);
|
63
66
|
var clearValue = isValueInDataSource ? {} : {
|
64
67
|
value: undefined
|
65
68
|
};
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
|
70
|
+
if (!readPretty) {
|
71
|
+
field.setState(_objectSpread({
|
72
|
+
dataSource: res,
|
73
|
+
loading: false,
|
74
|
+
readOnly: false
|
75
|
+
}, clearValue));
|
76
|
+
} else {
|
77
|
+
field.setState({
|
78
|
+
dataSource: res
|
79
|
+
});
|
80
|
+
}
|
81
|
+
|
71
82
|
return requestConfig.onComplete && requestConfig.onComplete(res, field, context);
|
72
83
|
}).catch(function () {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
84
|
+
if (!readPretty) {
|
85
|
+
field.setState({
|
86
|
+
loading: false,
|
87
|
+
readOnly: false
|
88
|
+
});
|
89
|
+
}
|
77
90
|
});
|
78
91
|
};
|
79
92
|
};
|
package/es/index.d.ts
CHANGED
@@ -24,5 +24,5 @@ export * from './skeleton';
|
|
24
24
|
export * from './table';
|
25
25
|
export * from './utils';
|
26
26
|
export * from './step';
|
27
|
-
declare const version = "1.2.
|
27
|
+
declare const version = "1.2.35";
|
28
28
|
export { version, ProAction, ProCard, ProField, ProForm, ProInfo, ProPageContainer, ProPageHeader, ProSkeleton, ProTable, ProStep, hooks, nocode, templates, utils, };
|
package/es/index.js
CHANGED
@@ -30,7 +30,7 @@ export * from './table';
|
|
30
30
|
export * from './utils'; // export * from './sidebar';
|
31
31
|
|
32
32
|
export * from './step';
|
33
|
-
var version = '1.2.
|
33
|
+
var version = '1.2.35';
|
34
34
|
export { version, ProAction, ProCard, ProField, ProForm, ProInfo, // ProLayout,
|
35
35
|
ProPageContainer, ProPageHeader, ProSkeleton, ProTable, // ProSidebar,
|
36
36
|
ProStep, hooks, nocode, templates, utils };
|