ztxkui 4.3.7 → 4.3.8

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.
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function DefaultTable(): JSX.Element;
@@ -0,0 +1,49 @@
1
+ // 普通的表格使用
2
+ import { useState, useEffect } from 'react';
3
+ import { Table } from '../../index';
4
+ import { data1 } from './data';
5
+ // 表格列配置相关逻辑
6
+ // 可以把columns定义成常量再最外面,或者state
7
+ function useColumns() {
8
+ var _a = useState([]), data = _a[0], setData = _a[1];
9
+ var columns = [
10
+ {
11
+ title: '序号',
12
+ width: 62,
13
+ fixed: 'left',
14
+ key: 'index',
15
+ render: function (_text, _record, index) { return "" + (index + 1); },
16
+ },
17
+ {
18
+ title: '测试列1',
19
+ width: 100,
20
+ dataIndex: 'test1',
21
+ key: 'test1',
22
+ showCopy: true,
23
+ },
24
+ {
25
+ title: '测试列2',
26
+ width: 100,
27
+ dataIndex: 'test2',
28
+ key: 'test2',
29
+ showCopy: true,
30
+ render: function (_text, _record, index) {
31
+ return _text + '自定义添加';
32
+ },
33
+ },
34
+ ];
35
+ useEffect(function () {
36
+ setTimeout(function () {
37
+ setData(data1);
38
+ }, 300);
39
+ }, []);
40
+ return { columns: columns, data: data };
41
+ }
42
+ export default function DefaultTable() {
43
+ var _a = useColumns(), columns = _a.columns, data = _a.data;
44
+ return (React.createElement(Table, { rowKey: "id", columns: columns, dataSource: data,
45
+ // 是否开启动态列配置
46
+ showColumnDynamic: true,
47
+ // 动态列配置必须参数,唯一的键值
48
+ showColumnDynamicKey: "single-local-key-001" }));
49
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function EditTable(): JSX.Element;
@@ -0,0 +1,231 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ // 带编辑属性的表格使用
38
+ import { useState, useEffect, useCallback, useRef } from 'react';
39
+ import { data2 } from './data';
40
+ import ProEditTable from './ProEditTable';
41
+ import { Button, message, EnhanceSelect } from '../../index';
42
+ // 表格列配置相关逻辑
43
+ // 可以把columns定义成常量再最外面,或者state
44
+ // 编辑列的配置需要注意的点
45
+ // 1. 对于编辑想的scu配置,因为里面存在比较复杂的render
46
+ // 2. 如果是input 或者inputNumber可以通过配置实现
47
+ // 3. 可以通过配置校验规则 验证表格
48
+ // 4. 自定义render 需要调用表格提供的修改数据方法
49
+ function useColumns(tableHandleRef) {
50
+ var _a = useState([]), data = _a[0], setData = _a[1];
51
+ var columns = [
52
+ {
53
+ title: '序号',
54
+ width: 62,
55
+ fixed: 'left',
56
+ key: 'index',
57
+ render: function (_text, _record, index) { return "" + (index + 1); },
58
+ },
59
+ {
60
+ title: '测试列1',
61
+ width: 100,
62
+ dataIndex: 'test1',
63
+ key: 'test1',
64
+ showCopy: true,
65
+ },
66
+ {
67
+ title: '测试列2',
68
+ width: 100,
69
+ dataIndex: 'test2',
70
+ key: 'test2',
71
+ showCopy: true,
72
+ render: function (_text, _record, index) {
73
+ return _text + '自定义添加';
74
+ },
75
+ },
76
+ {
77
+ title: '测试列3',
78
+ width: 100,
79
+ dataIndex: 'test3',
80
+ key: 'test3',
81
+ showCopy: true,
82
+ // 普通输入框配置
83
+ editable: true,
84
+ // 配置列的验证规则,这种是最普通的非空校验
85
+ validate: {},
86
+ shouldCellUpdate: function (record, preRecord) {
87
+ return record.test3 !== preRecord.test3;
88
+ },
89
+ },
90
+ {
91
+ title: '测试列4',
92
+ width: 100,
93
+ dataIndex: 'test4',
94
+ key: 'test4',
95
+ showCopy: true,
96
+ editable: true,
97
+ editableConfig: {
98
+ type: 'input',
99
+ placeholder: '输入',
100
+ },
101
+ // 配置列的验证规则,实现自定义校验
102
+ validate: {
103
+ validate: function (value, record, index, title) {
104
+ // value 当前输入值
105
+ // record 当前行数据
106
+ // index 当前行
107
+ // title 列头
108
+ if (value === '我是张飞') {
109
+ // 返回错误格式,为了迎合表单的校验
110
+ return Promise.reject({
111
+ errorFields: [
112
+ {
113
+ errors: "\u67D0\u67D0\u8868\u683C \u7B2C" + index + "\u884C " + title + " \u4E0D\u80FD\u4E3A\u5F20\u98DE\uFF01",
114
+ },
115
+ ],
116
+ });
117
+ }
118
+ return Promise.resolve();
119
+ },
120
+ },
121
+ shouldCellUpdate: function (record, preRecord) {
122
+ return record.test4 !== preRecord.test4;
123
+ },
124
+ },
125
+ {
126
+ title: '测试列5',
127
+ width: 100,
128
+ dataIndex: 'test5',
129
+ key: 'test5',
130
+ showCopy: true,
131
+ editable: true,
132
+ // 可以增加一些编辑列的配置,目前只建议使用 inputNumber 或者input
133
+ // input的话 可以不使用这个配置 默认就是input
134
+ editableConfig: {
135
+ type: 'inputNumber',
136
+ placeholder: '输入',
137
+ },
138
+ shouldCellUpdate: function (record, preRecord) {
139
+ return record.test5 !== preRecord.test5;
140
+ },
141
+ },
142
+ {
143
+ title: '测试列6',
144
+ width: 100,
145
+ dataIndex: 'test6',
146
+ key: 'test6',
147
+ shouldCellUpdate: function (record, preRecord) {
148
+ return record.test6 !== preRecord.test6;
149
+ },
150
+ // 自定义render的话 需要手动调用表格的修改数据方法,只传递当前值
151
+ render: function (_text, _record, index) {
152
+ return (React.createElement(EnhanceSelect, { value: _text, list: [
153
+ {
154
+ id: '1',
155
+ name: '小明',
156
+ },
157
+ {
158
+ id: '2',
159
+ name: '小李',
160
+ },
161
+ ], onChange: function (value, option, fullData) {
162
+ var _a, _b, _c;
163
+ var newRecord = {
164
+ test6: value,
165
+ test6Name: fullData.name,
166
+ };
167
+ var realyIndex = (_b = (_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.getRealyIndex) === null || _b === void 0 ? void 0 : _b.call(_a, index);
168
+ (_c = tableHandleRef.current) === null || _c === void 0 ? void 0 : _c.onEditableSaveHandle(newRecord, realyIndex);
169
+ } }));
170
+ },
171
+ },
172
+ ];
173
+ useEffect(function () {
174
+ setTimeout(function () {
175
+ setData(data2);
176
+ }, 300);
177
+ }, []);
178
+ return { columns: columns, data: data, setData: setData };
179
+ }
180
+ export default function EditTable() {
181
+ var _this = this;
182
+ var tableHandleRef = useRef({});
183
+ var _a = useColumns(tableHandleRef), columns = _a.columns, data = _a.data, setData = _a.setData;
184
+ // 触发onChange事件
185
+ var onChange = useCallback(function (dataSource) {
186
+ setData(dataSource);
187
+ }, [setData]);
188
+ return (React.createElement("div", null,
189
+ React.createElement(Button, { onClick: function () {
190
+ console.log(data);
191
+ } }, "\u83B7\u53D6\u6570\u636E"),
192
+ React.createElement(Button, { onClick: function () { return __awaiter(_this, void 0, void 0, function () {
193
+ var err_1, errorFields;
194
+ var _a;
195
+ return __generator(this, function (_b) {
196
+ switch (_b.label) {
197
+ case 0:
198
+ _b.trys.push([0, 2, , 3]);
199
+ return [4 /*yield*/, ((_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.validate())];
200
+ case 1:
201
+ _b.sent();
202
+ return [3 /*break*/, 3];
203
+ case 2:
204
+ err_1 = _b.sent();
205
+ errorFields = err_1.errorFields;
206
+ if (errorFields) {
207
+ message.warning(errorFields[0].errors + '');
208
+ }
209
+ return [3 /*break*/, 3];
210
+ case 3: return [2 /*return*/];
211
+ }
212
+ });
213
+ }); } }, "\u89E6\u53D1\u9A8C\u8BC1"),
214
+ React.createElement(ProEditTable, { rowKey: "id", columns: columns, dataSource: data,
215
+ // 调用表格内部提供的方法
216
+ tableHandleRef: tableHandleRef,
217
+ // 是否开启编辑,对于可编辑表格来说 这个属性很重要
218
+ isEdit: true,
219
+ // 是否开启拖拽
220
+ isMove: true,
221
+ // 是否可以批量复制,如果批量复制需要前置处理 或者后置处理 可通过提供方法处理
222
+ isPaste: true,
223
+ // 是否开启增减行
224
+ showDelIcon: true, showAddIcon: true,
225
+ // 增加数据的规则 是增加空白行 还是 复制一行
226
+ addDataMode: "blank",
227
+ // 是否记录列宽,但是又不要显示那个按钮
228
+ showColumnDynamic: true, showColumnDynamicKey: "single-110011", hiddenColumnDynamicIcon: true,
229
+ // 开启内部分页
230
+ showInnerPagination: true, defaultInnerPageSize: 20, onChange: onChange })));
231
+ }
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ export declare function useDataSourceRef<D>(dataSource: D[]): import("react").MutableRefObject<D[]>;
3
+ export declare function useAddAndDelRow(showAddIcon: any, showDelIcon: any, dataSourceRef: any, addDataMode: any, onChange: any, rowKey: any, refreshScuCell: any): {
4
+ needAddAndDel: any;
5
+ onAddAndDelHandle: (type: 'add' | 'del', index: number) => void;
6
+ };
7
+ export declare function useMoveRow(onChange: any, dataSourceRef: any, refreshScuCell: any): (dragIndex: number, hoverIndex: number) => void;
8
+ export declare function useEditRow(onChange: any, dataSourceRef: any, { onBatchPastePre, onBatchPastePost }: {
9
+ onBatchPastePre: any;
10
+ onBatchPastePost: any;
11
+ }): {
12
+ onEditableSaveHandle: (record: any, index: number | undefined, _dataIndex?: string) => void;
13
+ onBatchPasteHandle: (records: any, startIndex: any) => void;
14
+ };
15
+ export declare function useScuRfresh(): {
16
+ refreshScuCell: () => void;
17
+ getRefreshScuCell: () => boolean;
18
+ };
@@ -0,0 +1,178 @@
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, 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);
37
+ onChange && onChange(newDataSource_1);
38
+ return;
39
+ }
40
+ var newDataSource = __spreadArray([], dataSourceRef.current);
41
+ var newRecord = {};
42
+ if (type === 'add') {
43
+ if (addDataMode === 'blank') {
44
+ // 生成一条空白数据
45
+ newRecord = (_a = {},
46
+ _a[rowKey] = Date.now() + "-" + index,
47
+ _a.__INNER__ADD__DATA = true,
48
+ _a);
49
+ }
50
+ else {
51
+ // 复制当前这条数据
52
+ var currentRecord = newDataSource[index];
53
+ newRecord = __assign(__assign({}, currentRecord), (_b = {}, _b[rowKey] = Date.now() + "-" + index, _b.__INNER__ADD__DATA = true, _b));
54
+ }
55
+ newDataSource.splice(index + 1, 0, newRecord);
56
+ }
57
+ else {
58
+ newDataSource.splice(index, 1);
59
+ }
60
+ refreshScuCell();
61
+ onChange && onChange(newDataSource);
62
+ }, [addDataMode, onChange, dataSourceRef, rowKey, refreshScuCell]);
63
+ return {
64
+ needAddAndDel: needAddAndDel,
65
+ onAddAndDelHandle: onAddAndDelHandle,
66
+ };
67
+ }
68
+ // 拖拽行相关
69
+ export function useMoveRow(onChange, dataSourceRef, refreshScuCell) {
70
+ var onMoveRowHandle = useCallback(function (dragIndex, hoverIndex) {
71
+ var copyDataSource = __spreadArray([], dataSourceRef.current);
72
+ var dragRow = copyDataSource[dragIndex];
73
+ var newDataSource = update(copyDataSource, {
74
+ $splice: [
75
+ [dragIndex, 1],
76
+ [hoverIndex, 0, dragRow],
77
+ ],
78
+ });
79
+ refreshScuCell();
80
+ onChange && onChange(newDataSource);
81
+ }, [onChange, dataSourceRef, refreshScuCell]);
82
+ return onMoveRowHandle;
83
+ }
84
+ // 编辑行相关
85
+ function objIsEqual(newObj, oldObj) {
86
+ var keys = Object.keys(newObj);
87
+ for (var i = 0; i < keys.length; i++) {
88
+ var key = keys[i];
89
+ if (oldObj[key] !== newObj[key]) {
90
+ return false;
91
+ }
92
+ }
93
+ return true;
94
+ }
95
+ export function useEditRow(onChange, dataSourceRef, _a) {
96
+ var onBatchPastePre = _a.onBatchPastePre, onBatchPastePost = _a.onBatchPastePost;
97
+ var onEditableSaveHandle = useCallback(function (record, index, _dataIndex) {
98
+ var _a;
99
+ if (_dataIndex === void 0) { _dataIndex = ''; }
100
+ if (typeof index === 'number') {
101
+ var newDataSource = __spreadArray([], dataSourceRef.current);
102
+ var oldRecord = newDataSource[index];
103
+ // 如果新的record里面的值 老的Record里面有 那么不需要触发onChange
104
+ // 这里主要是为了优化物料组件带来的多次rerender导致的一些问题
105
+ if (objIsEqual(record, oldRecord)) {
106
+ return;
107
+ }
108
+ var newRecord = _dataIndex
109
+ ? __assign(__assign(__assign({}, record), oldRecord), (_a = {}, _a[_dataIndex] = record[_dataIndex], _a)) : __assign(__assign({}, oldRecord), record);
110
+ newDataSource.splice(index, 1, newRecord);
111
+ onChange && onChange(newDataSource);
112
+ }
113
+ }, [dataSourceRef, onChange]);
114
+ var onBatchPasteHandle = useCallback(function (records, startIndex) {
115
+ if (!Array.isArray(records)) {
116
+ return;
117
+ }
118
+ // 前置处理
119
+ var pasteRecords = onBatchPastePre ? onBatchPastePre(records) : records;
120
+ // 计算结束位置
121
+ var endIndex = startIndex + pasteRecords.length - 1;
122
+ var currentRecords = Array.isArray(dataSourceRef.current)
123
+ ? dataSourceRef.current.slice()
124
+ : [];
125
+ if (endIndex > currentRecords.length - 1) {
126
+ endIndex = currentRecords.length - 1;
127
+ }
128
+ // 从开始位置开始,替换对应的值
129
+ var currentIndex = 0;
130
+ var dataSource = currentRecords.map(function (record, index) {
131
+ if (index >= startIndex && index <= endIndex) {
132
+ var obj = __assign(__assign({}, record), pasteRecords[currentIndex]);
133
+ currentIndex++;
134
+ return obj;
135
+ }
136
+ return record;
137
+ });
138
+ // 后置处理
139
+ var newDataSource = onBatchPastePost
140
+ ? onBatchPastePost(dataSource)
141
+ : dataSource;
142
+ // 触发onChange事件
143
+ onChange && onChange(newDataSource);
144
+ }, [dataSourceRef, onChange, onBatchPastePre, onBatchPastePost]);
145
+ return {
146
+ onEditableSaveHandle: onEditableSaveHandle,
147
+ onBatchPasteHandle: onBatchPasteHandle,
148
+ };
149
+ }
150
+ // SCU刷新逻辑
151
+ // 这么写的原因是 如果拖拽行 增减行后,并不能触发column的scu
152
+ // 之前的写法是,通过useState刷新。但是 setState会触发整个组件的刷新
153
+ // 设置数据后,本身会触发setState。导致执行两次rerender。每个单元格都会执行rerender
154
+ // 通过Ref并不会触发 setState 通过setTimeout也不会导致每一个单元格的刷新出现问题
155
+ export function useScuRfresh() {
156
+ var timeOutRef = useRef(null);
157
+ var tableSCURefreshRef = useRef();
158
+ var refreshScuCell = useCallback(function () {
159
+ tableSCURefreshRef.current = true;
160
+ }, []);
161
+ var getRefreshScuCell = useCallback(function () {
162
+ if (tableSCURefreshRef.current) {
163
+ if (timeOutRef.current) {
164
+ clearTimeout(timeOutRef.current);
165
+ timeOutRef.current = null;
166
+ }
167
+ timeOutRef.current = setTimeout(function () {
168
+ tableSCURefreshRef.current = false;
169
+ });
170
+ return true;
171
+ }
172
+ return false;
173
+ }, []);
174
+ return {
175
+ refreshScuCell: refreshScuCell,
176
+ getRefreshScuCell: getRefreshScuCell,
177
+ };
178
+ }
@@ -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,67 @@
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 'ztxkui';
28
+ import { Table } from '../../../index';
29
+ import { useDataSourceRef, useAddAndDelRow, useScuRfresh, useMoveRow, useEditRow, } from './hooks';
30
+ function ProEditTable(props) {
31
+ 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, isMove = props.isMove, isEdit = props.isEdit, isPaste = props.isPaste, tableHandleRef = props.tableHandleRef, onBatchPastePre = props.onBatchPastePre, onBatchPastePost = props.onBatchPastePost, restProps = __rest(props, ["rowKey", "dataSource", "columns", "onChange", "showAddIcon", "showDelIcon", "addDataMode", "isMove", "isEdit", "isPaste", "tableHandleRef", "onBatchPastePre", "onBatchPastePost"]);
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, 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, {
54
+ onBatchPastePre: onBatchPastePre,
55
+ onBatchPastePost: onBatchPastePost,
56
+ }), onEditableSaveHandle = _d.onEditableSaveHandle, onBatchPasteHandle = _d.onBatchPasteHandle;
57
+ var innerTableHandleRef = useRef();
58
+ useImperativeHandle(tableHandleRef, function () { return ({
59
+ validate: innerTableHandleRef.current.validate,
60
+ clearErrorClass: innerTableHandleRef.current.clearErrorClass,
61
+ getCurrentPage: innerTableHandleRef.current.getCurrentPage,
62
+ getRealyIndex: innerTableHandleRef.current.getRealyIndex,
63
+ onEditableSaveHandle: onEditableSaveHandle,
64
+ }); });
65
+ 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 }, restProps)));
66
+ }
67
+ export default memo(ProEditTable);
@@ -0,0 +1,31 @@
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[]) => void;
9
+ showAddIcon?: boolean;
10
+ showDelIcon?: boolean;
11
+ /**
12
+ * 增加数据的模式 blank add空白数据; copy add复制数据; 自定义增加
13
+ */
14
+ addDataMode?: 'blank' | 'copy' | ((index: number, dataSource: any[]) => any[]);
15
+ isMove?: boolean;
16
+ isEdit?: boolean;
17
+ isPaste?: boolean;
18
+ onBatchPastePre?: (data: any[]) => any[];
19
+ onBatchPastePost?: (data: any[]) => any[];
20
+ tableHandleRef?: React.Ref<{
21
+ validate: () => Promise<any>;
22
+ clearErrorClass: (index: number) => void;
23
+ getCurrentPage: () => {
24
+ page: number;
25
+ pageSize: number;
26
+ } | null;
27
+ getRealyIndex: (index: number) => number;
28
+ onEditableSaveHandle: (record: any, index: number | undefined, _dataIndex: string) => void;
29
+ [prop: string]: any;
30
+ }>;
31
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare const data1: {
2
+ id: string;
3
+ test1: string;
4
+ test2: number;
5
+ }[];
6
+ export declare const data2: {
7
+ id: string;
8
+ test1: string;
9
+ test2: number;
10
+ }[];
@@ -0,0 +1,14 @@
1
+ export var data1 = new Array(50).fill(1).map(function (item, index) {
2
+ return {
3
+ id: "id-" + index,
4
+ test1: "test1-" + index,
5
+ test2: index + 100,
6
+ };
7
+ });
8
+ export var data2 = new Array(50).fill(1).map(function (item, index) {
9
+ return {
10
+ id: "id-" + index,
11
+ test1: "test1-" + index,
12
+ test2: index + 100,
13
+ };
14
+ });
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function TableDemo(): JSX.Element;
@@ -0,0 +1,5 @@
1
+ // 入口文件
2
+ import React from 'react';
3
+ export default function TableDemo() {
4
+ return React.createElement("div", null);
5
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function UIComponent(): JSX.Element;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { Link, Switch, Route } from 'react-router-dom';
3
+ import DefaultTable from './Table/DefaultTable';
4
+ import EditTable from './Table/EditTable';
5
+ export default function UIComponent() {
6
+ return (React.createElement("div", { style: { padding: '10px' } },
7
+ React.createElement(Link, { to: "/ui/default-table", style: { marginRight: '10px' } }, "\u7B80\u5355\u8868\u683C"),
8
+ React.createElement(Link, { to: "/ui/edit-table", style: { marginRight: '10px' } }, "\u53EF\u7F16\u8F91\u8868\u683C"),
9
+ React.createElement(Switch, null,
10
+ React.createElement(Route, { path: "/ui/default-table" },
11
+ React.createElement(DefaultTable, null)),
12
+ React.createElement(Route, { path: "/ui/edit-table" },
13
+ React.createElement(EditTable, null)))));
14
+ }
@@ -24,9 +24,9 @@ import React from 'react';
24
24
  import { Modal as AntModal, Spin } from 'antd';
25
25
  import classNames from 'classnames';
26
26
  function Modal(props) {
27
- var children = props.children, loading = props.loading, className = props.className, restProps = __rest(props, ["children", "loading", "className"]);
27
+ var children = props.children, loading = props.loading, className = props.className, visible = props.visible, open = props.open, restProps = __rest(props, ["children", "loading", "className", "visible", "open"]);
28
28
  var classes = classNames('zt-modal', className, {});
29
- return (React.createElement(AntModal, __assign({ className: classes }, restProps),
29
+ return (React.createElement(AntModal, __assign({ className: classes }, restProps, { open: open || visible }),
30
30
  React.createElement(Spin, { size: "large", spinning: loading }, children)));
31
31
  }
32
32
  Modal.info = AntModal.info;
@@ -79,7 +79,7 @@ function TableDynamic(props) {
79
79
  // getContainer={false}
80
80
  closable: false, maskClosable: false,
81
81
  // style={{ position: 'absolute' }}
82
- visible: visible, className: "zt-table__dynamic", title: React.createElement("div", null,
82
+ open: visible, className: "zt-table__dynamic", title: React.createElement("div", null,
83
83
  React.createElement(SettingOutlined, null),
84
84
  React.createElement("span", { className: "search-drawer--title-text" },
85
85
  "\u663E\u793A\u5B57\u6BB5\u81EA\u5B9A\u4E49",
@@ -83,9 +83,6 @@ export function tableValidate(dataSource, mergeColumns, restParams) {
83
83
  return [2 /*return*/, "break"];
84
84
  }
85
85
  value = item[dataIndex];
86
- if (dataIndex === 'test3') {
87
- console.log(value);
88
- }
89
86
  setElementState = function (i, index, className) {
90
87
  var _a, _b, _c;
91
88
  // 获取表格元素
package/dist/index.js CHANGED
@@ -25,13 +25,17 @@
25
25
  // import TableDemoAll from './TableDemo';
26
26
  // import CodeQueryDemo from './DemoCom/CodeQueryDemo';
27
27
  // import Speed from './speed';
28
+ // import UI from './UI';
28
29
  // dayjs.locale(zhCn);
29
30
  // ReactDOM.render(
30
31
  // // <React.StrictMode>
31
32
  // <ConfigProvider locale={zhCN}>
32
33
  // <BrowserRouter>
33
34
  // <Switch>
34
- // <Route exact path="/">
35
+ // <Route path="/ui">
36
+ // <UI />
37
+ // </Route>
38
+ // <Route exact path="/app">
35
39
  // <App />
36
40
  // </Route>
37
41
  // <Route exact path="/code-query">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "4.3.7",
3
+ "version": "4.3.8",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",