@vue-start/pro 0.3.2 → 0.4.0

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/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
- import { defineComponent, createVNode, mergeProps, isVNode, computed, reactive, inject, h, provide, ref, Fragment } from 'vue';
2
- import { map, isString, forEach, findIndex, get, isFunction, size, find, filter as filter$1, keys, omit, isArray, split, isEmpty, isObject, mergeWith, reduce, sortBy, pick, concat, isUndefined, debounce, some, clone, set, isBoolean } from 'lodash';
1
+ import { defineComponent, createVNode, mergeProps, isVNode, computed, h, inject, reactive, Fragment, provide, ref } from 'vue';
2
+ import { map, isString, forEach, reduce, size, get, set, pick, omit, isArray, some, keys, isFunction, head, isObject, findIndex, find, filter as filter$1, split, isEmpty, mergeWith, sortBy, concat, isUndefined, debounce, clone, isBoolean } from 'lodash';
3
3
  import { filter, tap, merge, Subject } from 'rxjs';
4
4
  import { useEffect, setReactiveValue, useWatch } from '@vue-start/hooks';
5
5
  import { useRequestProvide, isFailedRequestActor, isPreRequestActor, isDoneRequestActor } from '@vue-start/request';
@@ -195,186 +195,12 @@ var useComposeRequestActor = function useComposeRequestActor(actors, options, ca
195
195
  }, []);
196
196
  };
197
197
 
198
- var treeDefaultNames = {
199
- children: "children",
200
- label: "label",
201
- value: "value"
202
- };
203
- /**
204
- * 根据value从treeData中找到对象
205
- * @param data
206
- * @param value
207
- * @param fieldNames
208
- * @param cb 对象:同步 方法:回调,可以理解为异步
209
- */
210
-
211
- var findTargetInTree = function findTargetInTree(data, value, fieldNames, cb) {
212
- var index = findIndex(data, function (item) {
213
- return get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.value) || treeDefaultNames.value) === value;
214
- });
215
-
216
- if (index > -1) {
217
- if (isFunction(cb)) {
218
- cb(index, data[index], data);
219
- } else {
220
- cb.index = index;
221
- cb.target = data[index];
222
- cb.list = data;
223
- }
224
-
225
- return;
226
- }
227
-
228
- forEach(data, function (item) {
229
- var children = get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.children) || treeDefaultNames.children);
230
-
231
- if (size(children) > 0) {
232
- findTargetInTree(children, value, fieldNames, cb);
233
- }
234
- });
235
- };
236
- /**
237
- * 根据value从treeData中找出对象及父列表
238
- * @param data
239
- * @param value
240
- * @param fieldNames
241
- * @param cb
242
- * @param parent
243
- */
244
-
245
- var findTargetListInTree = function findTargetListInTree(data, value, fieldNames, cb) {
246
- var parent = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
247
- var target = find(data, function (item) {
248
- return get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.value) || treeDefaultNames.value) === value;
249
- });
250
-
251
- if (target) {
252
- if (isFunction(cb)) {
253
- cb([].concat(_toConsumableArray(parent), [target]));
254
- } else {
255
- cb.list = [].concat(_toConsumableArray(parent), [target]);
256
- }
257
-
258
- return;
259
- }
260
-
261
- forEach(data, function (item) {
262
- var children = get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.children) || treeDefaultNames.children);
263
-
264
- if (size(children) > 0) {
265
- findTargetListInTree(children, value, fieldNames, cb, [].concat(_toConsumableArray(parent), [item]));
266
- }
267
- });
268
- };
269
-
270
- /**
271
- * 剔除showState或showStateRules规则为!true的值
272
- * @param values
273
- * @param showState
274
- * @param showStateRules
275
- */
276
-
277
- var getValidValues = function getValidValues(values, showState, showStateRules) {
278
- if (showState) {
279
- var invalidKeys = filter$1(keys(showState), function (key) {
280
- return !showState[key];
281
- });
282
- return omit(values, invalidKeys);
283
- }
284
-
285
- if (showStateRules) {
286
- var _invalidKeys = filter$1(keys(showStateRules), function (key) {
287
- return !showStateRules[key](values);
288
- });
289
-
290
- return omit(values, _invalidKeys);
291
- }
292
-
293
- return values;
294
- };
295
- /**
296
- * string类型的path转为arr
297
- * @param path
298
- */
299
-
300
- var convertPathToList = function convertPathToList(path) {
301
- if (!path) {
302
- return undefined;
303
- }
304
-
305
- if (isArray(path)) {
306
- return path;
307
- }
308
-
309
- if (path && isString(path) && path.indexOf(".") > 0) {
310
- return split(path, ".");
311
- }
312
-
313
- return [path];
314
- };
315
- /**
316
- * 将listState 中的数据通过id merge到 list item中
317
- * ps:数组会替换
318
- * 注意:mergeWith 会改变原始对象
319
- * @param list
320
- * @param listState
321
- * @param id
322
- */
323
-
324
- var mergeStateToList = function mergeStateToList(list, listState, id) {
325
- if (!listState || !id) {
326
- return list;
327
- }
328
-
329
- return map(list, function (item) {
330
- var idName = isFunction(id) ? id(item) : id; //如果listState中有值,merge处理
331
-
332
- var stateData = get(listState, idName);
333
-
334
- if (!stateData || isEmpty(stateData) || isFunction(stateData) || !isObject(stateData)) {
335
- return item;
336
- } //只有是对象(键值对)才合并
337
-
338
-
339
- return mergeWith(item, stateData, function (objValue, srcValue) {
340
- //如果是数组,替换
341
- if (isArray(objValue) || isArray(srcValue)) {
342
- return srcValue;
343
- }
344
- });
345
- });
346
- };
347
-
348
- /**
349
- * 唯一id
350
- */
351
-
352
- var generateId = function generateId() {
353
- return Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36);
354
- };
355
- /**
356
- * ref 传递
357
- */
358
-
359
- var createExpose = function createExpose(methods, targetRef) {
360
- return reduce(methods, function (pair, method) {
361
- return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, method, function () {
362
- var _targetRef$value, _targetRef$value$meth;
363
-
364
- for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
365
- params[_key] = arguments[_key];
366
- }
367
-
368
- return (_targetRef$value = targetRef.value) === null || _targetRef$value === void 0 ? void 0 : (_targetRef$value$meth = _targetRef$value[method]) === null || _targetRef$value$meth === void 0 ? void 0 : _targetRef$value$meth.call.apply(_targetRef$value$meth, [_targetRef$value].concat(params));
369
- }));
370
- }, {});
371
- };
198
+ /***************************************** curd模式 *****************************************/
372
199
 
