ztxkui 4.2.23-2 → 4.2.23-21

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.
Files changed (86) hide show
  1. package/dist/DemoCom/PrintContainerDemo.js +223 -70
  2. package/dist/TableDemo/data.js +1 -1
  3. package/dist/UI/Basic/index.d.ts +2 -0
  4. package/dist/UI/Basic/index.js +18 -0
  5. package/dist/UI/Form/index.d.ts +3 -0
  6. package/dist/UI/Form/index.js +187 -0
  7. package/dist/UI/Modal/hooks.d.ts +15 -0
  8. package/dist/UI/Modal/hooks.js +172 -0
  9. package/dist/UI/Modal/index.d.ts +3 -0
  10. package/dist/UI/Modal/index.js +46 -0
  11. package/dist/UI/Table/DefaultTable.d.ts +2 -0
  12. package/dist/UI/Table/DefaultTable.js +49 -0
  13. package/dist/UI/Table/EditTable.d.ts +2 -0
  14. package/dist/UI/Table/EditTable.js +259 -0
  15. package/dist/UI/Table/data.d.ts +10 -0
  16. package/dist/UI/Table/data.js +14 -0
  17. package/dist/UI/Table/index.d.ts +2 -0
  18. package/dist/UI/Table/index.js +5 -0
  19. package/dist/UI/index.d.ts +2 -0
  20. package/dist/UI/index.js +26 -0
  21. package/dist/components/EnhanceSelect/index.js +4 -0
  22. package/dist/components/Input/input.js +38 -13
  23. package/dist/components/PrintContainer/print-container.js +70 -30
  24. package/dist/components/ProForm/hooks.d.ts +23 -0
  25. package/dist/components/ProForm/hooks.js +209 -0
  26. package/dist/components/ProForm/index.d.ts +6 -0
  27. package/dist/components/ProForm/index.js +87 -0
  28. package/dist/components/ProForm/interface.d.ts +116 -0
  29. package/dist/components/ProForm/interface.js +1 -0
  30. package/dist/components/ProForm/items.d.ts +5 -0
  31. package/dist/components/ProForm/items.js +136 -0
  32. package/dist/components/ProForm/search-drawer.d.ts +11 -0
  33. package/dist/components/ProForm/search-drawer.js +76 -0
  34. package/dist/components/ProForm/setting.d.ts +5 -0
  35. package/dist/components/ProForm/setting.js +13 -0
  36. package/dist/components/ProFormList/index.d.ts +12 -0
  37. package/dist/components/ProFormList/index.js +34 -0
  38. package/dist/components/ProModal/ModalForm.d.ts +8 -0
  39. package/dist/components/ProModal/ModalForm.js +32 -0
  40. package/dist/components/ProModal/ModalTable.d.ts +8 -0
  41. package/dist/components/ProModal/ModalTable.js +32 -0
  42. package/dist/components/ProModal/hooks.d.ts +33 -0
  43. package/dist/components/ProModal/hooks.js +193 -0
  44. package/dist/components/ProModal/index.d.ts +17 -0
  45. package/dist/components/ProModal/index.js +80 -0
  46. package/dist/components/ProModal/interface.d.ts +47 -0
  47. package/dist/components/ProModal/interface.js +1 -0
  48. package/dist/components/ProTable/hooks.d.ts +28 -0
  49. package/dist/components/ProTable/hooks.js +272 -0
  50. package/dist/components/ProTable/index.d.ts +8 -0
  51. package/dist/components/ProTable/index.js +76 -0
  52. package/dist/components/ProTable/interface.d.ts +51 -0
  53. package/dist/components/ProTable/interface.js +1 -0
  54. package/dist/components/Table/hooks/useColumns.d.ts +4 -4
  55. package/dist/components/Table/hooks/useColumns.js +227 -169
  56. package/dist/components/Table/hooks/useInnerPagination.js +1 -0
  57. package/dist/components/Table/table-adddel-column.d.ts +2 -1
  58. package/dist/components/Table/table-adddel-column.js +5 -3
  59. package/dist/components/Table/table-enhance-cell.d.ts +6 -3
  60. package/dist/components/Table/table-enhance-cell.js +119 -110
  61. package/dist/components/Table/table-enhance-row.d.ts +3 -4
  62. package/dist/components/Table/table-enhance-row.js +6 -10
  63. package/dist/components/Table/table-resizable-title.d.ts +4 -5
  64. package/dist/components/Table/table-resizable-title.js +31 -6
  65. package/dist/components/Table/table.d.ts +2 -0
  66. package/dist/components/Table/table.js +154 -150
  67. package/dist/components/Table/utils/shallowEqual.d.ts +2 -0
  68. package/dist/components/Table/utils/shallowEqual.js +34 -0
  69. package/dist/components/Table/utils/validate.js +0 -3
  70. package/dist/components/Tabs/DraggableTabNode.d.ts +7 -0
  71. package/dist/components/Tabs/DraggableTabNode.js +33 -0
  72. package/dist/components/Tabs/hooks.d.ts +3 -0
  73. package/dist/components/Tabs/hooks.js +59 -0
  74. package/dist/components/Tabs/tabs.d.ts +3 -0
  75. package/dist/components/Tabs/tabs.js +8 -2
  76. package/dist/components/business/Footer/index.d.ts +1 -0
  77. package/dist/components/business/Footer/index.js +18 -4
  78. package/dist/components/business/Signatures/components/QunjSeal.js +3 -2
  79. package/dist/components/business/Signatures/index.js +13 -14
  80. package/dist/constants.d.ts +1 -1
  81. package/dist/constants.js +1 -1
  82. package/dist/index.css +327 -0
  83. package/dist/index.css.map +1 -1
  84. package/dist/index.d.ts +4 -0
  85. package/dist/index.js +9 -1
  86. package/package.json +4 -4
