@vue-start/pro 0.3.1 → 0.4.1

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, computed, reactive, inject, h, provide, ref, createVNode, mergeProps, Fragment } from 'vue';
2
- import { map, isString, forEach, filter as filter$1, keys, omit, isArray, split, isFunction, get, isEmpty, isObject, mergeWith, reduce, sortBy, pick, debounce, size, 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';
@@ -79,6 +79,50 @@ function _nonIterableSpread() {
79
79
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
80
80
  }
81
81
 
82
+ function _isSlot$1(s) {
83
+ return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
84
+ }
85
+
86
+ var proGridProps = function proGridProps() {
87
+ return {
88
+ row: {
89
+ type: Object,
90
+ "default": undefined
91
+ },
92
+ col: {
93
+ type: Object
94
+ },
95
+ items: {
96
+ type: Array
97
+ }
98
+ };
99
+ };
100
+
101
+ var createGrid = function createGrid(Row, Col) {
102
+ return defineComponent({
103
+ props: _objectSpread2({}, proGridProps()),
104
+ setup: function setup(props) {
105
+ return function () {
106
+ var _slot;
107
+
108
+ return createVNode(Row, props.row, _isSlot$1(_slot = map(props.items, function (item) {
109
+ return createVNode(Col, mergeProps({
110
+ "key": item.rowKey
111
+ }, props.col, item.col), {
112
+ "default": function _default() {
113
+ return [item.vNode];
114
+ }
115
+ });
116
+ })) ? _slot : {
117
+ "default": function _default() {
118
+ return [_slot];
119
+ }
120
+ });
121
+ };
122
+ }
123
+ });
124
+ };
125
+
82
126
  var createUseRequestActor = function createUseRequestActor(filterFun) {
83
127
  return function (actors, callback) {
84
128
  var _useRequestProvide = useRequestProvide(),
@@ -151,94 +195,12 @@ var useComposeRequestActor = function useComposeRequestActor(actors, options, ca
151
195
  }, []);
152
196
  };
153
197
 
154
- /**
155
- * 剔除showState或showStateRules规则为!true的值
156
- * @param values
157
- * @param showState
158
- * @param showStateRules
159
- */
160
- var getValidValues = function getValidValues(values, showState, showStateRules) {
161
- if (showState) {
162
- var invalidKeys = filter$1(keys(showState), function (key) {
163
- return !showState[key];
164
- });
165
- return omit(values, invalidKeys);
166
- }
167
-
168
- if (showStateRules) {
169
- var _invalidKeys = filter$1(keys(showStateRules), function (key) {
170
- return !showStateRules[key](values);
171
- });
172
-
173
- return omit(values, _invalidKeys);
174
- }
175
-
176
- return values;
177
- };
178
- /**
179
- * string类型的path转为arr
180
- * @param path
181
- */
182
-
183
- var convertPathToList = function convertPathToList(path) {
184
- if (!path) {
185
- return undefined;
186
- }
187
-
188
- if (isArray(path)) {
189
- return path;
190
- }
191
-
192
- if (path && isString(path) && path.indexOf(".") > 0) {
193
- return split(path, ".");
194
- }
195
-
196
- return [path];
197
- };
198
- /**
199
- * 唯一id
200
- */
201
-
202
- var generateId = function generateId() {
203
- return Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36);
204
- };
205
- /**
206
- * 将listState 中的数据通过id merge到 list item中
207
- * ps:数组会替换
208
- * @param list
209
- * @param listState
210
- * @param id
211
- */
212
-
213
- var mergeStateToList = function mergeStateToList(list, listState, id) {
214
- if (!listState || !id) {
215
- return list;
216
- }
217
-
218
- return map(list, function (item) {
219
- var idName = isFunction(id) ? id(item) : id; //如果listState中有值,merge处理
220
-
221
- var stateData = get(listState, idName);
222
-
223
- if (!stateData || isEmpty(stateData) || isFunction(stateData) || !isObject(stateData)) {
224
- return item;
225
- } //只有是对象(键值对)才合并
226
-
227
-
228
- return mergeWith(item, stateData, function (objValue, srcValue) {
229
- //如果是数组,替换
230
- if (isArray(objValue) || isArray(srcValue)) {
231
- return srcValue;
232
- }
233
- });
234
- });
235
- };
198
+ /***************************************** curd模式 *****************************************/
236
199
 
237
200
  /**
238
201
  * 获取Column的valueType,默认"text"
239
202
  * @param column
240
203
  */
241
-
242
204
  var getColumnValueType = function getColumnValueType(column) {
243
205
  return column.formValueType || column.valueType || "text";
244
206
  };
@@ -304,6 +266,213 @@ var getItemEl = function getItemEl(elementMap, column, value) {
304
266
  value: value
305
267
  }), (_column$formFieldProp2 = column.formFieldProps) === null || _column$formFieldProp2 === void 0 ? void 0 : _column$formFieldProp2.slots);
306
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
+
307
476
  var ProModuleKey = Symbol("pro-module");
308
477
  var useProModule = function useProModule() {
309
478
  return inject(ProModuleKey);
@@ -326,32 +495,17 @@ var proModuleProps = function proModuleProps() {
326
495
  },
327
496
 
328
497
  /**
329
- * 配置(静态)
330
- */
331
- columns: {
332
- type: Array
333
- },
334
-
335
- /**
336
- * 配置(动态)
337
- * columns动态属性兼容
338
- */
339
- columnState: {
340
- type: Object
341
- },
342
-
343
- /**
344
- * 展示组件集
498
+ * 组件集
345
499
  */
346
500
  elementMap: {
347
501
  type: Object
348
502
  },
349
503
 
350
504
  /**
351
- * 录入组件集
505
+ * 组件描述(树)
352
506
  */
353
- formElementMap: {
354
- type: Object
507
+ elementConfigs: {
508
+ type: Array
355
509
  },
356
510
 
357
511
  /**
@@ -369,25 +523,13 @@ var ProModule = defineComponent({
369
523
  var slots = _ref.slots,
370
524
  expose = _ref.expose;
371
525
 
372
- /**
373
- * columns columnState 合并
374
- */
375
- var columns = computed(function () {
376
- return mergeStateToList(props.columns, props.columnState, function (item) {
377
- return getColumnFormItemName(item);
378
- });
379
- });
380
- /*********************************** 渲染组件 ***************************************/
381
- // 获取FormItem VNode
382
-
383
- var getFormItemVNode = function getFormItemVNode(column) {
384
- var needRules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
385
- return getFormItemEl(props.formElementMap, column, needRules);
386
- }; // 获取Item VNode
387
-
526
+ /*********************************** render ***************************************/
527
+ var render = function render(elementConfig) {
528
+ if (isArray(elementConfig)) {
529
+ return renderElements(props.elementMap, elementConfig);
530
+ }
388
531
 
389
- var getItemVNode = function getItemVNode(column, value) {
390
- return getItemEl(props.elementMap, column, value);
532
+ return renderElement(props.elementMap, elementConfig);
391
533
  };
392
534
  /*********************************** 事件处理 ***************************************/
393
535
 
@@ -403,13 +545,15 @@ var ProModule = defineComponent({
403
545
  var state = props.state || reactive({});
404
546
 
405
547
  var dispatch = function dispatch(action) {
406
- //如果要更新的属性值是 object ,执行覆盖操作
407
- if (isObject(state[action.type])) {
408
- 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);
409
553
  return;
410
554
  }
411
555
 
412
- state[action.type] = action.payload;
556
+ state[action.type] = data;
413
557
  };
414
558
  /*********************************** request ***************************************/
415
559
 
@@ -513,11 +657,7 @@ var ProModule = defineComponent({
513
657
  }
514
658
  }, true);
515
659
  provideProModule({
516
- columns: columns,
517
- getFormItemVNode: getFormItemVNode,
518
- getItemVNode: getItemVNode,
519
660
  elementMap: props.elementMap,
520
- formElementMap: props.formElementMap,
521
661
  //
522
662
  subject$: subject$,
523
663
  sendEvent: sendEvent,
@@ -535,7 +675,7 @@ var ProModule = defineComponent({
535
675
  return function () {
536
676
  var _slots$default;
537
677
 
538
- 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)]);
539
679
  };
540
680
  }
541
681
  });
@@ -614,20 +754,217 @@ var CurdAddAction;
614
754
  CurdAddAction["CONTINUE"] = "CONTINUE";
615
755
  })(CurdAddAction || (CurdAddAction = {}));