373
200
  /**
374
201
  * 获取Column的valueType,默认"text"
375
202
  * @param column
376
203
  */
377
-
378
204
  var getColumnValueType = function getColumnValueType(column) {
379
205
  return column.formValueType || column.valueType || "text";
380
206
  };
@@ -440,6 +266,213 @@ var getItemEl = function getItemEl(elementMap, column, value) {
440
266
  value: value
441
267
  }), (_column$formFieldProp2 = column.formFieldProps) === null || _column$formFieldProp2 === void 0 ? void 0 : _column$formFieldProp2.slots);
442
268
  };
269
+ /***************************************** 通用模式 *****************************************/
270
+
271
+ var renderElements = function renderElements(elementMap, elementConfigs) {
272
+ return map(elementConfigs, function (elementConfig) {
273
+ return renderElement(elementMap, elementConfig);
274
+ });
275
+ };
276
+ /**
277
+ * props转换
278
+ */
279
+
280
+ var convertPropsEl = function convertPropsEl(elementMap, elementConfig) {
281
+ var _elementConfig$highCo;
282
+
283
+ var elementProps = elementConfig.elementProps;
284
+
285
+ var nextProps = _objectSpread2({}, elementConfig.elementProps);
286
+
287
+ forEach((_elementConfig$highCo = elementConfig.highConfig$) === null || _elementConfig$highCo === void 0 ? void 0 : _elementConfig$highCo.registerPropsTrans, function (item) {
288
+ var target = get(elementProps, item.name);
289
+
290
+ if (!target || isVNode(target)) {
291
+ return;
292
+ }
293
+
294
+ if (isArray(target)) {
295
+ //如果list中存在VNode,不转换
296
+ if (some(target, function (sub) {
297
+ return isVNode(sub);
298
+ })) {
299
+ return;
300
+ } //如果碰到特殊场景,可以替换成单个渲染模式
301
+
302
+
303
+ set(nextProps, item.name, renderElements(elementMap, target));
304
+ return;
305
+ }
306
+
307
+ if (!target.elementType) {
308
+ return;
309
+ }
310
+
311
+ if (item.isFun) {
312
+ set(nextProps, item.name, function () {
313
+ for (var _len = arguments.length, params$ = new Array(_len), _key = 0; _key < _len; _key++) {
314
+ params$[_key] = arguments[_key];
315
+ }
316
+
317
+ var ep = item.needParams ? _objectSpread2(_objectSpread2({}, target.elementProps), {}, {
318
+ params$: params$
319
+ }) : target.elementProps;
320
+ return renderElement(elementMap, _objectSpread2(_objectSpread2({}, target), {}, {
321
+ elementProps: ep
322
+ }));
323
+ });
324
+ } else {
325
+ set(nextProps, item.name, renderElement(elementMap, target));
326
+ }
327
+ });
328
+ return nextProps;
329
+ };
330
+ /**
331
+ * slots转换
332
+ */
333
+
334
+
335
+ var convertSlots = function convertSlots(elementMap, elementConfig) {
336
+ var children = size(elementConfig.children) > 0 ? renderElements(elementMap, elementConfig.children) : undefined; //children插槽名称
337
+
338
+ var childrenSlotName = elementConfig.childrenSlotName || "default";
339
+ var validSlots = omit(elementConfig.slots, children ? childrenSlotName : ""); //如果slots注册的是 IElementConfig ,进行转换
340
+
341
+ forEach(keys(validSlots), function (k) {
342
+ var v = validSlots[k]; //IElementConfig
343
+
344
+ if (v && !isFunction(v) && v.elementType) {
345
+ validSlots[k] = function () {
346
+ for (var _len2 = arguments.length, params$ = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
347
+ params$[_key2] = arguments[_key2];
348
+ }
349
+
350
+ //如果需要params,在props中注入 params$
351
+ var elementProps = v.needParams ? _objectSpread2(_objectSpread2({}, v.elementProps), {}, {
352
+ params$: params$
353
+ }) : v.elementProps;
354
+ return renderElement(elementMap, _objectSpread2(_objectSpread2({}, v), {}, {
355
+ elementProps: elementProps
356
+ }));
357
+ };
358
+ }
359
+ });
360
+ return _objectSpread2(_defineProperty({}, childrenSlotName, children ? function () {
361
+ return children;
362
+ } : undefined), validSlots);
363
+ };
364
+ /**
365
+ *
366
+ * @param elementMap
367
+ * @param elementConfig
368
+ */
369
+
370
+
371
+ var renderElement = function renderElement(elementMap, elementConfig) {
372
+ var El = get(elementMap, elementConfig.elementType) || elementConfig.elementType; //如果有highConfig$,包裹一层Wrapper
373
+
374
+ if (elementConfig.highConfig$) {
375
+ return h(Wrapper, {
376
+ key: elementConfig.elementId,
377
+ elementMap: elementMap,
378
+ elementConfig: elementConfig
379
+ });
380
+ }
381
+
382
+ var slots = convertSlots(elementMap, elementConfig);
383
+ var elementProps = convertPropsEl(elementMap, elementConfig);
384
+ return h(El, _objectSpread2({
385
+ key: elementConfig.elementId
386
+ }, elementProps), slots);
387
+ };
388
+ /**
389
+ * 获取第一层级属性名
390
+ * 如:['aaa','bbb',...] 中的 'aaa'
391
+ * 如:"aaa.bbb.ccc..." 中的 'aaa'
392
+ */
393
+
394
+ var getFirstPropName = function getFirstPropName(name) {
395
+ if (isArray(name)) {
396
+ return head(name);
397
+ } else if (isString(name) && name.indexOf(".") > 0) {
398
+ return name.substring(0, name.indexOf("."));
399
+ }
400
+
401
+ return name;
402
+ };
403
+ /**
404
+ * 处理highConfig$
405
+ */
406
+
407
+ var Wrapper = defineComponent({
408
+ props: {
409
+ elementMap: {
410
+ type: Object
411
+ },
412
+ elementConfig: {
413
+ type: Object
414
+ }
415
+ },
416
+ setup: function setup(props) {
417
+ var _useProModule = useProModule(),
418
+ state = _useProModule.state,
419
+ sendEvent = _useProModule.sendEvent;
420
+
421
+ var elementMap = props.elementMap,
422
+ elementConfig = props.elementConfig;
423
+ var highConfig$ = elementConfig.highConfig$; //转换props
424
+
425
+ var elementProps = convertPropsEl(elementMap, elementConfig); //事件订阅
426
+
427
+ var events = reduce(highConfig$.registerEventList, function (pair, item) {
428
+ return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, item.name, function () {
429
+ for (var _len3 = arguments.length, params = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
430
+ params[_key3] = arguments[_key3];
431
+ }
432
+
433
+ sendEvent({
434
+ type: item.sendEventName || elementConfig.elementId,
435
+ payload: params
436
+ });
437
+ }));
438
+ }, {}); //receiveStateList 订阅
439
+
440
+ var receiveStates = computed(function () {
441
+ if (!highConfig$.registerStateList || size(highConfig$.registerStateList) <= 0) {
442
+ return undefined;
443
+ }
444
+
445
+ var changeProps = _objectSpread2({}, elementProps); //赋值 && 返回一级属性名称
446
+
447
+
448
+ var firstPropNameList = map(highConfig$.registerStateList, function (item) {
449
+ var targetName = item.mapName || item.name; //从state中取值
450
+
451
+ var value = get(state, item.name); //赋值
452
+
453
+ set(changeProps, targetName, value); //返回一级属性名称
454
+
455
+ return getFirstPropName(targetName);
456
+ });
457
+ return pick(changeProps, firstPropNameList);
458
+ });
459
+ var El = get(elementMap, elementConfig.elementType) || elementConfig.elementType;
460
+ var slots = convertSlots(elementMap, elementConfig);
461
+ return function () {
462
+ //如果标记show$值为false,不渲染组件
463
+ var show$ = get(receiveStates.value, "show$");
464
+
465
+ if (show$ === false) {
466
+ return null;
467
+ }
468
+
469
+ return h(El, _objectSpread2(_objectSpread2(_objectSpread2({
470
+ key: elementConfig.elementId
471
+ }, elementProps), omit(receiveStates.value, "show$")), events), slots);
472
+ };
473
+ }
474
+ });
475
+
443
476
  var ProModuleKey = Symbol("pro-module");