@@ -0,0 +1,80 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /**
24
+ * 模态框封装
25
+ * 是否需要每次打开模态框都是初始状态
26
+ * 1. 表单部分
27
+ * 2. 表格部分
28
+ * 3. 子表部分
29
+ */
30
+ import React, { memo, useState, useCallback } from 'react';
31
+ import Modal from '../Modal';
32
+ import ModalForm from './ModalForm';
33
+ import ModalTable from './ModalTable';
34
+ import Footer from '../business/Footer';
35
+ import { useData, useModalForm, useModalTable, useFooter } from './hooks';
36
+ function ProModal(props) {
37
+ // 属性提取
38
+ var children = props.children, request = props.request, visible = props.visible, onClose = props.onClose, value = props.value, onChange = props.onChange, outsideParams = props.outsideParams, formPropsItems = props.formPropsItems, formPropsShowDynamic = props.formPropsShowDynamic, formPropsShowDynamicKey = props.formPropsShowDynamicKey, formPropsDateTransform = props.formPropsDateTransform, formPropsReset = props.formPropsReset, tablePropsColumns = props.tablePropsColumns, tablePropsRowKey = props.tablePropsRowKey, tablePropsShowColumnDynamic = props.tablePropsShowColumnDynamic, tablePropsShowColumnDynamicKey = props.tablePropsShowColumnDynamicKey, tablePropsReset = props.tablePropsReset, tablePropsIsChoice = props.tablePropsIsChoice, tablePropsIsChoiceMode = props.tablePropsIsChoiceMode, tablePropsIsChoiceFilter = props.tablePropsIsChoiceFilter, tablePropsChoiceFilterHandle = props.tablePropsChoiceFilterHandle, tablePropsSelectedRowKeys = props.tablePropsSelectedRowKeys, tablePropsSelectedRows = props.tablePropsSelectedRows, tablePropsOnSelectedRowChange = props.tablePropsOnSelectedRowChange, tablePropsOnSelect = props.tablePropsOnSelect, tablePropsIsRepeatChoice = props.tablePropsIsRepeatChoice, modalReset = __rest(props, ["children", "request", "visible", "onClose", "value", "onChange", "outsideParams", "formPropsItems", "formPropsShowDynamic", "formPropsShowDynamicKey", "formPropsDateTransform", "formPropsReset", "tablePropsColumns", "tablePropsRowKey", "tablePropsShowColumnDynamic", "tablePropsShowColumnDynamicKey", "tablePropsReset", "tablePropsIsChoice", "tablePropsIsChoiceMode", "tablePropsIsChoiceFilter", "tablePropsChoiceFilterHandle", "tablePropsSelectedRowKeys", "tablePropsSelectedRows", "tablePropsOnSelectedRowChange", "tablePropsOnSelect", "tablePropsIsRepeatChoice"]);
39
+ // 获取表单相关信息
40
+ var _a = useModalForm(outsideParams, formPropsDateTransform, visible), form = _a.form, initialValues = _a.initialValues, fetchParams = _a.fetchParams, onSearchHandle = _a.onSearchHandle, onResetHandle = _a.onResetHandle;
41
+ // 弹出框内部获取数据相关逻辑
42
+ var _b = useData({ visible: visible, request: request }, fetchParams), loading = _b.loading, data = _b.data, setData = _b.setData;
43
+ // 弹出表格选中事件处理
44
+ var _c = useModalTable({
45
+ tablePropsChoiceFilterHandle: tablePropsChoiceFilterHandle,
46
+ tablePropsSelectedRowKeys: tablePropsSelectedRowKeys,
47
+ tablePropsSelectedRows: tablePropsSelectedRows,
48
+ tablePropsIsRepeatChoice: tablePropsIsRepeatChoice,
49
+ visible: visible,
50
+ }, setData), innerSelectedRowKeys = _c.innerSelectedRowKeys, setInnerSelectedRowKeys = _c.setInnerSelectedRowKeys, innerSelectedRows = _c.innerSelectedRows, setInnerSelectedRows = _c.setInnerSelectedRows, choiceFilterHandle = _c.choiceFilterHandle, onSelectedRowChange = _c.onSelectedRowChange, onTableChange = _c.onTableChange;
51
+ // 确定 取消相关事件
52
+ var _d = useFooter(onClose, {
53
+ innerSelectedRowKeys: innerSelectedRowKeys,
54
+ setInnerSelectedRowKeys: setInnerSelectedRowKeys,
55
+ innerSelectedRows: innerSelectedRows,
56
+ setInnerSelectedRows: setInnerSelectedRows,
57
+ tablePropsOnSelectedRowChange: tablePropsOnSelectedRowChange,
58
+ tablePropsRowKey: tablePropsRowKey,
59
+ }, data), footerDom = _d.footerDom, onCloseHandle = _d.onCloseHandle;
60
+ return (React.createElement(Modal, __assign({ loading: loading, visible: visible, onCancel: onCloseHandle, width: "80%", destroyOnClose: true, footer: null }, modalReset),
61
+ React.createElement(ModalForm, __assign({ items: formPropsItems, form: form, showDynamic: formPropsShowDynamic, showDynamicKey: formPropsShowDynamicKey, onSearchHandle: onSearchHandle, onResetHandle: onResetHandle, initialValues: initialValues }, formPropsReset)),
62
+ React.createElement(ModalTable, __assign({ columns: tablePropsColumns, rowKey: tablePropsRowKey, showColumnDynamic: tablePropsShowColumnDynamic, showColumnDynamicKey: tablePropsShowColumnDynamicKey, dataSource: data, isChoice: tablePropsIsChoice, choiceMode: tablePropsIsChoiceMode, isChoiceFilter: tablePropsIsChoiceFilter, selectedRowKeys: innerSelectedRowKeys, selectedRows: innerSelectedRows, choiceFilterHandle: choiceFilterHandle, onSelectedRowChange: onSelectedRowChange, onSelect: tablePropsOnSelect, onChange: onTableChange }, tablePropsReset)),
63
+ children,
64
+ React.createElement(Footer, { footerDom: footerDom, style: { marginTop: '10px' }, align: "right" })));
65
+ }
66
+ export function useVisible() {
67
+ var _a = useState(false), visible = _a[0], setVisible = _a[1];
68
+ var onClose = useCallback(function () {
69
+ setVisible(false);
70
+ }, []);
71
+ var onOpen = useCallback(function () {
72
+ setVisible(true);
73
+ }, []);
74
+ return {
75
+ visible: visible,
76
+ onClose: onClose,
77
+ onOpen: onOpen,
78
+ };
79
+ }
80
+ export default memo(ProModal);
@@ -0,0 +1,47 @@
1
+ /// <reference types="react" />
2
+ import { IProFormProps } from '../ProForm/interface';
3
+ import { ColumnsType } from '../Table';
4
+ import { IProps as IProTableProps } from '../ProTable/interface';
5
+ import { ModalProps } from 'antd/lib/modal';
6
+ export interface IDateTransform {
7
+ fromKey: (string | string[])[];
8
+ toKey: (string | string[])[];
9
+ type?: 'string' | 'object';
10
+ format?: string | string[];
11
+ }
12
+ export interface IProModalProps extends ModalProps {
13
+ children?: React.ReactNode;
14
+ request?: (params: any) => Promise<any>;
15
+ visible?: boolean;
16
+ onClose?: () => void;
17
+ value?: any;
18
+ onChange?: (value: any) => void;
19
+ /** 外部的查询参数 */
20
+ outsideParams?: any;
21
+ /** 表单配置 */
22
+ formPropsItems: IProFormProps['items'];
23
+ formPropsShowDynamic?: boolean;
24
+ formPropsShowDynamicKey?: string;
25
+ formPropsReset?: Partial<IProFormProps>;
26
+ formPropsDateTransform?: IDateTransform;
27
+ /** 表格配置 */
28
+ tablePropsColumns: ColumnsType<any>;
29
+ tablePropsRowKey: string;
30
+ tablePropsShowColumnDynamic?: boolean;
31
+ tablePropsShowColumnDynamicKey?: string;
32
+ tablePropsReset?: Partial<IProTableProps<any>>;
33
+ tablePropsIsChoice?: boolean;
34
+ tablePropsIsChoiceMode?: IProTableProps<any>['choiceMode'];
35
+ tablePropsIsChoiceFilter?: boolean;
36
+ tablePropsChoiceFilterHandle?: IProTableProps<any>['choiceFilterHandle'];
37
+ tablePropsSelectedRowKeys?: IProTableProps<any>['selectedRowKeys'];
38
+ tablePropsSelectedRows?: IProTableProps<any>['selectedRows'];
39
+ tablePropsOnSelectedRowChange?: IProTableProps<any>['onSelectedRowChange'];
40
+ tablePropsOnSelect?: IProTableProps<any>['onSelect'];
41
+ /** 模态框是否可以重复选择 */
42
+ tablePropsIsRepeatChoice?: boolean;
43
+ }
44
+ export interface IProModalFormProps extends IProFormProps {
45
+ }
46
+ export interface IProModalTableProps extends IProTableProps<any> {
47
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ /// <reference types="react" />
2
+ import { IProps } from './interface';
3
+ import { TableRowSelection } from '../../components/Table/index';
4
+ export declare function useDataSourceRef<D>(dataSource: D[]): import("react").MutableRefObject<D[]>;
5
+ export declare function useAddAndDelRow(showAddIcon: any, showDelIcon: any, dataSourceRef: any, addDataMode: any, addDataReturnRecord: any, onChange: any, rowKey: any, refreshScuCell: any): {
6
+ needAddAndDel: any;
7
+ onAddAndDelHandle: (type: 'add' | 'del', index: number) => void;
8
+ };
9
+ export declare function useMoveRow(onChange: any, dataSourceRef: any, refreshScuCell: any): (dragIndex: number, hoverIndex: number) => void;
10
+ export declare function useEditRow(onChange: any, dataSourceRef: any, innerTableHandleRef: any, { onBatchPastePre, onBatchPastePost }: {
11
+ onBatchPastePre: any;
12
+ onBatchPastePost: any;
13
+ }): {
14
+ onEditableSaveHandle: (record: any, index: number | undefined, _dataIndex?: string, otherConfig?: any) => void;
15
+ onBatchPasteHandle: (records: any, startIndex: any) => void;
16
+ };
17
+ export declare function useScuRfresh(): {
18
+ refreshScuCell: () => void;
19
+ getRefreshScuCell: () => boolean;
20
+ };
21
+ export declare function useChoice(choiceMode: IProps<any>['choiceMode'], filterOptions: any, selectedRowOptions: {
22
+ selectedRowKeys: IProps<any>['selectedRowKeys'];
23
+ selectedRows: IProps<any>['selectedRows'];
24
+ onSelectedRowChange: IProps<any>['onSelectedRowChange'];
25
+ onSelect: IProps<any>['onSelect'];
26
+ }): {
27
+ rowSelection: TableRowSelection<any>;
28
+ };
@@ -0,0 +1,272 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
13
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
14
+ to[j] = from[i];
15
+ return to;
16
+ };
17
+ import { useRef, useEffect, useMemo, useCallback } from 'react';
18
+ import update from 'immutability-helper';
19
+ // 设置数据源临时Ref对象
20
+ export function useDataSourceRef(dataSource) {
21
+ var dataSourceRef = useRef(dataSource);
22
+ useEffect(function () {
23
+ dataSourceRef.current = dataSource;
24
+ }, [dataSource]);
25
+ return dataSourceRef;
26
+ }
27
+ // 加减行相关
28
+ export function useAddAndDelRow(showAddIcon, showDelIcon, dataSourceRef, addDataMode, addDataReturnRecord, onChange, rowKey, refreshScuCell) {
29
+ var needAddAndDel = useMemo(function () {
30
+ return showAddIcon || showDelIcon;
31
+ }, [showAddIcon, showDelIcon]);
32
+ // 增减行回调
33
+ var onAddAndDelHandle = useCallback(function (type, index) {
34
+ var _a, _b;
35
+ if (typeof addDataMode === 'function') {
36
+ var newDataSource_1 = addDataMode(index, dataSourceRef.current, type);
37
+ refreshScuCell();
38
+ onChange &&
39
+ onChange(newDataSource_1, {
40
+ currentIndex: index,
41
+ type: type,
42
+ });
43
+ return;
44
+ }
45
+ var newDataSource = __spreadArray([], dataSourceRef.current);
46
+ var newRecord = {};
47
+ if (type === 'add') {
48
+ var currentRecord = newDataSource[index];
49
+ var outsideRecord = addDataReturnRecord
50
+ ? addDataReturnRecord(currentRecord)
51
+ : {};
52
+ if (addDataMode === 'blank') {
53
+ // 生成一条空白数据
54
+ newRecord = __assign((_a = {}, _a[rowKey] = Date.now() + "-" + index, _a.__INNER__ADD__DATA = true, _a), outsideRecord);
55
+ }
56
+ else {
57
+ // 复制当前这条数据
58
+ newRecord = __assign(__assign(__assign({}, currentRecord), (_b = {}, _b[rowKey] = Date.now() + "-" + index, _b.__INNER__ADD__DATA = true, _b)), outsideRecord);
59
+ }
60
+ newDataSource.splice(index + 1, 0, newRecord);
61
+ }
62
+ else {
63
+ newDataSource.splice(index, 1);
64
+ }
65
+ refreshScuCell();
66
+ onChange &&
67
+ onChange(newDataSource, {
68
+ currentIndex: index,
69
+ type: type,
70
+ });
71
+ }, [
72
+ addDataMode,
73
+ onChange,
74
+ dataSourceRef,
75
+ rowKey,
76
+ refreshScuCell,
77
+ addDataReturnRecord,
78
+ ]);
79
+ return {
80
+ needAddAndDel: needAddAndDel,
81
+ onAddAndDelHandle: onAddAndDelHandle,
82
+ };
83
+ }
84
+ // 拖拽行相关
85
+ export function useMoveRow(onChange, dataSourceRef, refreshScuCell) {
86
+ var onMoveRowHandle = useCallback(function (dragIndex, hoverIndex) {
87
+ var copyDataSource = __spreadArray([], dataSourceRef.current);
88
+ var dragRow = copyDataSource[dragIndex];
89
+ var newDataSource = update(copyDataSource, {
90
+ $splice: [
91
+ [dragIndex, 1],
92
+ [hoverIndex, 0, dragRow],
93
+ ],
94
+ });
95
+ refreshScuCell();
96
+ onChange &&
97
+ onChange(newDataSource, {
98
+ currentIndex: dragIndex,
99
+ targetIndex: hoverIndex,
100
+ type: 'move',
101
+ });
102
+ }, [onChange, dataSourceRef, refreshScuCell]);
103
+ return onMoveRowHandle;
104
+ }
105
+ // 编辑行相关
106
+ function objIsEqual(newObj, oldObj) {
107
+ try {
108
+ var keys = Object.keys(newObj);
109
+ var oldKeys = Object.keys(oldObj);
110
+ if (keys.length !== oldKeys.length) {
111
+ return false;
112
+ }
113
+ for (var i = 0; i < keys.length; i++) {
114
+ var key = keys[i];
115
+ if (oldObj[key] !== newObj[key]) {
116
+ return false;
117
+ }
118
+ }
119
+ return true;
120
+ }
121
+ catch (err) {
122
+ return false;
123
+ }
124
+ }
125
+ export function useEditRow(onChange, dataSourceRef, innerTableHandleRef, _a) {
126
+ var onBatchPastePre = _a.onBatchPastePre, onBatchPastePost = _a.onBatchPastePost;
127
+ var onEditableSaveHandle = useCallback(function (record, index, _dataIndex, otherConfig) {
128
+ var _a;
129
+ var _b, _c, _d, _e;
130
+ if (_dataIndex === void 0) { _dataIndex = ''; }
131
+ if (typeof index === 'number') {
132
+ // TODO:帮助找到真实的index,如果开启内部分页 需要这么做
133
+ var realyIndex = otherConfig && otherConfig.isInner
134
+ ? index
135
+ : (_c = (_b = innerTableHandleRef.current) === null || _b === void 0 ? void 0 : _b.getRealyIndex) === null || _c === void 0 ? void 0 : _c.call(_b, index);
136
+ var newDataSource = __spreadArray([], dataSourceRef.current);
137
+ var oldRecord = newDataSource[realyIndex];
138
+ // 如果新的record里面的值 老的Record里面有 那么不需要触发onChange
139
+ // 这里主要是为了优化物料组件带来的多次rerender导致的一些问题
140
+ if (objIsEqual(record, oldRecord)) {
141
+ return;
142
+ }
143
+ // TODO:清楚错误样式
144
+ if (!otherConfig || (otherConfig && !otherConfig.isInner)) {
145
+ (_e = (_d = innerTableHandleRef === null || innerTableHandleRef === void 0 ? void 0 : innerTableHandleRef.current) === null || _d === void 0 ? void 0 : _d.clearErrorClass) === null || _e === void 0 ? void 0 : _e.call(_d, index);
146
+ }
147
+ var newRecord = _dataIndex
148
+ ? __assign(__assign(__assign({}, record), oldRecord), (_a = {}, _a[_dataIndex] = record[_dataIndex], _a)) : __assign(__assign({}, oldRecord), record);
149
+ newDataSource.splice(realyIndex, 1, newRecord);
150
+ onChange &&
151
+ onChange(newDataSource, {
152
+ currentIndex: realyIndex,
153
+ type: 'edit',
154
+ });
155
+ }
156
+ }, [dataSourceRef, onChange, innerTableHandleRef]);
157
+ var onBatchPasteHandle = useCallback(function (records, startIndex) {
158
+ if (!Array.isArray(records)) {
159
+ return;
160
+ }
161
+ // 前置处理
162
+ var pasteRecords = onBatchPastePre
163
+ ? onBatchPastePre(records, {
164
+ currentIndex: startIndex,
165
+ })
166
+ : records;
167
+ // 计算结束位置
168
+ var endIndex = startIndex + pasteRecords.length - 1;
169
+ var currentRecords = Array.isArray(dataSourceRef.current)
170
+ ? dataSourceRef.current.slice()
171
+ : [];
172
+ if (endIndex > currentRecords.length - 1) {
173
+ endIndex = currentRecords.length - 1;
174
+ }
175
+ // 从开始位置开始,替换对应的值
176
+ var currentIndex = 0;
177
+ var dataSource = currentRecords.map(function (record, index) {
178
+ if (index >= startIndex && index <= endIndex) {
179
+ var obj = __assign(__assign({}, record), pasteRecords[currentIndex]);
180
+ currentIndex++;
181
+ return obj;
182
+ }
183
+ return record;
184
+ });
185
+ // 后置处理
186
+ var newDataSource = onBatchPastePost
187
+ ? onBatchPastePost(dataSource, {
188
+ currentIndex: startIndex,
189
+ endIndex: endIndex,
190
+ })
191
+ : dataSource;
192
+ // 触发onChange事件
193
+ onChange &&
194
+ onChange(newDataSource, {
195
+ currentIndex: startIndex,
196
+ endIndex: endIndex,
197
+ type: 'paste',
198
+ });
199
+ }, [dataSourceRef, onChange, onBatchPastePre, onBatchPastePost]);
200
+ return {
201
+ onEditableSaveHandle: onEditableSaveHandle,
202
+ onBatchPasteHandle: onBatchPasteHandle,
203
+ };
204
+ }
205
+ // SCU刷新逻辑
206
+ // 这么写的原因是 如果拖拽行 增减行后,并不能触发column的scu
207
+ // 之前的写法是,通过useState刷新。但是 setState会触发整个组件的刷新
208
+ // 设置数据后,本身会触发setState。导致执行两次rerender。每个单元格都会执行rerender
209
+ // 通过Ref并不会触发 setState 通过setTimeout也不会导致每一个单元格的刷新出现问题
210
+ export function useScuRfresh() {
211
+ var timeOutRef = useRef(null);
212
+ var tableSCURefreshRef = useRef();
213
+ var refreshScuCell = useCallback(function () {
214
+ tableSCURefreshRef.current = true;
215
+ }, []);
216
+ var getRefreshScuCell = useCallback(function () {
217
+ if (tableSCURefreshRef.current) {
218
+ if (timeOutRef.current) {
219
+ clearTimeout(timeOutRef.current);
220
+ timeOutRef.current = null;
221
+ }
222
+ timeOutRef.current = setTimeout(function () {
223
+ tableSCURefreshRef.current = false;
224
+ });
225
+ return true;
226
+ }
227
+ return false;
228
+ }, []);
229
+ return {
230
+ refreshScuCell: refreshScuCell,
231
+ getRefreshScuCell: getRefreshScuCell,
232
+ };
233
+ }
234
+ // 选择相关控制
235
+ export function useChoice(choiceMode, filterOptions, selectedRowOptions) {
236
+ if (choiceMode === void 0) { choiceMode = 'checkbox'; }
237
+ var isChoiceFilter = filterOptions.isChoiceFilter, choiceFilterHandle = filterOptions.choiceFilterHandle;
238
+ var selectedRowKeys = selectedRowOptions.selectedRowKeys, selectedRows = selectedRowOptions.selectedRows, onSelectedRowChange = selectedRowOptions.onSelectedRowChange, onSelect = selectedRowOptions.onSelect;
239
+ var rowSelection = useMemo(function () {
240
+ return {
241
+ type: choiceMode,
242
+ selectedRowKeys: selectedRowKeys,
243
+ onChange: function (selectedRowKeys, selectedRows) {
244
+ onSelectedRowChange &&
245
+ onSelectedRowChange(selectedRowKeys, selectedRows);
246
+ },
247
+ onSelect: function (record, selected, selectedRows) {
248
+ onSelect && onSelect(record, selected, selectedRows);
249
+ },
250
+ // 过滤规则设置
251
+ getCheckboxProps: function (record) {
252
+ // 如果不开启过滤 那么全都可以选
253
+ if (!isChoiceFilter) {
254
+ return {};
255
+ }
256
+ // 如果传入了过滤函数,那么如何过滤用户自定义
257
+ if (choiceFilterHandle) {
258
+ return choiceFilterHandle(record, selectedRowKeys, selectedRows);
259
+ }
260
+ },
261
+ };
262
+ }, [
263
+ choiceMode,
264
+ isChoiceFilter,
265
+ choiceFilterHandle,
266
+ selectedRowKeys,
267
+ selectedRows,
268
+ onSelectedRowChange,
269
+ onSelect,
270
+ ]);
271
+ return { rowSelection: rowSelection };
272
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 业务封装可编辑表格组件
3
+ */
4
+ import React from 'react';
5
+ import { IProps } from './interface';
6
+ declare function ProEditTable(props: IProps<any>): JSX.Element;
7
+ declare const _default: React.MemoExoticComponent<typeof ProEditTable>;
8
+ export default _default;
@@ -0,0 +1,76 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ /**
24
+ * 业务封装可编辑表格组件
25
+ */
26
+ import React, { memo, useRef, useImperativeHandle } from 'react';
27
+ import { Table } from '../../index';
28
+ import { useDataSourceRef, useAddAndDelRow, useScuRfresh, useMoveRow, useEditRow, useChoice, } from './hooks';
29
+ function ProEditTable(props) {
30
+ var rowKey = props.rowKey, dataSource = props.dataSource, columns = props.columns, onChange = props.onChange, showAddIcon = props.showAddIcon, showDelIcon = props.showDelIcon, _a = props.addDataMode, addDataMode = _a === void 0 ? 'blank' : _a, addDataReturnRecord = props.addDataReturnRecord, isMove = props.isMove, isEdit = props.isEdit, isPaste = props.isPaste, tableHandleRef = props.tableHandleRef, onBatchPastePre = props.onBatchPastePre, onBatchPastePost = props.onBatchPastePost, isChoice = props.isChoice, choiceMode = props.choiceMode, isChoiceFilter = props.isChoiceFilter, choiceFilterHandle = props.choiceFilterHandle, selectedRowKeys = props.selectedRowKeys, selectedRows = props.selectedRows, onSelectedRowChange = props.onSelectedRowChange, onSelect = props.onSelect, restProps = __rest(props, ["rowKey", "dataSource", "columns", "onChange", "showAddIcon", "showDelIcon", "addDataMode", "addDataReturnRecord", "isMove", "isEdit", "isPaste", "tableHandleRef", "onBatchPastePre", "onBatchPastePost", "isChoice", "choiceMode", "isChoiceFilter", "choiceFilterHandle", "selectedRowKeys", "selectedRows", "onSelectedRowChange", "onSelect"]);
31
+ var innerTableHandleRef = useRef();
32
+ var tableColumns = columns.map(function (item) {
33
+ if (item.shouldCellUpdate) {
34
+ var fn_1 = item.shouldCellUpdate;
35
+ item.shouldCellUpdate = function (record, preRecord) {
36
+ if (getRefreshScuCell()) {
37
+ return true;
38
+ }
39
+ return fn_1(record, preRecord);
40
+ };
41
+ }
42
+ return item;
43
+ });
44
+ // 保存dataSource值存为Ref
45
+ var dataSourceRef = useDataSourceRef(dataSource);
46
+ // SCU逻辑
47
+ var _b = useScuRfresh(), refreshScuCell = _b.refreshScuCell, getRefreshScuCell = _b.getRefreshScuCell;
48
+ // 增减行相关hook
49
+ var _c = useAddAndDelRow(showAddIcon, showDelIcon, dataSourceRef, addDataMode, addDataReturnRecord, onChange, rowKey, refreshScuCell), needAddAndDel = _c.needAddAndDel, onAddAndDelHandle = _c.onAddAndDelHandle;
50
+ // 拖拽行相关hook
51
+ var onMoveRowHandle = useMoveRow(onChange, dataSourceRef, refreshScuCell);
52
+ // 修改行相关hook
53
+ var _d = useEditRow(onChange, dataSourceRef, innerTableHandleRef, {
54
+ onBatchPastePre: onBatchPastePre,
55
+ onBatchPastePost: onBatchPastePost,
56
+ }), onEditableSaveHandle = _d.onEditableSaveHandle, onBatchPasteHandle = _d.onBatchPasteHandle;
57
+ // 选择行相关hook
58
+ var rowSelection = useChoice(choiceMode, {
59
+ isChoiceFilter: isChoiceFilter,
60
+ choiceFilterHandle: choiceFilterHandle,
61
+ }, {
62
+ selectedRowKeys: selectedRowKeys,
63
+ selectedRows: selectedRows,
64
+ onSelectedRowChange: onSelectedRowChange,
65
+ onSelect: onSelect,
66
+ }).rowSelection;
67
+ useImperativeHandle(tableHandleRef, function () { return ({
68
+ validate: innerTableHandleRef.current.validate,
69
+ clearErrorClass: innerTableHandleRef.current.clearErrorClass,
70
+ getCurrentPage: innerTableHandleRef.current.getCurrentPage,
71
+ getRealyIndex: innerTableHandleRef.current.getRealyIndex,
72
+ onEditableSaveHandle: onEditableSaveHandle,
73
+ }); });
74
+ return (React.createElement(Table, __assign({ rowKey: rowKey, dataSource: dataSource, columns: tableColumns, hideAddIcon: !showAddIcon, hideDelIcon: !showDelIcon, onAddAndDelHandle: needAddAndDel ? onAddAndDelHandle : undefined, onMoveRow: isMove ? onMoveRowHandle : undefined, onEditableSave: isEdit ? onEditableSaveHandle : undefined, tableHandleRef: innerTableHandleRef, onTableChange: isPaste ? onBatchPasteHandle : undefined, rowSelection: isChoice ? rowSelection : undefined }, restProps)));
75
+ }
76
+ export default memo(ProEditTable);
@@ -0,0 +1,51 @@
1
+ /// <reference types="react" />
2
+ import { ColumnsType } from '../../components/Table';
3
+ import { IProps as TableIProps } from '../../components/Table/table';
4
+ export interface IProps<RecordType> extends Omit<TableIProps<RecordType>, 'columns' | 'onChange' | 'onEditableSave'> {
5
+ dataSource: any[];
6
+ columns: ColumnsType<any>;
7
+ rowKey: string;
8
+ onChange?: (dataSource: any[], info?: {
9
+ currentIndex: number;
10
+ endIndex?: number;
11
+ targetIndex?: number;
12
+ type?: string;
13
+ }) => void;
14
+ showAddIcon?: boolean;
15
+ showDelIcon?: boolean;
16
+ /**
17
+ * 增加数据的模式 blank add空白数据; copy add复制数据; 自定义增加
18
+ */
19
+ addDataMode?: 'blank' | 'copy' | ((index: number, dataSource: any[], type: string) => any[]);
20
+ addDataReturnRecord?: (record: any) => any;
21
+ isMove?: boolean;
22
+ isEdit?: boolean;
23
+ isPaste?: boolean;
24
+ onBatchPastePre?: (data: any[], info?: {
25
+ currentIndex: number;
26
+ endIndex?: number;
27
+ }) => any[];
28
+ onBatchPastePost?: (data: any[], info?: {
29
+ currentIndex: number;
30
+ endIndex?: number;
31
+ }) => any[];
32
+ isChoice?: boolean;
33
+ choiceMode?: 'radio' | 'checkbox';
34
+ isChoiceFilter?: boolean;
35
+ choiceFilterHandle?: (record: any, selectedRowKeys: React.Key[], selectedRows: any[]) => any;
36
+ selectedRowKeys?: React.Key[];
37
+ selectedRows?: any[];
38
+ onSelectedRowChange?: (selectedRowKeys: React.Key[], selectedRows: any[]) => void;
39
+ onSelect?: (record: any, selected: boolean, selectedRows: any) => void;
40
+ tableHandleRef?: React.Ref<{
41
+ validate: () => Promise<any>;
42
+ clearErrorClass: (index: number) => void;
43
+ getCurrentPage: () => {
44
+ page: number;
45
+ pageSize: number;
46
+ } | null;
47
+ getRealyIndex: (index: number) => number;
48
+ onEditableSaveHandle: (record: any, index: number | undefined, _dataIndex: string) => void;
49
+ [prop: string]: any;
50
+ }>;
51
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { ColumnsType } from '../';
3
2
  export interface IConfigInfo {
4
3
  [props: string]: {
@@ -9,6 +8,7 @@ export interface IConfigInfo {
9
8
  }
10
9
  interface IProps<RecordType> {
11
10
  columns: ColumnsType<RecordType> | undefined;
11
+ hiddenColumnDynamicIcon?: boolean;
12
12
  showColumnDynamic?: boolean;
13
13
  showColumnDynamicKey?: string;
14
14
  /**新增行删除行方法 */
@@ -39,8 +39,8 @@ export declare const LOCALSTORAGE_LRU_KEY = "ztui_dynamic_table_lru_key";
39
39
  export declare const LOCALSTORAGE_LRU_MAX_SIZE = 500;
40
40
  export declare function setDynamicKey(dynamicStorageKey: string, value: any): void;
41
41
  declare function useColumns<RecordType>(props: IProps<RecordType>): {
42
- newColumns: any;
43
- dynamicColumns: any;
44
- setNewColumns: React.Dispatch<any>;
42
+ newColumns: ColumnsType<RecordType>;
43
+ dynamicColumns: ColumnsType<RecordType>;
44
+ refreshColumnsHandle: (columns?: any) => void;
45
45
  };
46
46
  export default useColumns;