@zat-design/sisyphus-react 3.13.4-beta.5 → 3.13.5-beta.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.
@@ -72,17 +72,13 @@ var DndWrapper = function DndWrapper(_ref2) {
72
72
  value = _ref2.value,
73
73
  onChange = _ref2.onChange,
74
74
  onDrag = _ref2.onDrag,
75
+ onDragEnd = _ref2.onDragEnd,
75
76
  disabled = _ref2.disabled,
76
77
  children = _ref2.children;
77
- var onDragEnd = function onDragEnd(event) {
78
+ var onDragEndtInside = function onDragEndtInside(event) {
78
79
  var active = event.active,
79
80
  over = event.over;
80
81
  if (active.id !== (over === null || over === void 0 ? void 0 : over.id)) {
81
- if (onDrag) {
82
- var nextList = onDrag(event, value);
83
- onChange(nextList);
84
- return;
85
- }
86
82
  var activeIndex = value.findIndex(function (i) {
87
83
  return i.rowKey === active.id;
88
84
  });
@@ -90,11 +86,16 @@ var DndWrapper = function DndWrapper(_ref2) {
90
86
  return i.rowKey === (over === null || over === void 0 ? void 0 : over.id);
91
87
  });
92
88
  var nextValue = arrayMove(value, activeIndex, overIndex);
89
+ if (onDrag || onDragEnd) {
90
+ var nextList = onDragEnd ? onDragEnd(event, value, nextValue) : onDrag(event, value, nextValue);
91
+ onChange(nextList);
92
+ return;
93
+ }
93
94
  onChange(nextValue);
94
95
  }
95
96
  };
96
97
  return draggable && !disabled ? _jsx(DndContext, {
97
- onDragEnd: onDragEnd,
98
+ onDragEnd: onDragEndtInside,
98
99
  children: _jsx(SortableContext, {
99
100
  items: (value === null || value === void 0 ? void 0 : (_value$ = value[0]) === null || _value$ === void 0 ? void 0 : _value$.rowKey) ? value.map(function (i) {
100
101
  return i.rowKey;
@@ -130,11 +131,13 @@ var DraggableTable = function DraggableTable(_ref3) {
130
131
  handlePageChange = tableProps.handlePageChange;
131
132
  var onChange = draggableProps.onChange,
132
133
  onDrag = draggableProps.onDrag,
133
- draggable = draggableProps.draggable;
134
+ draggable = draggableProps.draggable,
135
+ onDragEnd = draggableProps.onDragEnd;
134
136
  return _jsxs(DndWrapper, {
135
137
  value: value,
136
138
  onChange: onChange,
137
139
  onDrag: onDrag,
140
+ onDragEnd: onDragEnd,
138
141
  disabled: disabled,
139
142
  draggable: draggable,
140
143
  children: [headerRender ? _jsx("div", {
@@ -11,7 +11,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
11
11
  import "antd/es/form/style";
12
12
  import _Form from "antd/es/form";
13
13
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
14
- var _excluded = ["value", "onChange", "onDrag", "className", "columns", "type", "mode", "stripe", "draggable", "virtual", "disabled", "insertType", "emptyBtnText", "actionWidth", "actionProps", "toolbarProps", "toolbarSticky", "rowSelection", "onlyOneLineMsg", "deletePoConfirmMsg", "mulDeletePoConfirmMsg", "requiredAlign", "summary", "max", "headerRender", "pagination", "rowKey", "rowDisabled", "rowDraggable", "footerRender", "scroll", "actionDirection", "diffConfig"];
14
+ var _excluded = ["value", "onChange", "onDrag", "onDragEnd", "className", "columns", "type", "mode", "stripe", "draggable", "virtual", "disabled", "insertType", "emptyBtnText", "actionWidth", "actionProps", "toolbarProps", "toolbarSticky", "rowSelection", "onlyOneLineMsg", "deletePoConfirmMsg", "mulDeletePoConfirmMsg", "requiredAlign", "summary", "max", "headerRender", "pagination", "rowKey", "rowDisabled", "rowDraggable", "footerRender", "scroll", "actionDirection", "diffConfig"];
15
15
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
16
16
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
17
17
  import { get, isArray, isBoolean, set } from 'lodash';
@@ -29,6 +29,7 @@ var ProEditTable = function ProEditTable(_ref, ref) {
29
29
  var value = _ref.value,
30
30
  onChange = _ref.onChange,
31
31
  onDrag = _ref.onDrag,
32
+ onDragEnd = _ref.onDragEnd,
32
33
  className = _ref.className,
33
34
  columns = _ref.columns,
34
35
  type = _ref.type,
@@ -405,6 +406,7 @@ var ProEditTable = function ProEditTable(_ref, ref) {
405
406
  draggableProps: {
406
407
  onChange: onChange,
407
408
  onDrag: onDrag,
409
+ onDragEnd: onDragEnd,
408
410
  draggable: draggable
409
411
  },
410
412
  tableProps: {
@@ -377,8 +377,18 @@ export interface ProEditTableProps<T = any> extends Omit<TableProps<T>, 'onChang
377
377
  rowDraggable?: (record?: T) => string | boolean;
378
378
  /**
379
379
  * 拖拽事件处理
380
+ * @param event 拖拽事件
381
+ * @param dataSource 当前数据源
382
+ * @param nextDataSource 拖拽后的数据源
380
383
  */
381
- onDrag?: (event: DragEndEvent, dataSource: T[]) => T[];
384
+ onDrag?: (event: DragEndEvent, dataSource: T[], nextDataSource: T[]) => T[];
385
+ /**
386
+ * 拖拽结束事件处理
387
+ * @param event 拖拽事件
388
+ * @param dataSource 当前数据源
389
+ * @param nextDataSource 拖拽后的数据源
390
+ */
391
+ onDragEnd?: (event: DragEndEvent, dataSource: T[], nextDataSource: T[]) => T[];
382
392
  /**
383
393
  * 引用对象
384
394
  */
@@ -1,16 +1,8 @@
1
+ var _ref;
1
2
  /* eslint-disable no-redeclare */
2
3
  import { useProConfig } from '../../ProConfigProvider';
3
4
  import { getEnumData } from '../utils';
4
- var baseEnumStorage = null;
5
- try {
6
- var storedData = window.localStorage.getItem('zat-design-pro-component-cacheKey');
7
- if (storedData) {
8
- baseEnumStorage = JSON.parse(storedData);
9
- }
10
- } catch (error) {
11
- console.error('解析枚举缓存数据失败', error);
12
- baseEnumStorage = null;
13
- }
5
+ var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-component-cacheKey') && JSON.parse(window.localStorage.getItem('zat-design-pro-component-cacheKey'))) !== null && _ref !== void 0 ? _ref : null;
14
6
  /**
15
7
  * 根据 code 从枚举缓存取出对应的 options 、以及回显
16
8
  * @param codes
@@ -19,16 +11,16 @@ try {
19
11
  * @returns
20
12
  */
21
13
  function useEnum(codes, value, compose) {
22
- var _ref = useProConfig('globalConfig') || {},
23
- _ref$storage = _ref.storage,
24
- storage = _ref$storage === void 0 ? 'localStorage' : _ref$storage;
25
- var _ref2 = useProConfig('ProEnum') || {},
26
- _ref2$cacheKey = _ref2.cacheKey,
27
- cacheKey = _ref2$cacheKey === void 0 ? 'zat-design-pro-component-cacheKey' : _ref2$cacheKey,
28
- _ref2$fieldNames = _ref2.fieldNames,
29
- fieldNames = _ref2$fieldNames === void 0 ? {} : _ref2$fieldNames,
30
- _ref2$clear = _ref2.clear,
31
- clear = _ref2$clear === void 0 ? true : _ref2$clear;
14
+ var _ref2 = useProConfig('globalConfig') || {},
15
+ _ref2$storage = _ref2.storage,
16
+ storage = _ref2$storage === void 0 ? 'localStorage' : _ref2$storage;
17
+ var _ref3 = useProConfig('ProEnum') || {},
18
+ _ref3$cacheKey = _ref3.cacheKey,
19
+ cacheKey = _ref3$cacheKey === void 0 ? 'zat-design-pro-component-cacheKey' : _ref3$cacheKey,
20
+ _ref3$fieldNames = _ref3.fieldNames,
21
+ fieldNames = _ref3$fieldNames === void 0 ? {} : _ref3$fieldNames,
22
+ _ref3$clear = _ref3.clear,
23
+ clear = _ref3$clear === void 0 ? true : _ref3$clear;
32
24
  var catchData = getEnumData(storage, cacheKey, baseEnumStorage);
33
25
  // 默认枚举缓存数据
34
26
  baseEnumStorage = catchData;
@@ -11,10 +11,35 @@ interface EnumRes {
11
11
  * @param baseEnumStorage
12
12
  * @returns
13
13
  */
14
- export declare function getEnumData(storage: StorageType, cacheKey: string, baseEnumStorage?: any, dataSource?: any[]): EnumRes;
14
+ export declare function getEnumData(storage: StorageType, cacheKey: string, baseEnumStorage?: any): EnumRes;
15
+ /**
16
+ * 设置枚举数据
17
+ * @param storage
18
+ * @param cacheKey
19
+ * @param data
20
+ */
15
21
  export declare function setEnumData(storage: StorageType, cacheKey: string, data: any): boolean;
22
+ /**
23
+ * 判断枚举列表是否存在
24
+ * @param storage
25
+ * @param cacheKey
26
+ * @param code
27
+ * @returns
28
+ */
16
29
  export declare function hasEnumList(storage: StorageType, cacheKey: any, code: string): import("../propsType").DataOptionType[];
30
+ /**
31
+ * 判断是否是对象
32
+ * @param obj
33
+ * @returns
34
+ */
17
35
  export declare function isObject(obj: any): boolean;
36
+ /**
37
+ * 合并枚举数据
38
+ * @param storage
39
+ * @param code
40
+ * @param cacheKey
41
+ * @param responseData
42
+ */
18
43
  export declare function mergeCacheData(storage: string, code: string, cacheKey: string, responseData: any): void;
19
44
  /**
20
45
  * diff code 差异
@@ -8,8 +8,8 @@ import { isNull, isUndefined } from 'lodash';
8
8
  * @param baseEnumStorage
9
9
  * @returns
10
10
  */
11
- export function getEnumData(storage, cacheKey, baseEnumStorage, dataSource) {
12
- if (baseEnumStorage && cacheKey === 'zat-design-pro-component-cacheKey') {
11
+ export function getEnumData(storage, cacheKey, baseEnumStorage) {
12
+ if (baseEnumStorage) {
13
13
  return baseEnumStorage;
14
14
  }
15
15
  if (storage === 'localStorage') {
@@ -19,6 +19,12 @@ export function getEnumData(storage, cacheKey, baseEnumStorage, dataSource) {
19
19
  return JSON.parse(window.sessionStorage.getItem(cacheKey) || '{}');
20
20
  }
21
21
  }
22
+ /**
23
+ * 设置枚举数据
24
+ * @param storage
25
+ * @param cacheKey
26
+ * @param data
27
+ */
22
28
  export function setEnumData(storage, cacheKey, data) {
23
29
  var _Object$keys;
24
30
  if (!((_Object$keys = Object.keys(data === null || data === void 0 ? void 0 : data.data)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.length)) {
@@ -30,14 +36,33 @@ export function setEnumData(storage, cacheKey, data) {
30
36
  window.sessionStorage.setItem(cacheKey, JSON.stringify(data));
31
37
  }
32
38
  }
39
+ /**
40
+ * 判断枚举列表是否存在
41
+ * @param storage
42
+ * @param cacheKey
43
+ * @param code
44
+ * @returns
45
+ */
33
46
  export function hasEnumList(storage, cacheKey, code) {
34
47
  var res = getEnumData(storage, cacheKey);
35
48
  var enumList = (res === null || res === void 0 ? void 0 : res.data) || {};
36
49
  return enumList === null || enumList === void 0 ? void 0 : enumList[code];
37
50
  }
51
+ /**
52
+ * 判断是否是对象
53
+ * @param obj
54
+ * @returns
55
+ */
38
56
  export function isObject(obj) {
39
57
  return Object.prototype.toString.call(obj) === '[object Object]';
40
58
  }
59
+ /**
60
+ * 合并枚举数据
61
+ * @param storage
62
+ * @param code
63
+ * @param cacheKey
64
+ * @param responseData
65
+ */
41
66
  export function mergeCacheData(storage, code, cacheKey, responseData) {
42
67
  var _window, _window2;
43
68
  var cacheStorage = storage === 'localStorage' ? 'localStorage' : 'sessionStorage';
@@ -0,0 +1,20 @@
1
+ import { InternalNamePath, NamePath } from 'antd/lib/form/interface';
2
+ import { FormInstance } from 'antd';
3
+ import type { GroupColumnType, GroupType } from '../propsType';
4
+ export type EventArgs = any[];
5
+ interface ColumnsTransformerParams {
6
+ columns: GroupColumnType[];
7
+ name?: NamePath;
8
+ names?: NamePath[];
9
+ value?: any[];
10
+ onChange: any;
11
+ namePath?: InternalNamePath;
12
+ form: FormInstance;
13
+ index?: number;
14
+ formDisabled?: boolean;
15
+ desensitizationKey?: string;
16
+ groupProps: GroupType;
17
+ }
18
+ /** 转换columns */
19
+ export declare const useTransformColumns: (params: ColumnsTransformerParams) => any[];
20
+ export {};
@@ -0,0 +1,161 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ /* eslint-disable no-lonely-if */
4
+ import { useRef } from 'react';
5
+ import { cloneDeep, isEqual } from 'lodash';
6
+ import { useDeepCompareMemo } from '../../../../utils/useDeepCompareMemo';
7
+ import { difference } from '../../../../../ProEditTable/utils/tools';
8
+ import { getReactiveProps, getValueTypeTrans, valueFromEventWrapper } from '../utils';
9
+ /** 转换columns */
10
+ export var useTransformColumns = function useTransformColumns(params) {
11
+ var form = params.form,
12
+ columns = params.columns,
13
+ name = params.name,
14
+ names = params.names,
15
+ outerIndex = params.index,
16
+ namePath = params.namePath,
17
+ value = params.value,
18
+ internalChange = params.onChange,
19
+ groupProps = params.groupProps,
20
+ formDisabled = params.formDisabled,
21
+ desensitizationKey = params.desensitizationKey;
22
+ var timerRef = useRef([]);
23
+ return columns === null || columns === void 0 ? void 0 : columns.flatMap(function (column, index) {
24
+ var type = column.type,
25
+ valueType = column.valueType,
26
+ switchValue = column.switchValue,
27
+ toISOString = column.toISOString,
28
+ toCSTString = column.toCSTString,
29
+ fieldProps = column.fieldProps,
30
+ normalize = column.normalize,
31
+ disabled = column.disabled,
32
+ show = column.show,
33
+ component = column.component,
34
+ clearNotShow = column.clearNotShow,
35
+ desensitization = column.desensitization;
36
+ var _ref = fieldProps || {},
37
+ mode = _ref.mode,
38
+ onChange = _ref.onChange,
39
+ onFieldChange = _ref.onFieldChange,
40
+ comDisabled = _ref.disabled,
41
+ onBlur = _ref.onBlur;
42
+ var _disabled = disabled || comDisabled;
43
+ var columnName = names ? names[index] : [].concat(name, index);
44
+ // 响应式字段改变后的回调
45
+ var changedCallback = function changedCallback(lastDependency, current) {
46
+ // 清值防抖 多次刷新时以最后一次为准
47
+ if (clearNotShow !== false && names) {
48
+ if ((current === null || current === void 0 ? void 0 : current.show) === false) {
49
+ clearInterval(timerRef.current[index]);
50
+ timerRef.current[index] = setTimeout(function () {
51
+ if (names) {
52
+ form.resetFields([columnName]);
53
+ }
54
+ if (!names && (value === null || value === void 0 ? void 0 : value.length)) {
55
+ value[index] = null;
56
+ form.setFieldValue(columnName, _toConsumableArray(value));
57
+ }
58
+ }, 200);
59
+ } else {
60
+ clearInterval(timerRef.current[index]);
61
+ }
62
+ }
63
+ };
64
+ // 响应式字段
65
+ // eslint-disable-next-line react-hooks/rules-of-hooks
66
+ var reactiveProps = useDeepCompareMemo(function () {
67
+ return getReactiveProps({
68
+ form: form,
69
+ index: index,
70
+ type: type,
71
+ namePath: namePath,
72
+ disabled: _disabled,
73
+ show: show,
74
+ component: component,
75
+ fieldProps: fieldProps,
76
+ name: columnName,
77
+ desensitization: desensitization
78
+ });
79
+ }, changedCallback, [value, show, fieldProps, _disabled, columnName, type]);
80
+ if (reactiveProps.show === false) {
81
+ return [];
82
+ }
83
+ var transform = getValueTypeTrans({
84
+ type: type,
85
+ valueType: valueType,
86
+ switchValue: switchValue,
87
+ toISOString: toISOString,
88
+ toCSTString: toCSTString,
89
+ mode: mode
90
+ });
91
+ var newValue;
92
+ var handleChange = function handleChange() {
93
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
94
+ args[_key] = arguments[_key];
95
+ }
96
+ newValue = valueFromEventWrapper(column, args);
97
+ if (transform === null || transform === void 0 ? void 0 : transform.normalize) {
98
+ var _transform$normalize;
99
+ newValue = transform === null || transform === void 0 ? void 0 : (_transform$normalize = transform.normalize) === null || _transform$normalize === void 0 ? void 0 : _transform$normalize.call(transform, newValue);
100
+ } else if (normalize) {
101
+ // @ts-ignore
102
+ newValue = normalize === null || normalize === void 0 ? void 0 : normalize(newValue);
103
+ }
104
+ internalChange === null || internalChange === void 0 ? void 0 : internalChange(newValue, args[1], index);
105
+ var values = form.getFieldValue(namePath);
106
+ var originRow = (namePath === null || namePath === void 0 ? void 0 : namePath.length) ? cloneDeep(values) : undefined;
107
+ onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, args);
108
+ onFieldChange === null || onFieldChange === void 0 ? void 0 : onFieldChange(newValue, values, {
109
+ index: outerIndex,
110
+ namePath: namePath,
111
+ form: form,
112
+ option: args === null || args === void 0 ? void 0 : args[1]
113
+ });
114
+ // 如果是在可编辑表格或formList内部, 储存当前行的值, 并在变更后更新到表单里
115
+ if ((namePath === null || namePath === void 0 ? void 0 : namePath.length) && !isEqual(originRow, values)) {
116
+ var _Object$keys, _Object$keys$map;
117
+ form.setFieldValue(namePath, values);
118
+ var diff = difference(originRow, values) || {};
119
+ var validateFieldKeys = (_Object$keys = Object.keys(diff)) === null || _Object$keys === void 0 ? void 0 : (_Object$keys$map = _Object$keys.map) === null || _Object$keys$map === void 0 ? void 0 : _Object$keys$map.call(_Object$keys, function (key) {
120
+ return [].concat(_toConsumableArray(namePath), [key]);
121
+ });
122
+ if (validateFieldKeys === null || validateFieldKeys === void 0 ? void 0 : validateFieldKeys.length) {
123
+ setTimeout(function () {
124
+ form.validateFields([name].concat(_toConsumableArray(validateFieldKeys)));
125
+ }, 100);
126
+ }
127
+ }
128
+ };
129
+ var handleBlur = function handleBlur() {
130
+ if (!onBlur) return;
131
+ var values = form.getFieldValue(namePath);
132
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
133
+ args[_key2] = arguments[_key2];
134
+ }
135
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(args[0], values, {
136
+ index: outerIndex,
137
+ namePath: namePath,
138
+ form: form,
139
+ option: args === null || args === void 0 ? void 0 : args[1]
140
+ });
141
+ };
142
+ // 内外一个为true则为true
143
+ var getLastDisabled = function getLastDisabled() {
144
+ if (Array.isArray(groupProps.disabled)) {
145
+ return reactiveProps.disabled || groupProps.disabled[index];
146
+ }
147
+ return reactiveProps.disabled || groupProps.disabled;
148
+ };
149
+ return _objectSpread(_objectSpread(_objectSpread({}, column), {}, {
150
+ name: columnName
151
+ }, reactiveProps), {}, {
152
+ disabled: getLastDisabled(),
153
+ getValueProps: transform === null || transform === void 0 ? void 0 : transform.getValueProps,
154
+ fieldProps: _objectSpread(_objectSpread(_objectSpread({}, column === null || column === void 0 ? void 0 : column.fieldProps), reactiveProps === null || reactiveProps === void 0 ? void 0 : reactiveProps.fieldProps), {}, {
155
+ onChange: handleChange,
156
+ onBlur: handleBlur,
157
+ value: value === null || value === void 0 ? void 0 : value[index]
158
+ })
159
+ });
160
+ });
161
+ };
@@ -7,7 +7,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
7
7
  import React from 'react';
8
8
  import { omit } from 'lodash';
9
9
  import classnames from 'classnames';
10
- import { insertSeparator, useTransformColumns } from './utils';
10
+ import { insertSeparator } from './utils';
11
+ import { useTransformColumns } from './hooks';
11
12
  import ProForm from '../../../../ProForm';
12
13
  import ComRender from './component/ComRender';
13
14
  /**
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { InternalNamePath, NamePath } from 'antd/lib/form/interface';
3
3
  import { FormInstance } from 'antd';
4
- import type { GroupColumnType, GroupType, SpaceType } from './propsType';
4
+ import type { GroupColumnType, SpaceType } from './propsType';
5
5
  import type { ProFormColumnType, ReactiveFunction } from '../../render/propsType';
6
6
  export type EventArgs = any[];
7
7
  /**
@@ -50,19 +50,6 @@ type ValueTypeGetterParams = Pick<ProFormColumnType, 'valueType' | 'switchValue'
50
50
  export declare const getValueTypeTrans: (params: ValueTypeGetterParams) => any;
51
51
  /** 执行所有中间件 返回处理后的值 */
52
52
  export declare const getValueMiddleware: (value: any, callbacks?: any[]) => any;
53
- interface ColumnsTransformerParams {
54
- columns: GroupColumnType[];
55
- name?: NamePath;
56
- names?: NamePath[];
57
- value?: any[];
58
- onChange: any;
59
- namePath?: InternalNamePath;
60
- form: FormInstance;
61
- index?: number;
62
- formDisabled?: boolean;
63
- desensitizationKey?: string;
64
- groupProps: GroupType;
65
- }
66
- /** 转换columns */
67
- export declare const useTransformColumns: (params: ColumnsTransformerParams) => any[];
53
+ /** 获取中间件处理后的value */
54
+ export declare const valueFromEventWrapper: (column: any, args: any) => any;
68
55
  export {};
@@ -1,16 +1,11 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
2
  import _typeof from "@babel/runtime/helpers/esm/typeof";
4
3
  import "antd/es/button/style";
5
4
  import _Button from "antd/es/button";
6
5
  import { jsx as _jsx } from "react/jsx-runtime";
7
- /* eslint-disable no-lonely-if */
8
- import { useRef } from 'react';
9
- import { cloneDeep, isEqual, isFunction } from 'lodash';
6
+ import { isFunction } from 'lodash';
10
7
  import { validate } from '@zat-design/utils';
11
8
  import valueTypeMap from '../../../utils/valueType';
12
- import { useDeepCompareMemo } from '../../../utils/useDeepCompareMemo';
13
- import { difference } from '../../../../ProEditTable/utils/tools';
14
9
  /**
15
10
  * 插入间隔符
16
11
  * @param columns 表单配置数组
@@ -177,7 +172,7 @@ export var getValueMiddleware = function getValueMiddleware(value) {
177
172
  }, value);
178
173
  };
179
174
  /** 获取中间件处理后的value */
180
- var valueFromEventWrapper = function valueFromEventWrapper(column, args) {
175
+ export var valueFromEventWrapper = function valueFromEventWrapper(column, args) {
181
176
  var getValueFromEvent = column.getValueFromEvent,
182
177
  _column$valuePropName = column.valuePropName,
183
178
  valuePropName = _column$valuePropName === void 0 ? 'value' : _column$valuePropName,
@@ -193,157 +188,4 @@ var valueFromEventWrapper = function valueFromEventWrapper(column, args) {
193
188
  if (trim) list.push(getTrim);
194
189
  if (upperCase) list.push(getUpperCase);
195
190
  return getValueMiddleware(newValue, list);
196
- };
197
- /** 转换columns */
198
- export var useTransformColumns = function useTransformColumns(params) {
199
- var form = params.form,
200
- columns = params.columns,
201
- name = params.name,
202
- names = params.names,
203
- outerIndex = params.index,
204
- namePath = params.namePath,
205
- value = params.value,
206
- internalChange = params.onChange,
207
- groupProps = params.groupProps,
208
- formDisabled = params.formDisabled,
209
- desensitizationKey = params.desensitizationKey;
210
- var timerRef = useRef([]);
211
- return columns === null || columns === void 0 ? void 0 : columns.flatMap(function (column, index) {
212
- var type = column.type,
213
- valueType = column.valueType,
214
- switchValue = column.switchValue,
215
- toISOString = column.toISOString,
216
- toCSTString = column.toCSTString,
217
- fieldProps = column.fieldProps,
218
- normalize = column.normalize,
219
- disabled = column.disabled,
220
- show = column.show,
221
- component = column.component,
222
- clearNotShow = column.clearNotShow,
223
- desensitization = column.desensitization;
224
- var _ref = fieldProps || {},
225
- mode = _ref.mode,
226
- onChange = _ref.onChange,
227
- onFieldChange = _ref.onFieldChange,
228
- comDisabled = _ref.disabled,
229
- onBlur = _ref.onBlur;
230
- var _disabled = disabled || comDisabled;
231
- var columnName = names ? names[index] : [].concat(name, index);
232
- // 响应式字段改变后的回调
233
- var changedCallback = function changedCallback(lastDependency, current) {
234
- // 清值防抖 多次刷新时以最后一次为准
235
- if (clearNotShow !== false && names) {
236
- if ((current === null || current === void 0 ? void 0 : current.show) === false) {
237
- clearInterval(timerRef.current[index]);
238
- timerRef.current[index] = setTimeout(function () {
239
- if (names) {
240
- form.resetFields([columnName]);
241
- }
242
- if (!names && (value === null || value === void 0 ? void 0 : value.length)) {
243
- value[index] = null;
244
- form.setFieldValue(columnName, _toConsumableArray(value));
245
- }
246
- }, 200);
247
- } else {
248
- clearInterval(timerRef.current[index]);
249
- }
250
- }
251
- };
252
- // 响应式字段
253
- // eslint-disable-next-line react-hooks/rules-of-hooks
254
- var reactiveProps = useDeepCompareMemo(function () {
255
- return getReactiveProps({
256
- form: form,
257
- index: index,
258
- type: type,
259
- namePath: namePath,
260
- disabled: _disabled,
261
- show: show,
262
- component: component,
263
- fieldProps: fieldProps,
264
- name: columnName,
265
- desensitization: desensitization
266
- });
267
- }, changedCallback, [value, show, fieldProps, _disabled, columnName, type]);
268
- if (reactiveProps.show === false) {
269
- return [];
270
- }
271
- var transform = getValueTypeTrans({
272
- type: type,
273
- valueType: valueType,
274
- switchValue: switchValue,
275
- toISOString: toISOString,
276
- toCSTString: toCSTString,
277
- mode: mode
278
- });
279
- var newValue;
280
- var handleChange = function handleChange() {
281
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
282
- args[_key] = arguments[_key];
283
- }
284
- newValue = valueFromEventWrapper(column, args);
285
- if (transform === null || transform === void 0 ? void 0 : transform.normalize) {
286
- var _transform$normalize;
287
- newValue = transform === null || transform === void 0 ? void 0 : (_transform$normalize = transform.normalize) === null || _transform$normalize === void 0 ? void 0 : _transform$normalize.call(transform, newValue);
288
- } else if (normalize) {
289
- // @ts-ignore
290
- newValue = normalize === null || normalize === void 0 ? void 0 : normalize(newValue);
291
- }
292
- internalChange === null || internalChange === void 0 ? void 0 : internalChange(newValue, args[1], index);
293
- var values = form.getFieldValue(namePath);
294
- var originRow = (namePath === null || namePath === void 0 ? void 0 : namePath.length) ? cloneDeep(values) : undefined;
295
- onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, args);
296
- onFieldChange === null || onFieldChange === void 0 ? void 0 : onFieldChange(newValue, values, {
297
- index: outerIndex,
298
- namePath: namePath,
299
- form: form,
300
- option: args === null || args === void 0 ? void 0 : args[1]
301
- });
302
- // 如果是在可编辑表格或formList内部, 储存当前行的值, 并在变更后更新到表单里
303
- if ((namePath === null || namePath === void 0 ? void 0 : namePath.length) && !isEqual(originRow, values)) {
304
- var _Object$keys, _Object$keys$map;
305
- form.setFieldValue(namePath, values);
306
- var diff = difference(originRow, values) || {};
307
- var validateFieldKeys = (_Object$keys = Object.keys(diff)) === null || _Object$keys === void 0 ? void 0 : (_Object$keys$map = _Object$keys.map) === null || _Object$keys$map === void 0 ? void 0 : _Object$keys$map.call(_Object$keys, function (key) {
308
- return [].concat(_toConsumableArray(namePath), [key]);
309
- });
310
- if (validateFieldKeys === null || validateFieldKeys === void 0 ? void 0 : validateFieldKeys.length) {
311
- setTimeout(function () {
312
- form.validateFields([name].concat(_toConsumableArray(validateFieldKeys)));
313
- }, 100);
314
- }
315
- }
316
- };
317
- var handleBlur = function handleBlur() {
318
- if (!onBlur) return;
319
- var values = form.getFieldValue(namePath);
320
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
321
- args[_key2] = arguments[_key2];
322
- }
323
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(args[0], values, {
324
- index: outerIndex,
325
- namePath: namePath,
326
- form: form,
327
- option: args === null || args === void 0 ? void 0 : args[1]
328
- });
329
- };
330
- // 内外一个为true则为true
331
- var getLastDisabled = function getLastDisabled() {
332
- if (Array.isArray(groupProps.disabled)) {
333
- return reactiveProps.disabled || groupProps.disabled[index];
334
- }
335
- return reactiveProps.disabled || groupProps.disabled;
336
- };
337
- return _objectSpread(_objectSpread(_objectSpread({}, column), {}, {
338
- name: columnName
339
- }, reactiveProps), {}, {
340
- disabled: getLastDisabled(),
341
- getValueProps: transform === null || transform === void 0 ? void 0 : transform.getValueProps,
342
- fieldProps: _objectSpread(_objectSpread(_objectSpread({}, column === null || column === void 0 ? void 0 : column.fieldProps), reactiveProps === null || reactiveProps === void 0 ? void 0 : reactiveProps.fieldProps), {}, {
343
- onChange: handleChange,
344
- onBlur: handleBlur,
345
- value: value === null || value === void 0 ? void 0 : value[index]
346
- })
347
- });
348
- });
349
191
  };
@@ -92,6 +92,9 @@ var ButtonRender = function ButtonRender(props) {
92
92
  children: [_jsx(CloudUploadOutlined, {}), buttonText]
93
93
  })), afterRender ? _jsx("div", {
94
94
  className: "pro-upload-button-inner-right",
95
+ onClick: function onClick(e) {
96
+ return e.stopPropagation();
97
+ },
95
98
  children: afterRender
96
99
  }) : null]
97
100
  })