444
477
  var useProModule = function useProModule() {
445
478
  return inject(ProModuleKey);
@@ -462,32 +495,17 @@ var proModuleProps = function proModuleProps() {
462
495
  },
463
496
 
464
497
  /**
465
- * 配置(静态)
466
- */
467
- columns: {
468
- type: Array
469
- },
470
-
471
- /**
472
- * 配置(动态)
473
- * columns动态属性兼容
474
- */
475
- columnState: {
476
- type: Object
477
- },
478
-
479
- /**
480
- * 展示组件集
498
+ * 组件集
481
499
  */
482
500
  elementMap: {
483
501
  type: Object
484
502
  },
485
503
 
486
504
  /**
487
- * 录入组件集
505
+ * 组件描述(树)
488
506
  */
489
- formElementMap: {
490
- type: Object
507
+ elementConfigs: {
508
+ type: Array
491
509
  },
492
510
 
493
511
  /**
@@ -497,33 +515,21 @@ var proModuleProps = function proModuleProps() {
497
515
  type: Array
498
516
  }
499
517
  };
500
- };
501
-
502
- var ProModule = defineComponent({
503
- props: _objectSpread2({}, proModuleProps()),
504
- setup: function setup(props, _ref) {
505
- var slots = _ref.slots,
506
- expose = _ref.expose;
507
-
508
- /**
509
- * columns columnState 合并
510
- */
511
- var columns = computed(function () {
512
- return mergeStateToList(props.columns, props.columnState, function (item) {
513
- return getColumnFormItemName(item);
514
- });
515
- });
516
- /*********************************** 渲染组件 ***************************************/
517
- // 获取FormItem VNode
518
+ };
518
519
 
519
- var getFormItemVNode = function getFormItemVNode(column) {
520
- var needRules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
521
- return getFormItemEl(props.formElementMap, column, needRules);
522
- }; // 获取Item VNode
520
+ var ProModule = defineComponent({
521
+ props: _objectSpread2({}, proModuleProps()),
522
+ setup: function setup(props, _ref) {
523
+ var slots = _ref.slots,
524
+ expose = _ref.expose;
523
525
 
526
+ /*********************************** render ***************************************/
527
+ var render = function render(elementConfig) {
528
+ if (isArray(elementConfig)) {
529
+ return renderElements(props.elementMap, elementConfig);
530
+ }
524
531
 
525
- var getItemVNode = function getItemVNode(column, value) {
526
- return getItemEl(props.elementMap, column, value);
532
+ return renderElement(props.elementMap, elementConfig);
527
533
  };
528
534
  /*********************************** 事件处理 ***************************************/
529
535
 
@@ -539,13 +545,15 @@ var ProModule = defineComponent({
539
545
  var state = props.state || reactive({});
540
546
 
541
547
  var dispatch = function dispatch(action) {
542
- //如果要更新的属性值是 object ,执行覆盖操作
543
- if (isObject(state[action.type])) {
544
- setReactiveValue(state[action.type], action.payload);
548
+ var prev = state[action.type];
549
+ var data = isFunction(action.payload) ? action.payload(prev) : action.payload; //如果要更新的属性值是 object ,执行覆盖操作
550
+
551
+ if (isObject(prev)) {
552
+ setReactiveValue(state[action.type], data);
545
553
  return;
546
554
  }
547
555
 
548
- state[action.type] = action.payload;
556
+ state[action.type] = data;
549
557
  };
550
558
  /*********************************** request ***************************************/
551
559
 
@@ -649,11 +657,7 @@ var ProModule = defineComponent({
649
657
  }
650
658
  }, true);
651
659
  provideProModule({
652
- columns: columns,
653
- getFormItemVNode: getFormItemVNode,
654
- getItemVNode: getItemVNode,
655
660
  elementMap: props.elementMap,
656
- formElementMap: props.formElementMap,
657
661
  //
658
662
  subject$: subject$,
659
663
  sendEvent: sendEvent,
@@ -671,7 +675,7 @@ var ProModule = defineComponent({
671
675
  return function () {
672
676
  var _slots$default;
673
677
 
674
- return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
678
+ return createVNode(Fragment, null, [size(props.elementConfigs) > 0 && render(props.elementConfigs), (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)]);
675
679
  };
676
680
  }
677
681
  });
@@ -750,6 +754,181 @@ var CurdAddAction;
750
754
  CurdAddAction["CONTINUE"] = "CONTINUE";
751
755
  })(CurdAddAction || (CurdAddAction = {}));
752
756
 
757
+ var treeDefaultNames = {
758
+ children: "children",
759
+ label: "label",
760
+ value: "value"
761
+ };
762
+ /**
763
+ * 根据value从treeData中找到对象
764
+ * @param data
765
+ * @param value
766
+ * @param fieldNames
767
+ * @param cb 对象:同步 方法:回调,可以理解为异步
768
+ */
769
+
770
+ var findTargetInTree = function findTargetInTree(data, value, fieldNames, cb) {
771
+ var index = findIndex(data, function (item) {
772
+ return get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.value) || treeDefaultNames.value) === value;
773
+ });
774
+
775
+ if (index > -1) {
776
+ if (isFunction(cb)) {
777
+ cb(index, data[index], data);
778
+ } else {
779
+ cb.index = index;
780
+ cb.target = data[index];
781
+ cb.list = data;
782
+ }
783
+
784
+ return;
785
+ }
786
+
787
+ forEach(data, function (item) {
788
+ var children = get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.children) || treeDefaultNames.children);
789
+
790
+ if (size(children) > 0) {
791
+ findTargetInTree(children, value, fieldNames, cb);
792
+ }
793
+ });
794
+ };
795
+ /**
796
+ * 根据value从treeData中找出对象及父列表
797
+ * @param data
798
+ * @param value
799
+ * @param fieldNames
800
+ * @param cb
801
+ * @param parent
802
+ */
803
+
804
+ var findTargetListInTree = function findTargetListInTree(data, value, fieldNames, cb) {
805
+ var parent = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
806
+ var target = find(data, function (item) {
807
+ return get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.value) || treeDefaultNames.value) === value;
808
+ });
809
+
810
+ if (target) {
811
+ if (isFunction(cb)) {
812
+ cb([].concat(_toConsumableArray(parent), [target]));
813
+ } else {
814
+ cb.list = [].concat(_toConsumableArray(parent), [target]);
815
+ }
816
+
817
+ return;
818
+ }
819
+
820
+ forEach(data, function (item) {
821
+ var children = get(item, (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.children) || treeDefaultNames.children);
822
+
823
+ if (size(children) > 0) {
824
+ findTargetListInTree(children, value, fieldNames, cb, [].concat(_toConsumableArray(parent), [item]));
825
+ }
826
+ });
827
+ };
828
+
829
+ /**
830
+ * 剔除showState或showStateRules规则为!true的值
831
+ * @param values
832
+ * @param showState
833
+ * @param showStateRules
834
+ */
835
+
836
+ var getValidValues = function getValidValues(values, showState, showStateRules) {
837
+ if (showState) {
838
+ var invalidKeys = filter$1(keys(showState), function (key) {
839
+ return !showState[key];
840
+ });
841
+ return omit(values, invalidKeys);
842
+ }
843
+
844
+ if (showStateRules) {
845
+ var _invalidKeys = filter$1(keys(showStateRules), function (key) {
846
+ return !showStateRules[key](values);
847
+ });
848
+
849
+ return omit(values, _invalidKeys);
850
+ }
851
+
852
+ return values;
853
+ };
854
+ /**
855
+ * string类型的path转为arr
856
+ * @param path
857
+ */
858
+
859
+ var convertPathToList = function convertPathToList(path) {
860
+ if (!path) {
861
+ return undefined;
862
+ }
863
+
864
+ if (isArray(path)) {
865
+ return path;
866
+ }
867
+
868
+ if (path && isString(path) && path.indexOf(".") > 0) {
869
+ return split(path, ".");
870
+ }
871
+
872
+ return [path];
873
+ };
874
+ /**
875
+ * 将listState 中的数据通过id merge到 list item中
876
+ * ps:数组会替换
877
+ * 注意:mergeWith 会改变原始对象
878
+ * @param list
879
+ * @param listState
880
+ * @param id
881
+ */
882
+
883
+ var mergeStateToList = function mergeStateToList(list, listState, id) {
884
+ if (!listState || !id) {
885
+ return list;
886
+ }
887
+
888
+ return map(list, function (item) {
889
+ var idName = isFunction(id) ? id(item) : id; //如果listState中有值,merge处理
890
+
891
+ var stateData = get(listState, idName);
892
+
893
+ if (!stateData || isEmpty(stateData) || isFunction(stateData) || !isObject(stateData)) {
894
+ return item;
895
+ } //只有是对象(键值对)才合并
896
+
897
+
898
+ return mergeWith(item, stateData, function (objValue, srcValue) {
899
+ //如果是数组,替换
900
+ if (isArray(objValue) || isArray(srcValue)) {
901
+ return srcValue;
902
+ }
903
+ });
904
+ });
905
+ };
906
+
907
+ /**
908
+ * 唯一id
909
+ */
910
+
911
+ var generateId = function generateId() {
912
+ return Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36);
913
+ };
914
+ /**
915
+ * ref 传递
916
+ */
917
+
918
+ var createExpose = function createExpose(methods, targetRef) {
919
+ return reduce(methods, function (pair, method) {
920
+ return _objectSpread2(_objectSpread2({}, pair), {}, _defineProperty({}, method, function () {
921
+ var _targetRef$value, _targetRef$value$meth;
922
+
923
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
924
+ params[_key] = arguments[_key];
925
+ }
926
+
927
+ return (_targetRef$value = targetRef.value) === null || _targetRef$value === void 0 ? void 0 : (_targetRef$value$meth = _targetRef$value[method]) === null || _targetRef$value$meth === void 0 ? void 0 : _targetRef$value$meth.call.apply(_targetRef$value$meth, [_targetRef$value].concat(params));
928
+ }));
929
+ }, {});
930
+ };
931
+
753
932
  var defaultPage = {
754
933
  page: 1,
755
934
  pageSize: 10
@@ -757,16 +936,38 @@ var defaultPage = {
757
936
 
758
937
  var proCurdProps = function proCurdProps() {
759
938
  return {
760
- /**
761
- * 列表 或 详情 的唯一标识
939
+ /**
940
+ * 配置(静态)
941
+ */
942
+ columns: {
943
+ type: Array
944
+ },
945
+
946
+ /**
947
+ * 配置(动态)
948
+ * columns动态属性兼容
949
+ */
950
+ columnState: {
951
+ type: Object
952
+ },
953
+
954
+ /**
955
+ * 录入组件集
956
+ */
957
+ formElementMap: {
958
+ type: Object
959
+ },
960
+
961
+ /**
962
+ * 列表 或 详情 的唯一标识
762
963
  */
763
964
  rowKey: {
764
965
  type: String,
765
966
  "default": "id"
766
967
  },
767
968
 
768
- /**
769
- * operates
969
+ /**
970
+ * operates
770
971
  */
771
972
  operates: {
772
973
  type: Array
@@ -795,58 +996,67 @@ var Curd = defineComponent({
795
996
  expose = _ref.expose;
796
997
 
797
998
  var _ref2 = useProModule(),
798
- columns = _ref2.columns,
999
+ elementMap = _ref2.elementMap,
799
1000
  state = _ref2.state,
800
1001
  sendEvent = _ref2.sendEvent,
801
1002
  sendRequest = _ref2.sendRequest;
802
- /**
803
- * 排序
804
- * @param list
805
- * @param propName
1003
+ /**
1004
+ * columns columnState 合并
806
1005
  */
807
1006
 
808
1007
 
809
- var dealSort = function dealSort(list, propName) {
810
- return sortBy(list, function (item) {
811
- return get(item, propName);
1008
+ var columns = computed(function () {
1009
+ return mergeStateToList(props.columns, props.columnState, function (item) {
1010
+ return getColumnFormItemName(item);
812
1011
  });
1012
+ });
1013
+ /*********************************** 渲染组件 ***************************************/
1014
+ // 获取FormItem VNode
1015
+
1016
+ var getFormItemVNode = function getFormItemVNode(column) {
1017
+ var needRules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1018
+ return getFormItemEl(props.formElementMap, column, needRules);
1019
+ }; // 获取Item VNode
1020
+
1021
+
1022
+ var getItemVNode = function getItemVNode(column, value) {
1023
+ return getItemEl(elementMap, column, value);
813
1024
  };
814
- /**
815
- * hideInForm columns
1025
+ /**
1026
+ * ${signName} 配置为true 会被选择
1027
+ * @param signName
1028
+ * @param opposite 如果为true,未配置(undefined)会被选择
816
1029
  */
817
1030
 
818
1031
 
1032
+ var getSignColumns = function getSignColumns(signName, opposite) {
1033
+ var signColumns = filter$1(columns.value, function (item) {
1034
+ var sign = get(item, ["extra", signName]) || get(item, signName);
1035
+
1036
+ if (opposite) {
1037
+ //不为false 即为选中
1038
+ return sign !== false;
1039
+ } //只有true 才为选中
1040
+
1041
+
1042
+ return sign;
1043
+ });
1044
+ return sortBy(signColumns, function (item) {
1045
+ return get(item, ["extra", "".concat(signName, "Sort")]) || get(item, "".concat(signName, "Sort"));
1046
+ });
1047
+ };
1048
+
819
1049
  var formColumns = computed(function () {
820
- return dealSort(filter$1(columns.value, function (item) {
821
- return !item.hideInForm;
822
- }), "formSort");
1050
+ return getSignColumns("form", true);
823
1051
  });
824
- /**
825
- * 非 hideInDetail columns
826
- */
827
-
828
1052
  var descColumns = computed(function () {
829
- return dealSort(filter$1(columns.value, function (item) {
830
- return !item.hideInDetail;
831
- }), "descSort");
1053
+ return getSignColumns("detail", true);
832
1054
  });
833
- /**
834
- * 非 hideInTable columns
835
- */
836
-
837
1055
  var tableColumns = computed(function () {
838
- return dealSort(filter$1(columns.value, function (item) {
839
- return !item.hideInTable;
840
- }), "tableSort");
1056
+ return getSignColumns("table", true);
841
1057
  });
842
- /**
843
- * search columns
844
- */
845
-
846
1058
  var searchColumns = computed(function () {
847
- return dealSort(filter$1(columns.value, function (item) {
848
- return !!item.search;
849
- }), "searchSort");
1059
+ return getSignColumns("search");
850
1060
  });
851
1061
  /******************************** 逻辑 *************************************/
852
1062
  //上一次发起列表请求的参数
@@ -931,6 +1141,13 @@ var Curd = defineComponent({
931
1141
  return props.modalProps;
932
1142
  });
933
1143
  provideProCurd({
1144
+ columns: columns,
1145
+ getSignColumns: getSignColumns,
1146
+ getFormItemVNode: getFormItemVNode,
1147
+ getItemVNode: getItemVNode,
1148
+ elementMap: elementMap,
1149
+ formElementMap: props.formElementMap,
1150
+ //
934
1151
  rowKey: props.rowKey,
935
1152
  curdState: state,
936
1153
  formColumns: formColumns,
@@ -1412,14 +1629,17 @@ function _isSlot(s) {
1412
1629
 
1413
1630
  var createCurdDesc = function createCurdDesc(Descriptions, DescriptionsItem) {
1414
1631
  return defineComponent({
1415
- props: _objectSpread2({}, Descriptions.props),
1632
+ props: _objectSpread2(_objectSpread2({}, Descriptions.props), {}, {
1633
+ //重写Item content
1634
+ renderItem: {
1635
+ type: Function
1636
+ }
1637
+ }),
1416
1638
  setup: function setup(props, _ref) {
1417
1639
  var slots = _ref.slots;
1418
1640
 
1419
- var _useProModule = useProModule(),
1420
- getItemVNode = _useProModule.getItemVNode;
1421
-
1422
1641
  var _useProCurd = useProCurd(),
1642
+ getItemVNode = _useProCurd.getItemVNode,
1423
1643
  curdState = _useProCurd.curdState,
1424
1644
  descColumns = _useProCurd.descColumns;
1425
1645
 
@@ -1427,6 +1647,14 @@ var createCurdDesc = function createCurdDesc(Descriptions, DescriptionsItem) {
1427
1647
  return map(descColumns.value, function (item) {
1428
1648
  var _slot;
1429
1649
 
1650
+ var _props$renderItem;
1651
+
1652
+ var vn = (_props$renderItem = props.renderItem) === null || _props$renderItem === void 0 ? void 0 : _props$renderItem.call(props, item);
1653
+
1654
+ if (vn) {
1655
+ return vn;
1656
+ }
1657
+
1430
1658
  var value = get(curdState.detailData, item.dataIndex);
1431
1659
  return createVNode(DescriptionsItem, mergeProps({
1432
1660
  "key": item.dataIndex,
@@ -1443,7 +1671,7 @@ var createCurdDesc = function createCurdDesc(Descriptions, DescriptionsItem) {
1443
1671
 
1444
1672
  return createVNode(Descriptions, props, _objectSpread2({
1445
1673
  "default": function _default() {
1446
- return [(_slots$start = slots.start) === null || _slots$start === void 0 ? void 0 : _slots$start.call(slots), descVNodes, (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)];
1674
+ return [(_slots$start = slots.start) === null || _slots$start === void 0 ? void 0 : _slots$start.call(slots), descVNodes.value, (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)];
1447
1675
  }
1448
1676
  }, omit(slots, "default", "start")));
1449
1677
  };
@@ -1488,11 +1716,9 @@ var createCurdForm = function createCurdForm(Form, Button, convertFormProps) {
1488
1716
  setup: function setup(props, _ref) {
1489
1717
  var slots = _ref.slots;
1490
1718
 
1491
- var _useProModule = useProModule(),
1492
- elementMap = _useProModule.elementMap,
1493
- formElementMap = _useProModule.formElementMap;
1494
-
1495
1719
  var _useProCurd = useProCurd(),
1720
+ elementMap = _useProCurd.elementMap,
1721
+ formElementMap = _useProCurd.formElementMap,
1496
1722
  curdState = _useProCurd.curdState,
1497
1723
  formColumns = _useProCurd.formColumns,
1498
1724
  sendCurdEvent = _useProCurd.sendCurdEvent;
@@ -1601,11 +1827,9 @@ var createCurdList = function createCurdList(SearchForm, Table) {
1601
1827
  setup: function setup(props, _ref) {
1602
1828
  var slots = _ref.slots;
1603
1829
 
1604
- var _useProModule = useProModule(),
1605
- elementMap = _useProModule.elementMap,
1606
- formElementMap = _useProModule.formElementMap;
1607
-
1608
1830
  var _useProCurd = useProCurd(),
1831
+ elementMap = _useProCurd.elementMap,
1832
+ formElementMap = _useProCurd.formElementMap,
1609
1833
  curdState = _useProCurd.curdState,
1610
1834
  searchColumns = _useProCurd.searchColumns,
1611
1835
  tableColumns = _useProCurd.tableColumns,
@@ -2452,4 +2676,4 @@ var createTable = function createTable(Table, Props) {
2452
2676
  });
2453
2677
  };
2454
2678
 
2455
- export { CurdAction, CurdAddAction, CurdCurrentMode, CurdSubAction, ProCurd, ProModalCurd, ProModule, ProPageCurd, RequestAction, SearchMode, convertPathToList, createCurdDesc, createCurdForm, createCurdList, createExpose, createForm, createFormItemCompFn, createFormList, createGrid, createSearchForm, createTable, defaultPage, findTargetInTree, findTargetListInTree, generateId, getColumnFormItemName, getColumnValueType, getFormItemEl, getItemEl, getValidValues, mergeStateToList, provideProCurd, provideProModule, useComposeRequestActor, useDoneRequestActor, useFailedRequestActor, useModuleEvent, useProCurd, useProForm, useProFormList, useProModule, useProTable };
2679
+ export { CurdAction, CurdAddAction, CurdCurrentMode, CurdSubAction, ProCurd, ProModalCurd, ProModule, ProPageCurd, RequestAction, SearchMode, Wrapper, convertPathToList, createCurdDesc, createCurdForm, createCurdList, createExpose, createForm, createFormItemCompFn, createFormList, createGrid, createSearchForm, createTable, defaultPage, findTargetInTree, findTargetListInTree, generateId, getColumnFormItemName, getColumnValueType, getFirstPropName, getFormItemEl, getItemEl, getValidValues, mergeStateToList, provideProCurd, provideProModule, renderElement, renderElements, useComposeRequestActor, useDoneRequestActor, useFailedRequestActor, useModuleEvent, useProCurd, useProForm, useProFormList, useProModule, useProTable };