616
756
 
617
- var defaultPage = {
618
- page: 1,
619
- pageSize: 10
757
+ var treeDefaultNames = {
758
+ children: "children",
759
+ label: "label",
760
+ value: "value"
620
761
  };
762
+ /**
763
+ * 根据value从treeData中找到对象
764
+ * @param data
765
+ * @param value
766
+ * @param fieldNames
767
+ * @param cb 对象:同步 方法:回调,可以理解为异步
768
+ */
621
769
 
622
- var proCurdProps = function proCurdProps() {
623
- return {
624
- /**
625
- * 列表 或 详情 的唯一标识
626
- */
627
- rowKey: {
628
- type: String,
629
- "default": "id"
630
- },
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
+
932
+ var defaultPage = {
933
+ page: 1,
934
+ pageSize: 10
935
+ };
936
+
937
+ var proCurdProps = function proCurdProps() {
938
+ return {
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
+ * 列表 或 详情 的唯一标识
963
+ */
964
+ rowKey: {
965
+ type: String,
966
+ "default": "id"
967
+ },
631
968
 
632
969
  /**
633
970
  * operates
@@ -659,58 +996,67 @@ var Curd = defineComponent({
659
996
  expose = _ref.expose;
660
997
 
661
998
  var _ref2 = useProModule(),
662
- columns = _ref2.columns,
999
+ elementMap = _ref2.elementMap,
663
1000
  state = _ref2.state,
664
1001
  sendEvent = _ref2.sendEvent,
665
1002
  sendRequest = _ref2.sendRequest;
666
1003
  /**
667
- * 排序
668
- * @param list
669
- * @param propName
1004
+ * columns columnState 合并
670
1005
  */
671
1006
 
672
1007
 
673
- var dealSort = function dealSort(list, propName) {
674
- return sortBy(list, function (item) {
675
- return get(item, propName);
1008
+ var columns = computed(function () {
1009
+ return mergeStateToList(props.columns, props.columnState, function (item) {
1010
+ return getColumnFormItemName(item);
676
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);
677
1024
  };
678
1025
  /**
679
- * hideInForm columns
1026
+ * ${signName} 配置为true 会被选择
1027
+ * @param signName
1028
+ * @param opposite 如果为true,未配置(undefined)会被选择
680
1029
  */
681
1030
 
682
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
+
683
1049
  var formColumns = computed(function () {
684
- return dealSort(filter$1(columns.value, function (item) {
685
- return !item.hideInForm;
686
- }), "formSort");
1050
+ return getSignColumns("form", true);
687
1051
  });
688
- /**
689
- * 非 hideInDetail columns
690
- */
691
-
692
1052
  var descColumns = computed(function () {
693
- return dealSort(filter$1(columns.value, function (item) {
694
- return !item.hideInDetail;
695
- }), "descSort");
1053
+ return getSignColumns("detail", true);
696
1054
  });
697
- /**
698
- * 非 hideInTable columns
699
- */
700
-
701
1055
  var tableColumns = computed(function () {
702
- return dealSort(filter$1(columns.value, function (item) {
703
- return !item.hideInTable;
704
- }), "tableSort");
1056
+ return getSignColumns("table", true);
705
1057
  });
706
- /**
707
- * search columns
708
- */
709
-
710
1058
  var searchColumns = computed(function () {
711
- return dealSort(filter$1(columns.value, function (item) {
712
- return !!item.search;
713
- }), "searchSort");
1059
+ return getSignColumns("search");
714
1060
  });
715
1061
  /******************************** 逻辑 *************************************/
716
1062
  //上一次发起列表请求的参数
@@ -795,6 +1141,13 @@ var Curd = defineComponent({
795
1141
  return props.modalProps;
796
1142
  });
797
1143
  provideProCurd({
1144
+ columns: columns,
1145
+ getSignColumns: getSignColumns,
1146
+ getFormItemVNode: getFormItemVNode,
1147
+ getItemVNode: getItemVNode,
1148
+ elementMap: elementMap,
1149
+ formElementMap: props.formElementMap,
1150
+ //
798
1151
  rowKey: props.rowKey,
799
1152
  curdState: state,
800
1153
  formColumns: formColumns,
@@ -1270,97 +1623,525 @@ var ProPageCurd = defineComponent({
1270
1623
  }
1271
1624
  });
1272
1625
 
1273
- var ProFormKey = Symbol("pro-form");
1274
- var useProForm = function useProForm() {
1275
- return inject(ProFormKey);
1276
- };
1626
+ function _isSlot(s) {
1627
+ return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
1628
+ }
1277
1629
 
1278
- var provideProForm = function provideProForm(ctx) {
1279
- provide(ProFormKey, ctx);
1630
+ var createCurdDesc = function createCurdDesc(Descriptions, DescriptionsItem) {
1631
+ return defineComponent({
1632
+ props: _objectSpread2(_objectSpread2({}, Descriptions.props), {}, {
1633
+ //重写Item content
1634
+ renderItem: {
1635
+ type: Function
1636
+ }
1637
+ }),
1638
+ setup: function setup(props, _ref) {
1639
+ var slots = _ref.slots;
1640
+
1641
+ var _useProCurd = useProCurd(),
1642
+ getItemVNode = _useProCurd.getItemVNode,
1643
+ curdState = _useProCurd.curdState,
1644
+ descColumns = _useProCurd.descColumns;
1645
+
1646
+ var descVNodes = computed(function () {
1647
+ return map(descColumns.value, function (item) {
1648
+ var _slot;
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
+
1658
+ var value = get(curdState.detailData, item.dataIndex);
1659
+ return createVNode(DescriptionsItem, mergeProps({
1660
+ "key": item.dataIndex,
1661
+ "label": item.title
1662
+ }, get(item.extra, "desc")), _isSlot(_slot = getItemVNode(item, value)) ? _slot : {
1663
+ "default": function _default() {
1664
+ return [_slot];
1665
+ }
1666
+ });
1667
+ });
1668
+ });
1669
+ return function () {
1670
+ var _slots$start, _slots$default;
1671
+
1672
+ return createVNode(Descriptions, props, _objectSpread2({
1673
+ "default": function _default() {
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)];
1675
+ }
1676
+ }, omit(slots, "default", "start")));
1677
+ };
1678
+ }
1679
+ });
1280
1680
  };
1281
1681
 
1282
- var proFormProps = function proFormProps() {
1682
+ var proCurdAddOrEditProps = function proCurdAddOrEditProps() {
1283
1683
  return {
1284
- /**
1285
- * 同 antd 或 element form中的model
1286
- */
1287
- model: {
1288
- type: Object
1289
- },
1290
-
1291
- /**
1292
- * 子组件是否只读样式
1293
- */
1294
- readonly: {
1684
+ //是否使用operate bar
1685
+ operateBar: {
1295
1686
  type: Boolean,
1296
- "default": undefined
1297
- },
1298
-
1299
- /**
1300
- * FormComponent 根据此项来确定组件是否显示
1301
- * rules 根据rules中方法生成showState对象
1302
- */
1303
- showState: {
1304
- type: Object
1687
+ "default": true
1305
1688
  },
1306
- showStateRules: {
1307
- type: Object
1689
+ //显示 确定并继续 按钮
1690
+ showContinueAdd: {
1691
+ type: Boolean,
1692
+ "default": false
1308
1693
  },
1309
-
1310
- /**
1311
- * 是否只读
1312
- */
1313
- readonlyState: {
1314
- type: Object
1694
+ //
1695
+ okText: {
1696
+ type: String,
1697
+ "default": "确定"
1315
1698
  },
1316
- readonlyStateRules: {
1699
+ okButtonProps: {
1317
1700
  type: Object
1318
1701
  },
1319
-
1320
- /**
1321
- * 是否disabled
1322
- */
1323
- disableState: {
1324
- type: Object
1702
+ //
1703
+ continueText: {
1704
+ type: String,
1705
+ "default": "确定并继续"
1325
1706
  },
1326
- disableStateRules: {
1707
+ continueButtonProps: {
1327
1708
  type: Object
1328
- },
1709
+ }
1710
+ };
1711
+ };
1329
1712
 
1330
- /**
1331
- *
1332
- */
1333
- columns: {
1713
+ var createCurdForm = function createCurdForm(Form, Button, convertFormProps) {
1714
+ return defineComponent({
1715
+ props: _objectSpread2(_objectSpread2({}, Form.props), proCurdAddOrEditProps()),
1716
+ setup: function setup(props, _ref) {
1717
+ var slots = _ref.slots;
1718
+
1719
+ var _useProCurd = useProCurd(),
1720
+ elementMap = _useProCurd.elementMap,
1721
+ formElementMap = _useProCurd.formElementMap,
1722
+ curdState = _useProCurd.curdState,
1723
+ formColumns = _useProCurd.formColumns,
1724
+ sendCurdEvent = _useProCurd.sendCurdEvent;
1725
+
1726
+ var formRef = ref();
1727
+
1728
+ var handleFinish = function handleFinish(values) {
1729
+ if (curdState.mode === CurdCurrentMode.EDIT) {
1730
+ //edit
1731
+ sendCurdEvent({
1732
+ action: CurdAction.EDIT,
1733
+ type: CurdSubAction.EXECUTE,
1734
+ values: values
1735
+ });
1736
+ } else {
1737
+ //add
1738
+ sendCurdEvent({
1739
+ action: CurdAction.ADD,
1740
+ type: CurdSubAction.EXECUTE,
1741
+ values: values
1742
+ });
1743
+ }
1744
+ };
1745
+
1746
+ var handleAdd = function handleAdd() {
1747
+ var _formRef$value;
1748
+
1749
+ curdState.addAction = CurdAddAction.NORMAL;
1750
+ (_formRef$value = formRef.value) === null || _formRef$value === void 0 ? void 0 : _formRef$value.submit();
1751
+ };
1752
+
1753
+ var handleContinueAdd = function handleContinueAdd() {
1754
+ var _formRef$value2;
1755
+
1756
+ curdState.addAction = CurdAddAction.CONTINUE;
1757
+ (_formRef$value2 = formRef.value) === null || _formRef$value2 === void 0 ? void 0 : _formRef$value2.submit();
1758
+ };
1759
+
1760
+ return function () {
1761
+ var _slots$divide, _slots$operateStart, _slots$operateCenter, _slots$operateEnd, _slots$default;
1762
+
1763
+ return createVNode(Form, mergeProps({
1764
+ "ref": formRef
1765
+ }, props, {
1766
+ "elementMap": props.elementMap || elementMap,
1767
+ "formElementMap": props.formElementMap || formElementMap,
1768
+ "columns": formColumns.value,
1769
+ "model": curdState.detailData,
1770
+ "readonly": curdState.mode === CurdCurrentMode.DETAIL,
1771
+ "onFinish": handleFinish
1772
+ }, convertFormProps === null || convertFormProps === void 0 ? void 0 : convertFormProps(curdState)), _objectSpread2({
1773
+ "default": function _default() {
1774
+ return [(_slots$divide = slots.divide) === null || _slots$divide === void 0 ? void 0 : _slots$divide.call(slots), props.operateBar && createVNode("div", {
1775
+ "class": "pro-curd-form-operate"
1776
+ }, [(_slots$operateStart = slots.operateStart) === null || _slots$operateStart === void 0 ? void 0 : _slots$operateStart.call(slots), curdState.mode !== CurdCurrentMode.DETAIL && createVNode(Button, mergeProps({
1777
+ "onClick": handleAdd
1778
+ }, props.okButtonProps, {
1779
+ "loading": curdState.operateLoading
1780
+ }), {
1781
+ "default": function _default() {
1782
+ return [props.okText];
1783
+ }
1784
+ }), (_slots$operateCenter = slots.operateCenter) === null || _slots$operateCenter === void 0 ? void 0 : _slots$operateCenter.call(slots), props.showContinueAdd && curdState.mode === CurdCurrentMode.ADD && createVNode(Button, mergeProps({
1785
+ "onClick": handleContinueAdd
1786
+ }, props.continueButtonProps, {
1787
+ "loading": curdState.operateLoading
1788
+ }), {
1789
+ "default": function _default() {
1790
+ return [props.continueText];
1791
+ }
1792
+ }), (_slots$operateEnd = slots.operateEnd) === null || _slots$operateEnd === void 0 ? void 0 : _slots$operateEnd.call(slots)]), (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)];
1793
+ }
1794
+ }, omit(slots, "default", "divide", "operateStart", "operateCenter", "operateEnd")));
1795
+ };
1796
+ }
1797
+ });
1798
+ };
1799
+
1800
+ var proCurdListProps = function proCurdListProps() {
1801
+ return {
1802
+ /**
1803
+ * extra 是否放到SearchForm中
1804
+ */
1805
+ extraInSearch: {
1806
+ type: Boolean,
1807
+ "default": undefined
1808
+ },
1809
+ //search
1810
+ searchProps: {
1811
+ type: Object
1812
+ },
1813
+ //table
1814
+ tableProps: {
1815
+ type: Object
1816
+ },
1817
+ //pageState
1818
+ pageState: {
1819
+ type: Object
1820
+ }
1821
+ };
1822
+ };
1823
+
1824
+ var createCurdList = function createCurdList(SearchForm, Table) {
1825
+ return defineComponent({
1826
+ props: _objectSpread2({}, proCurdListProps()),
1827
+ setup: function setup(props, _ref) {
1828
+ var slots = _ref.slots;
1829
+
1830
+ var _useProCurd = useProCurd(),
1831
+ elementMap = _useProCurd.elementMap,
1832
+ formElementMap = _useProCurd.formElementMap,
1833
+ curdState = _useProCurd.curdState,
1834
+ searchColumns = _useProCurd.searchColumns,
1835
+ tableColumns = _useProCurd.tableColumns,
1836
+ getOperate = _useProCurd.getOperate,
1837
+ sendCurdEvent = _useProCurd.sendCurdEvent;
1838
+ /******************* search pagination ********************/
1839
+
1840
+
1841
+ var pageState = props.pageState || reactive(_objectSpread2({}, defaultPage));
1842
+ var prevValues;
1843
+
1844
+ var handleSearch = function handleSearch() {
1845
+ sendCurdEvent({
1846
+ action: CurdAction.LIST,
1847
+ type: CurdSubAction.EMIT,
1848
+ values: _objectSpread2(_objectSpread2({}, prevValues), pageState)
1849
+ });
1850
+ };
1851
+
1852
+ var executeSearchWithResetPage = function executeSearchWithResetPage(values) {
1853
+ prevValues = values;
1854
+ pageState.page = 1;
1855
+ handleSearch();
1856
+ };
1857
+ /******************* table ********************/
1858
+
1859
+
1860
+ var createTableItem = function createTableItem(action) {
1861
+ var operate = getOperate(action);
1862
+
1863
+ var item = _objectSpread2(_objectSpread2({}, pick(operate, "label", "element", "disabled", "sort", "onClick")), {}, {
1864
+ show: !isUndefined(operate === null || operate === void 0 ? void 0 : operate.show) ? operate === null || operate === void 0 ? void 0 : operate.show : false,
1865
+ value: action
1866
+ });
1867
+
1868
+ if (!item.onClick) {
1869
+ return _objectSpread2(_objectSpread2({}, item), {}, {
1870
+ onClick: function onClick(record) {
1871
+ //默认发送事件
1872
+ sendCurdEvent({
1873
+ action: action,
1874
+ type: CurdSubAction.EMIT,
1875
+ record: record
1876
+ });
1877
+ }
1878
+ });
1879
+ }
1880
+
1881
+ return item;
1882
+ }; //table操作栏 items
1883
+
1884
+
1885
+ var tableOperateItems = [createTableItem(CurdAction.DETAIL), createTableItem(CurdAction.EDIT), createTableItem(CurdAction.DELETE)]; //新配置的operate item,添加默认发送事件方法
1886
+
1887
+ var convertOperateItems = function convertOperateItems(list) {
1888
+ return map(list, function (item) {
1889
+ if (!item.onClick) {
1890
+ return _objectSpread2(_objectSpread2({}, item), {}, {
1891
+ onClick: function onClick(record) {
1892
+ sendCurdEvent({
1893
+ action: "operate",
1894
+ type: item.value,
1895
+ record: record
1896
+ });
1897
+ }
1898
+ });
1899
+ }
1900
+
1901
+ return item;
1902
+ });
1903
+ };
1904
+
1905
+ return function () {
1906
+ var _props$searchProps, _slots$divide, _curdState$listData, _slots$divide2, _slots$footerStart, _slots$pagination, _curdState$listData2, _slots$footerEnd;
1907
+
1908
+ var tableProps = props.tableProps;
1909
+ var extra = slots.extra ? createVNode("div", {
1910
+ "class": "pro-curd-list-extra"
1911
+ }, [slots.extra()]) : null;
1912
+ return createVNode(Fragment, null, [createVNode(SearchForm, mergeProps({
1913
+ "formElementMap": formElementMap
1914
+ }, omit(props.searchProps, "slots"), {
1915
+ "columns": searchColumns.value,
1916
+ "onFinish": executeSearchWithResetPage
1917
+ }), _objectSpread2({
1918
+ "default": function _default() {
1919
+ return [props.extraInSearch && extra];
1920
+ }
1921
+ }, (_props$searchProps = props.searchProps) === null || _props$searchProps === void 0 ? void 0 : _props$searchProps.slots)), (_slots$divide = slots.divide) === null || _slots$divide === void 0 ? void 0 : _slots$divide.call(slots), !props.extraInSearch && extra, slots.table ? slots.table() : createVNode(Table, mergeProps({
1922
+ "elementMap": elementMap
1923
+ }, omit(tableProps, "slots", "operate"), {
1924
+ "operate": mergeWith({
1925
+ items: tableOperateItems
1926
+ }, tableProps === null || tableProps === void 0 ? void 0 : tableProps.operate, function (objValue, srcValue) {
1927
+ if (isArray(objValue) && isArray(srcValue)) {
1928
+ return concat(objValue, convertOperateItems(srcValue));
1929
+ }
1930
+ }),
1931
+ "paginationState": {
1932
+ page: pageState.page,
1933
+ pageSize: pageState.pageSize
1934
+ },
1935
+ "columns": tableColumns.value,
1936
+ "loading": curdState.listLoading,
1937
+ "dataSource": (_curdState$listData = curdState.listData) === null || _curdState$listData === void 0 ? void 0 : _curdState$listData.dataSource
1938
+ }), tableProps === null || tableProps === void 0 ? void 0 : tableProps.slots), (_slots$divide2 = slots.divide2) === null || _slots$divide2 === void 0 ? void 0 : _slots$divide2.call(slots), createVNode("div", {
1939
+ "class": "pro-curd-list-footer"
1940
+ }, [(_slots$footerStart = slots.footerStart) === null || _slots$footerStart === void 0 ? void 0 : _slots$footerStart.call(slots), (_slots$pagination = slots.pagination) === null || _slots$pagination === void 0 ? void 0 : _slots$pagination.call(slots, pageState, (_curdState$listData2 = curdState.listData) === null || _curdState$listData2 === void 0 ? void 0 : _curdState$listData2.total, handleSearch), (_slots$footerEnd = slots.footerEnd) === null || _slots$footerEnd === void 0 ? void 0 : _slots$footerEnd.call(slots)])]);
1941
+ };
1942
+ }
1943
+ });
1944
+ };
1945
+
1946
+ /**
1947
+ * ProFormList ctx
1948
+ */
1949
+
1950
+ var ProFormListKey = Symbol("pro-form-list");
1951
+ var useProFormList = function useProFormList() {
1952
+ return inject(ProFormListKey);
1953
+ };
1954
+ var provideProFormList = function provideProFormList(ctx) {
1955
+ provide(ProFormListKey, ctx);
1956
+ };
1957
+ var FormListProvider = defineComponent({
1958
+ props: {
1959
+ pathList: {
1960
+ type: Array
1961
+ }
1962
+ },
1963
+ setup: function setup(props, _ref) {
1964
+ var slots = _ref.slots;
1965
+ provideProFormList({
1966
+ pathList: props.pathList
1967
+ });
1968
+ return function () {
1969
+ var _slots$default;
1970
+
1971
+ return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
1972
+ };
1973
+ }
1974
+ });
1975
+
1976
+ var createFormList = function createFormList(FormItem) {
1977
+ return defineComponent({
1978
+ props: _objectSpread2(_objectSpread2({}, FormItem.props), {}, {
1979
+ //每行默认id
1980
+ rowKey: {
1981
+ type: String,
1982
+ "default": "id"
1983
+ }
1984
+ }),
1985
+ setup: function setup(props, _ref2) {
1986
+ var slots = _ref2.slots;
1987
+
1988
+ var _useProForm = useProForm(),
1989
+ formState = _useProForm.formState,
1990
+ readonly = _useProForm.readonly;
1991
+
1992
+ var formListCtx = useProFormList();
1993
+ var nameList = convertPathToList(props.name);
1994
+ var path = formListCtx !== null && formListCtx !== void 0 && formListCtx.pathList ? [].concat(_toConsumableArray(formListCtx.pathList), _toConsumableArray(nameList)) : nameList;
1995
+
1996
+ var handleAdd = function handleAdd() {
1997
+ var targetList = get(formState, path);
1998
+
1999
+ if (!isArray(targetList)) {
2000
+ targetList = [];
2001
+ }
2002
+
2003
+ targetList.push(_defineProperty({}, props.rowKey, new Date().valueOf()));
2004
+ set(formState, path, targetList);
2005
+ };
2006
+
2007
+ var handleRemove = function handleRemove(index) {
2008
+ var targetList = get(formState, path);
2009
+
2010
+ if (size(targetList) <= 0) {
2011
+ return;
2012
+ }
2013
+
2014
+ targetList.splice(index, 1);
2015
+ };
2016
+
2017
+ return function () {
2018
+ var _slots$add;
2019
+
2020
+ return createVNode(FormItem, omit(props, "rowKey"), {
2021
+ "default": function _default() {
2022
+ return [map(get(formState, path), function (item, index) {
2023
+ var _slots$default2, _slots$itemAdd, _slots$itemMinus;
2024
+
2025
+ return createVNode(FormListProvider, {
2026
+ "key": item[props.rowKey] || index,
2027
+ "pathList": [].concat(_toConsumableArray(path), [index])
2028
+ }, {
2029
+ "default": function _default() {
2030
+ return [createVNode("div", {
2031
+ "class": "pro-form-list-item"
2032
+ }, [(_slots$default2 = slots["default"]) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots), !readonly.value && createVNode(Fragment, null, [createVNode("div", {
2033
+ "class": "pro-form-list-item-add",
2034
+ "onClick": handleAdd
2035
+ }, [(_slots$itemAdd = slots.itemAdd) === null || _slots$itemAdd === void 0 ? void 0 : _slots$itemAdd.call(slots)]), createVNode("div", {
2036
+ "class": "pro-form-list-item-minus",
2037
+ "onClick": function onClick() {
2038
+ return handleRemove(index);
2039
+ }
2040
+ }, [(_slots$itemMinus = slots.itemMinus) === null || _slots$itemMinus === void 0 ? void 0 : _slots$itemMinus.call(slots)])])])];
2041
+ }
2042
+ });
2043
+ }), !readonly.value && createVNode("div", {
2044
+ "class": "pro-form-list-add",
2045
+ "onClick": handleAdd
2046
+ }, [(_slots$add = slots.add) === null || _slots$add === void 0 ? void 0 : _slots$add.call(slots)])];
2047
+ }
2048
+ });
2049
+ };
2050
+ }
2051
+ });
2052
+ };
2053
+
2054
+ var ProFormKey = Symbol("pro-form");
2055
+ var useProForm = function useProForm() {
2056
+ return inject(ProFormKey);
2057
+ };
2058
+
2059
+ var provideProForm = function provideProForm(ctx) {
2060
+ provide(ProFormKey, ctx);
2061
+ };
2062
+
2063
+ var proFormProps = function proFormProps() {
2064
+ return {
2065
+ /**
2066
+ * 同 antd 或 element form中的model
2067
+ */
2068
+ model: {
2069
+ type: Object
2070
+ },
2071
+
2072
+ /**
2073
+ * 子组件是否只读样式
2074
+ */
2075
+ readonly: {
2076
+ type: Boolean,
2077
+ "default": undefined
2078
+ },
2079
+
2080
+ /**
2081
+ * FormComponent 根据此项来确定组件是否显示
2082
+ * rules 根据rules中方法生成showState对象
2083
+ */
2084
+ showState: {
2085
+ type: Object
2086
+ },
2087
+ showStateRules: {
2088
+ type: Object
2089
+ },
2090
+
2091
+ /**
2092
+ * 是否只读
2093
+ */
2094
+ readonlyState: {
2095
+ type: Object
2096
+ },
2097
+ readonlyStateRules: {
2098
+ type: Object
2099
+ },
2100
+
2101
+ /**
2102
+ * 是否disabled
2103
+ */
2104
+ disableState: {
2105
+ type: Object
2106
+ },
2107
+ disableStateRules: {
2108
+ type: Object
2109
+ },
2110
+
2111
+ /**
2112
+ *
2113
+ */
2114
+ columns: {
1334
2115
  type: Array
1335
2116
  },
1336
2117
  columnState: {
1337
2118
  type: Object
1338
2119
  },
1339
2120
 
1340
- /**
1341
- * 展示控件集合,readonly模式下使用这些组件渲染
2121
+ /**
2122
+ * 展示控件集合,readonly模式下使用这些组件渲染
1342
2123
  */
1343
2124
  elementMap: {
1344
2125
  type: Object
1345
2126
  },
1346
2127
 
1347
- /**
1348
- * 录入控件集合
2128
+ /**
2129
+ * 录入控件集合
1349
2130
  */
1350
2131
  formElementMap: {
1351
2132
  type: Object
1352
2133
  },
1353
2134
 
1354
- /**
1355
- * 是否启用rules验证
2135
+ /**
2136
+ * 是否启用rules验证
1356
2137
  */
1357
2138
  needRules: {
1358
2139
  type: Boolean,
1359
2140
  "default": true
1360
2141
  },
1361
2142
 
1362
- /**
1363
- * provide传递
2143
+ /**
2144
+ * provide传递
1364
2145
  */
1365
2146
  provideExtra: {
1366
2147
  type: Object
@@ -1368,65 +2149,122 @@ var proFormProps = function proFormProps() {
1368
2149
  };
1369
2150
  };
1370
2151
 
1371
- var ProForm = defineComponent({
1372
- props: _objectSpread2({}, proFormProps()),
1373
- setup: function setup(props, _ref) {
1374
- var slots = _ref.slots;
1375
- var formState = props.model || reactive({}); //组件状态相关
2152
+ var createForm = function createForm(Form, Grid) {
2153
+ return defineComponent({
2154
+ inheritAttrs: false,
2155
+ props: _objectSpread2(_objectSpread2(_objectSpread2({}, Form.props), proFormProps()), omit(Grid.props, "items")),
2156
+ setup: function setup(props, _ref) {
2157
+ var slots = _ref.slots,
2158
+ emit = _ref.emit,
2159
+ expose = _ref.expose,
2160
+ attrs = _ref.attrs;
2161
+ var formState = props.model || reactive({}); //组件状态相关
2162
+
2163
+ var showState = props.showState || reactive({});
2164
+ var readonlyState = props.readonlyState || reactive({});
2165
+ var disableState = props.disableState || reactive({}); //formState改变情况下,更新 showState,readonlyState,disableState状态
2166
+
2167
+ useEffect(function () {
2168
+ if (props.showStateRules) {
2169
+ forEach(props.showStateRules, function (fn, key) {
2170
+ showState[key] = fn(formState);
2171
+ });
2172
+ }
1376
2173
 
1377
- var showState = props.showState || reactive({});
1378
- var readonlyState = props.readonlyState || reactive({});
1379
- var disableState = props.disableState || reactive({}); //formState改变情况下,更新 showState,readonlyState,disableState状态
2174
+ if (props.readonlyStateRules) {
2175
+ forEach(props.readonlyStateRules, function (fn, key) {
2176
+ readonlyState[key] = fn(formState);
2177
+ });
2178
+ }
1380
2179
 
1381
- useEffect(function () {
1382
- if (props.showStateRules) {
1383
- forEach(props.showStateRules, function (fn, key) {
1384
- showState[key] = fn(formState);
1385
- });
1386
- }
2180
+ if (props.disableStateRules) {
2181
+ forEach(props.disableStateRules, function (fn, key) {
2182
+ disableState[key] = fn(formState);
2183
+ });
2184
+ }
2185
+ }, formState); //readonly
1387
2186
 
1388
- if (props.readonlyStateRules) {
1389
- forEach(props.readonlyStateRules, function (fn, key) {
1390
- readonlyState[key] = fn(formState);
1391
- });
1392
- }
2187
+ var readonly = computed(function () {
2188
+ return props.readonly;
2189
+ }); //columns合并
1393
2190
 
1394
- if (props.disableStateRules) {
1395
- forEach(props.disableStateRules, function (fn, key) {
1396
- disableState[key] = fn(formState);
2191
+ var columns = computed(function () {
2192
+ return mergeStateToList(props.columns, props.columnState, function (item) {
2193
+ return getColumnFormItemName(item);
1397
2194
  });
1398
- }
1399
- }, formState); //转换为ref对象
1400
-
1401
- var readonly = computed(function () {
1402
- return props.readonly;
1403
- });
1404
- var columns = computed(function () {
1405
- return mergeStateToList(props.columns, props.columnState, function (item) {
1406
- return getColumnFormItemName(item);
1407
2195
  });
1408
- });
1409
- provideProForm(_objectSpread2({
1410
- formState: formState,
1411
- showState: showState,
1412
- readonlyState: readonlyState,
1413
- disableState: disableState,
1414
- //
1415
- elementMap: props.elementMap,
1416
- formElementMap: props.formElementMap,
1417
- //
1418
- readonly: readonly,
1419
- //
1420
- columns: columns
1421
- }, props.provideExtra));
1422
- return function () {
1423
- var _slots$default;
1424
2196
 
1425
- // console.log("########", columns.value, props.columns, props.columnState);
1426
- return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
1427
- };
1428
- }
1429
- });
2197
+ var handleFinish = function handleFinish(values) {
2198
+ //删除不显示的值再触发事件
2199
+ var showValues = getValidValues(values, showState, props.showStateRules);
2200
+ emit("finish", showValues, values);
2201
+ };
2202
+
2203
+ var formRef = ref();
2204
+ expose({
2205
+ submit: function submit() {
2206
+ var _formRef$value;
2207
+
2208
+ (_formRef$value = formRef.value) === null || _formRef$value === void 0 ? void 0 : _formRef$value.submit();
2209
+ },
2210
+ resetFields: function resetFields() {
2211
+ var _formRef$value2;
2212
+
2213
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
2214
+ params[_key] = arguments[_key];
2215
+ }
2216
+
2217
+ (_formRef$value2 = formRef.value) === null || _formRef$value2 === void 0 ? void 0 : _formRef$value2.resetFields.apply(_formRef$value2, params);
2218
+ }
2219
+ });
2220
+ provideProForm(_objectSpread2({
2221
+ formState: formState,
2222
+ showState: showState,
2223
+ readonlyState: readonlyState,
2224
+ disableState: disableState,
2225
+ //
2226
+ elementMap: props.elementMap,
2227
+ formElementMap: props.formElementMap,
2228
+ //
2229
+ readonly: readonly,
2230
+ //
2231
+ columns: columns,
2232
+ //
2233
+ formRef: formRef
2234
+ }, props.provideExtra)); //为了不warning ...
2235
+
2236
+ provideProFormList({});
2237
+ var invalidKeys = keys(proFormProps());
2238
+ var gridKeys = keys(omit(Grid.props, "items"));
2239
+ return function () {
2240
+ var _slots$start, _slots$default;
2241
+
2242
+ return createVNode(Form, mergeProps({
2243
+ "ref": formRef
2244
+ }, omit(attrs, "onFinish"), omit.apply(void 0, [props].concat(_toConsumableArray(invalidKeys), _toConsumableArray(gridKeys), ["onFinish"])), {
2245
+ "model": formState,
2246
+ "onFinish": handleFinish
2247
+ }), _objectSpread2({
2248
+ "default": function _default() {
2249
+ return [(_slots$start = slots.start) === null || _slots$start === void 0 ? void 0 : _slots$start.call(slots), props.formElementMap && size(columns.value) > 0 && createVNode(Fragment, null, [props.row ? createVNode(Grid, {
2250
+ "row": props.row,
2251
+ "col": props.col,
2252
+ "items": map(columns.value, function (item) {
2253
+ return {
2254
+ rowKey: getColumnFormItemName(item),
2255
+ vNode: getFormItemEl(props.formElementMap, item, props.needRules),
2256
+ col: get(item, ["extra", "col"])
2257
+ };
2258
+ })
2259
+ }, null) : map(columns.value, function (item) {
2260
+ return getFormItemEl(props.formElementMap, item, props.needRules);
2261
+ })]), (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)];
2262
+ }
2263
+ }, omit(slots, "default")));
2264
+ };
2265
+ }
2266
+ });
2267
+ };
1430
2268
 
1431
2269
  var SearchMode;
1432
2270
 
@@ -1437,44 +2275,48 @@ var SearchMode;
1437
2275
 
1438
2276
  var proSearchFormProps = function proSearchFormProps() {
1439
2277
  return {
1440
- /**
1441
- * 需要监听的对象
2278
+ /**
2279
+ * 需要监听的对象
1442
2280
  */
1443
2281
  model: {
1444
- type: Object,
1445
- required: true
2282
+ type: Object
1446
2283
  },
1447
2284
 
1448
- /**
1449
- * 初始化触发 onFinish
2285
+ /**
2286
+ * 初始化触发 onFinish
1450
2287
  */
1451
2288
  initEmit: {
1452
2289
  type: Boolean,
1453
2290
  "default": true
1454
2291
  },
1455
2292
 
1456
- /**
1457
- * 模式 自动触发或者手动触发 onFinish
2293
+ /**
2294
+ * 模式 自动触发或者手动触发 onFinish
1458
2295
  */
1459
2296
  searchMode: {
1460
2297
  type: String,
1461
2298
  "default": SearchMode.AUTO
1462
2299
  },
1463
2300
 
1464
- /**
1465
- * 配置 同ProForm中的columns
1466
- * 可以根据column中valueType计算出默认的debounceKeys
2301
+ /**
2302
+ * 配置 同ProForm中的columns
2303
+ * 可以根据column中valueType计算出默认的debounceKeys
1467
2304
  */
1468
2305
  columns: {
1469
2306
  type: Array
1470
2307
  },
1471
2308
 
1472
- /**
1473
- * 需要debounce处理的字段
2309
+ /**
2310
+ * 需要debounce处理的字段
1474
2311
  */
1475
2312
  debounceKeys: {
1476
2313
  type: Array
1477
2314
  },
2315
+ //默认 valueType 为 text 的控件会debounce处理
2316
+ debounceTypes: {
2317
+ type: Array,
2318
+ "default": ["text"]
2319
+ },
1478
2320
  debounceTime: {
1479
2321
  type: Number,
1480
2322
  "default": 800
@@ -1482,180 +2324,79 @@ var proSearchFormProps = function proSearchFormProps() {
1482
2324
  };
1483
2325
  };
1484
2326
 
1485
- /**
1486
- * 该组件只是个模式,最终返回null,不做任何渲染,应配合着ProForm的包装类一起使用
1487
- * 针对传入的model(监听对象)做相应的finish(回调)处理
2327
+ /**
2328
+ * 该组件只是个模式,最终返回null,不做任何渲染,应配合着ProForm的包装类一起使用
2329
+ * 针对传入的model(监听对象)做相应的finish(回调)处理
1488
2330
  */
1489
- var ProSearchForm = defineComponent({
1490
- props: _objectSpread2({}, proSearchFormProps()),
1491
- setup: function setup(props, _ref) {
1492
- var emit = _ref.emit;
1493
- //根据column valueType 算出默认需要debounce处理的属性集合
1494
- var defaultDebounceKeys = map(filter$1(props.columns, function (column) {
1495
- var valueType = getColumnValueType(column); //默认input组件的触发事件需要debounce处理
1496
-
1497
- return valueType === "text";
1498
- }), function (column) {
1499
- return getColumnFormItemName(column);
1500
- });
1501
-
1502
- var handleFinish = function handleFinish() {
1503
- emit("finish");
1504
- };
1505
-
1506
- var debounceFinish = debounce(function () {
1507
- handleFinish();
1508
- }, props.debounceTime); //初始化
1509
-
1510
- useEffect(function () {
1511
- if (props.initEmit) {
1512
- handleFinish();
1513
- }
1514
- }, []);
1515
-
1516
- var isDebounceDataChange = function isDebounceDataChange(state, prevState, debounceKeys) {
1517
- return some(debounceKeys, function (key) {
1518
- return get(state, key) !== get(prevState, key);
2331
+ var createSearchForm = function createSearchForm(Form, Props) {
2332
+ return defineComponent({
2333
+ props: _objectSpread2(_objectSpread2(_objectSpread2({}, Form.props), Props), proSearchFormProps()),
2334
+ setup: function setup(props, _ref) {
2335
+ var slots = _ref.slots;
2336
+ var formState = props.model || reactive({});
2337
+ var valueTypeSet = new Set(props.debounceTypes); //根据column valueType 算出默认需要debounce处理的属性集合
2338
+
2339
+ var defaultDebounceKeys = map(filter$1(props.columns, function (column) {
2340
+ var valueType = getColumnValueType(column); //默认input组件的触发事件需要debounce处理
2341
+
2342
+ return valueTypeSet.has(valueType);
2343
+ }), function (column) {
2344
+ return getColumnFormItemName(column);
1519
2345
  });
1520
- }; //监听
1521
-
2346
+ var formRef = ref();
1522
2347
 
1523
- useWatch(function (state, prevState) {
1524
- if (props.searchMode !== SearchMode.AUTO) {
1525
- return;
1526
- } //如果改变的值中包括debounceKeys中注册的 延时触发
2348
+ var handleFinish = function handleFinish() {
2349
+ var _formRef$value;
1527
2350
 
2351
+ (_formRef$value = formRef.value) === null || _formRef$value === void 0 ? void 0 : _formRef$value.submit();
2352
+ };
1528
2353
 
1529
- var debounceKeys = size(props.debounceKeys) > 0 ? props.debounceKeys : defaultDebounceKeys;
2354
+ var debounceFinish = debounce(function () {
2355
+ handleFinish();
2356
+ }, props.debounceTime); //初始化
1530
2357
 
1531
- if (size(debounceKeys) > 0 && isDebounceDataChange(state, prevState, debounceKeys)) {
1532
- debounceFinish();
1533
- return;
1534
- }
2358
+ useEffect(function () {
2359
+ if (props.initEmit) {
2360
+ handleFinish();
2361
+ }
2362
+ }, []);
1535
2363
 
1536
- handleFinish();
1537
- }, function () {
1538
- return clone(props.model);
1539
- });
1540
- return function () {
1541
- return null;
1542
- };
1543
- }
1544
- });
2364
+ var isDebounceDataChange = function isDebounceDataChange(state, prevState, debounceKeys) {
2365
+ return some(debounceKeys, function (key) {
2366
+ return get(state, key) !== get(prevState, key);
2367
+ });
2368
+ }; //监听
1545
2369
 
1546
- /**
1547
- * ProFormList ctx
1548
- */
1549
2370
 
1550
- var ProFormListKey = Symbol("pro-form-list");
1551
- var useProFormList = function useProFormList() {
1552
- return inject(ProFormListKey);
1553
- };
2371
+ useWatch(function (state, prevState) {
2372
+ if (props.searchMode !== SearchMode.AUTO) {
2373
+ return;
2374
+ } //如果改变的值中包括debounceKeys中注册的 延时触发
1554
2375
 
1555
- var provideProFormList = function provideProFormList(ctx) {
1556
- provide(ProFormListKey, ctx);
1557
- };
1558
2376
 
1559
- var FormListProvider = defineComponent({
1560
- props: {
1561
- pathList: {
1562
- type: Array
1563
- }
1564
- },
1565
- setup: function setup(props, _ref) {
1566
- var slots = _ref.slots;
1567
- provideProFormList({
1568
- pathList: props.pathList
1569
- });
1570
- return function () {
1571
- var _slots$default;
2377
+ var debounceKeys = size(props.debounceKeys) > 0 ? props.debounceKeys : defaultDebounceKeys;
1572
2378
 
1573
- return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
1574
- };
1575
- }
1576
- });
2379
+ if (size(debounceKeys) > 0 && isDebounceDataChange(state, prevState, debounceKeys)) {
2380
+ debounceFinish();
2381
+ return;
2382
+ }
1577
2383
 
1578
- var proFormListProps = function proFormListProps() {
1579
- return {
1580
- //每行默认id
1581
- rowKey: {
1582
- type: String,
1583
- "default": "id"
1584
- },
1585
- //name
1586
- name: {
1587
- type: [String, Number, Array],
1588
- required: true
2384
+ handleFinish();
2385
+ }, function () {
2386
+ return clone(formState);
2387
+ });
2388
+ var invalidKeys = keys(omit(proSearchFormProps(), "columns"));
2389
+ return function () {
2390
+ return createVNode(Form, mergeProps({
2391
+ "ref": formRef
2392
+ }, omit(props, invalidKeys), {
2393
+ "model": formState
2394
+ }), slots);
2395
+ };
1589
2396
  }
1590
- };
2397
+ });
1591
2398
  };
1592
2399
 
1593
- var ProFormList = defineComponent({
1594
- props: _objectSpread2({}, proFormListProps()),
1595
- setup: function setup(props, _ref2) {
1596
- var slots = _ref2.slots;
1597
-
1598
- var _useProForm = useProForm(),
1599
- formState = _useProForm.formState,
1600
- readonly = _useProForm.readonly;
1601
-
1602
- var formListCtx = useProFormList();
1603
- var nameList = convertPathToList(props.name);
1604
- var path = formListCtx !== null && formListCtx !== void 0 && formListCtx.pathList ? [].concat(_toConsumableArray(formListCtx.pathList), _toConsumableArray(nameList)) : nameList;
1605
-
1606
- var handleAdd = function handleAdd() {
1607
- var targetList = get(formState, path);
1608
-
1609
- if (!isArray(targetList)) {
1610
- targetList = [];
1611
- }
1612
-
1613
- targetList.push(_defineProperty({}, props.rowKey, new Date().valueOf()));
1614
- set(formState, path, targetList);
1615
- };
1616
-
1617
- var handleRemove = function handleRemove(index) {
1618
- var targetList = get(formState, path);
1619
-
1620
- if (size(targetList) <= 0) {
1621
- return;
1622
- }
1623
-
1624
- targetList.splice(index, 1);
1625
- };
1626
-
1627
- return function () {
1628
- var _slots$add;
1629
-
1630
- return createVNode(Fragment, null, [map(get(formState, path), function (item, index) {
1631
- var _slots$default2, _slots$itemAdd, _slots$itemMinus;
1632
-
1633
- return createVNode(FormListProvider, {
1634
- "key": index,
1635
- "pathList": [].concat(_toConsumableArray(path), [index])
1636
- }, {
1637
- "default": function _default() {
1638
- return [createVNode("div", {
1639
- "class": "pro-form-list-item"
1640
- }, [(_slots$default2 = slots["default"]) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots), !readonly.value && createVNode(Fragment, null, [createVNode("div", {
1641
- "class": "pro-form-list-item-add",
1642
- "onClick": handleAdd
1643
- }, [(_slots$itemAdd = slots.itemAdd) === null || _slots$itemAdd === void 0 ? void 0 : _slots$itemAdd.call(slots)]), createVNode("div", {
1644
- "class": "pro-form-list-item-minus",
1645
- "onClick": function onClick() {
1646
- return handleRemove(index);
1647
- }
1648
- }, [(_slots$itemMinus = slots.itemMinus) === null || _slots$itemMinus === void 0 ? void 0 : _slots$itemMinus.call(slots)])])])];
1649
- }
1650
- });
1651
- }), !readonly.value && createVNode("div", {
1652
- "class": "pro-form-list-add",
1653
- "onClick": handleAdd
1654
- }, [(_slots$add = slots.add) === null || _slots$add === void 0 ? void 0 : _slots$add.call(slots)])]);
1655
- };
1656
- }
1657
- });
1658
-
1659
2400
  var proFormItemProps = function proFormItemProps() {
1660
2401
  return {
1661
2402
  readonly: {
@@ -1759,8 +2500,8 @@ var proTableProps = function proTableProps() {
1759
2500
  type: String
1760
2501
  },
1761
2502
 
1762
- /**
1763
- * 公共column,会merge到columns item中
2503
+ /**
2504
+ * 公共column,会merge到columns item中
1764
2505
  */
1765
2506
  column: {
1766
2507
  type: Object
@@ -1773,36 +2514,29 @@ var proTableProps = function proTableProps() {
1773
2514
  type: Object
1774
2515
  },
1775
2516
 
1776
- /**
1777
- * 展示控件集合,readonly模式下使用这些组件渲染
2517
+ /**
2518
+ * 展示控件集合,readonly模式下使用这些组件渲染
1778
2519
  */
1779
2520
  elementMap: {
1780
2521
  type: Object
1781
2522
  },
1782
2523
 
1783
- /**
1784
- * loading
1785
- */
1786
- loading: {
1787
- type: Boolean
1788
- },
1789
-
1790
- /**
1791
- * 序号
2524
+ /**
2525
+ * 序号
1792
2526
  */
1793
2527
  serialNumber: {
1794
2528
  type: Boolean
1795
2529
  },
1796
2530
 
1797
- /**
1798
- * 分页
2531
+ /**
2532
+ * 分页
1799
2533
  */
1800
- pagination: {
2534
+ paginationState: {
1801
2535
  type: Object
1802
2536
  },
1803
2537
 
1804
- /**
1805
- * provide传递
2538
+ /**
2539
+ * provide传递
1806
2540
  */
1807
2541
  provideExtra: {
1808
2542
  type: Object
@@ -1810,62 +2544,35 @@ var proTableProps = function proTableProps() {
1810
2544
  };
1811
2545
  };
1812
2546
 
1813
- var ProTable = defineComponent({
1814
- props: _objectSpread2({}, proTableProps()),
1815
- setup: function setup(props, _ref) {
1816
- var slots = _ref.slots;
1817
- var columns = computed(function () {
1818
- var mergeColumns = mergeStateToList(props.columns, props.columnState, function (item) {
1819
- return item.dataIndex;
1820
- }); //根据valueType选择对应的展示组件
1821
-
1822
- var columns = map(mergeColumns, function (item) {
1823
- //merge公共item
1824
- var nextItem = _objectSpread2(_objectSpread2({}, props.column), item);
1825
-
1826
- if (!item.customRender) {
1827
- nextItem.customRender = function (_ref2) {
1828
- var text = _ref2.text;
1829
- var vn = getItemEl(props.elementMap, _objectSpread2(_objectSpread2({}, item), {}, {
1830
- showProps: _objectSpread2(_objectSpread2({}, item.showProps), {}, {
1831
- content: props.columnEmptyText
1832
- })
1833
- }), text); //如果找不到注册的组件,使用当前值 及 columnEmptyText
1834
-
1835
- return vn || text || props.columnEmptyText;
1836
- };
1837
- }
2547
+ var createTable = function createTable(Table, Props) {
2548
+ return defineComponent({
2549
+ props: _objectSpread2(_objectSpread2(_objectSpread2({}, Table.props), Props), proTableProps()),
2550
+ setup: function setup(props, _ref) {
2551
+ var slots = _ref.slots;
1838
2552
 
1839
- return nextItem;
1840
- }); //处理序号
1841
-
1842
- if (props.serialNumber) {
1843
- columns.unshift(_objectSpread2(_objectSpread2({
2553
+ var createNumberColumn = function createNumberColumn() {
2554
+ return _objectSpread2(_objectSpread2({
1844
2555
  title: "序号",
1845
2556
  dataIndex: "serialNumber",
1846
2557
  width: 80
1847
2558
  }, props.column), {}, {
1848
- // @ts-ignore
1849
- customRender: function customRender(_ref3) {
1850
- var _props$pagination, _props$pagination2;
2559
+ customRender: function customRender(_ref2) {
2560
+ var _props$paginationStat, _props$paginationStat2;
1851
2561
 
1852
- var index = _ref3.index;
2562
+ var index = _ref2.index;
1853
2563
 
1854
- if ((_props$pagination = props.pagination) !== null && _props$pagination !== void 0 && _props$pagination.page && (_props$pagination2 = props.pagination) !== null && _props$pagination2 !== void 0 && _props$pagination2.pageSize) {
1855
- return props.pagination.pageSize * (props.pagination.page - 1) + index + 1;
2564
+ if ((_props$paginationStat = props.paginationState) !== null && _props$paginationStat !== void 0 && _props$paginationStat.page && (_props$paginationStat2 = props.paginationState) !== null && _props$paginationStat2 !== void 0 && _props$paginationStat2.pageSize) {
2565
+ return props.paginationState.pageSize * (props.paginationState.page - 1) + index + 1;
1856
2566
  }
1857
2567
 
1858
2568
  return index + 1;
1859
2569
  }
1860
- }));
1861
- }
2570
+ });
2571
+ };
1862
2572
 
1863
- var operate = props.operate; //处理operate
2573
+ var createOperateColumn = function createOperateColumn() {
2574
+ var operate = props.operate; //将itemState补充的信息拼到item中
1864
2575
 
1865
- if (operate && operate.items && some(operate.items, function (item) {
1866
- return item.show;
1867
- })) {
1868
- //将itemState补充的信息拼到item中
1869
2576
  var items = map(operate.items, function (i) {
1870
2577
  return _objectSpread2(_objectSpread2({}, i), get(operate.itemState, i.value));
1871
2578
  }); //排序
@@ -1873,14 +2580,14 @@ var ProTable = defineComponent({
1873
2580
  var sortedItems = sortBy(items, function (item) {
1874
2581
  return item.sort;
1875
2582
  });
1876
- columns.push(_objectSpread2(_objectSpread2({
2583
+ return _objectSpread2(_objectSpread2(_objectSpread2({}, props.column), {}, {
1877
2584
  title: "操作",
1878
2585
  dataIndex: "operate",
1879
2586
  fixed: "right"
1880
- }, props.column), {}, {
1881
- customRender: function customRender(_ref4) {
1882
- var record = _ref4.record;
1883
- var validItems = filter$1(sortedItems, function (item) {
2587
+ }, operate.column), {}, {
2588
+ customRender: function customRender(_ref3) {
2589
+ var record = _ref3.record;
2590
+ var showItems = filter$1(sortedItems, function (item) {
1884
2591
  if (item.show && isFunction(item.show)) {
1885
2592
  return item.show(record);
1886
2593
  }
@@ -1893,7 +2600,7 @@ var ProTable = defineComponent({
1893
2600
  });
1894
2601
  return createVNode("div", {
1895
2602
  "class": "pro-table-operate"
1896
- }, [map(validItems, function (item) {
2603
+ }, [map(showItems, function (item) {
1897
2604
  //自定义
1898
2605
  if (isFunction(item.element)) {
1899
2606
  return item.element(record, item);
@@ -1910,20 +2617,62 @@ var ProTable = defineComponent({
1910
2617
  }, [item.label]);
1911
2618
  })]);
1912
2619
  }
1913
- }, operate.column));
1914
- }
2620
+ });
2621
+ };
1915
2622
 
1916
- return columns;
1917
- });
1918
- provideProTable(_objectSpread2({
1919
- columns: columns
1920
- }, props.provideExtra));
1921
- return function () {
1922
- var _slots$default;
2623
+ var columns = computed(function () {
2624
+ var mergeColumns = mergeStateToList(props.columns, props.columnState, function (item) {
2625
+ return item.dataIndex;
2626
+ }); //根据valueType选择对应的展示组件
2627
+
2628
+ var columns = map(mergeColumns, function (item) {
2629
+ //merge公共item
2630
+ var nextItem = _objectSpread2(_objectSpread2({}, props.column), item);
2631
+
2632
+ if (!item.customRender) {
2633
+ nextItem.customRender = function (_ref4) {
2634
+ var text = _ref4.text;
2635
+ var vn = getItemEl(props.elementMap, _objectSpread2(_objectSpread2({}, item), {}, {
2636
+ showProps: _objectSpread2(_objectSpread2({}, item.showProps), {}, {
2637
+ content: props.columnEmptyText
2638
+ })
2639
+ }), text); //如果找不到注册的组件,使用当前值 及 columnEmptyText
2640
+
2641
+ return vn || text || props.columnEmptyText;
2642
+ };
2643
+ }
1923
2644
 
1924
- return (_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
1925
- };
1926
- }
1927
- });
2645
+ return nextItem;
2646
+ }); //处理序号
2647
+
2648
+ if (props.serialNumber) {
2649
+ columns.unshift(createNumberColumn());
2650
+ } //处理operate
2651
+
2652
+
2653
+ if (props.operate && props.operate.items && some(props.operate.items, function (item) {
2654
+ return item.show;
2655
+ })) {
2656
+ columns.push(createOperateColumn());
2657
+ }
2658
+
2659
+ return columns;
2660
+ });
2661
+ var tableRef = ref();
2662
+ provideProTable(_objectSpread2({
2663
+ columns: columns,
2664
+ tableRef: tableRef
2665
+ }, props.provideExtra));
2666
+ var invalidKeys = keys(proTableProps());
2667
+ return function () {
2668
+ return createVNode(Table, mergeProps({
2669
+ "ref": tableRef
2670
+ }, omit(props, invalidKeys), {
2671
+ "columns": columns.value
2672
+ }), slots);
2673
+ };
2674
+ }
2675
+ });
2676
+ };
1928
2677
 
1929
- export { CurdAction, CurdAddAction, CurdCurrentMode, CurdSubAction, ProCurd, ProForm, ProFormList, ProModalCurd, ProModule, ProPageCurd, ProSearchForm, ProTable, RequestAction, SearchMode, convertPathToList, createFormItemCompFn, defaultPage, generateId, getColumnFormItemName, getColumnValueType, getFormItemEl, getItemEl, getValidValues, mergeStateToList, provideProCurd, provideProModule, useComposeRequestActor, useDoneRequestActor, useFailedRequestActor, useModuleEvent, useProCurd, useProForm, useProFormList, useProModule, useProTable };
2678
+ 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, provideProFormList, provideProModule, renderElement, renderElements, useComposeRequestActor, useDoneRequestActor, useFailedRequestActor, useModuleEvent, useProCurd, useProForm, useProFormList, useProModule, useProTable };