ls-pro-common 3.0.18 → 3.0.19
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/common.css +8 -0
- package/dist/common.js +1 -1
- package/dist/common.min.css +8 -0
- package/dist/common.min.js +1 -1
- package/es/components/InputTable.js +94 -49
- package/es/components/antd-custom.less +1 -0
- package/lib/components/InputTable.js +93 -48
- package/lib/components/antd-custom.less +1 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
6
6
|
import "antd/es/button/style";
|
|
7
7
|
import _Button from "antd/es/button";
|
|
8
8
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
9
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
9
10
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
10
11
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
11
12
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
@@ -18,22 +19,25 @@ import ProTable from 'ls-pro-table';
|
|
|
18
19
|
import { ProFormText, ProFormContext } from 'ls-pro-form';
|
|
19
20
|
import { MoreOutlined } from '@ant-design/icons';
|
|
20
21
|
import { httpGet } from '../http';
|
|
21
|
-
import { showWarn } from '../utils';
|
|
22
|
+
import { isDev, showWarn } from '../utils';
|
|
22
23
|
var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
23
24
|
//@ts-ignore
|
|
24
25
|
var _useContext = useContext(ProFormContext),
|
|
25
26
|
formRef = _useContext.formRef;
|
|
26
|
-
// const inputRef=useRef<any>();
|
|
27
27
|
var tableRef = useRef();
|
|
28
28
|
var selectRowRef = useRef([]);
|
|
29
|
-
var _useState = useState(
|
|
29
|
+
var _useState = useState([]),
|
|
30
30
|
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var _useState3 = useState(
|
|
31
|
+
selectedKeys = _useState2[0],
|
|
32
|
+
setSelectedKeys = _useState2[1];
|
|
33
|
+
var _useState3 = useState(false),
|
|
34
34
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
visible = _useState4[0],
|
|
36
|
+
setVisible = _useState4[1];
|
|
37
|
+
var _useState5 = useState(''),
|
|
38
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
39
|
+
text = _useState6[0],
|
|
40
|
+
setText = _useState6[1];
|
|
37
41
|
var inputRef = useRef();
|
|
38
42
|
useImperativeHandle(ref, function () {
|
|
39
43
|
return inputRef.current;
|
|
@@ -80,7 +84,16 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
80
84
|
arrowPointAtCenter = _prop$arrowPointAtCen === void 0 ? true : _prop$arrowPointAtCen,
|
|
81
85
|
rowKey = prop.rowKey,
|
|
82
86
|
rest = _objectWithoutProperties(prop, _excluded);
|
|
83
|
-
|
|
87
|
+
if (!valueField && isDev) {
|
|
88
|
+
console.error('valueField 属性必须设置');
|
|
89
|
+
}
|
|
90
|
+
if (!url && isDev) {
|
|
91
|
+
console.error('url 属性必须设置');
|
|
92
|
+
}
|
|
93
|
+
if (!name && isDev) {
|
|
94
|
+
console.error('name 属性必须设置');
|
|
95
|
+
}
|
|
96
|
+
var tableKey = (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowKey) || valueField || 'id';
|
|
84
97
|
//显示输入框绑定的name,如果不设置textName,设置为$name__text
|
|
85
98
|
var textNameProp = useMemo(function () {
|
|
86
99
|
return textName || name + '__text';
|
|
@@ -106,7 +119,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
106
119
|
}, [columns, searchField, valueField, textField]);
|
|
107
120
|
var loadData = /*#__PURE__*/function () {
|
|
108
121
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
|
|
109
|
-
var current, pageSize, rest, data, _tableRef$current, _tableRef$current$cle, result, rows;
|
|
122
|
+
var current, pageSize, rest, data, _tableRef$current, _tableRef$current$cle, result, rows, _formRef$current, _formRef$current$getF, val, _selectRowRef$current, arr, pageSelectedRows;
|
|
110
123
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
111
124
|
while (1) switch (_context.prev = _context.next) {
|
|
112
125
|
case 0:
|
|
@@ -141,13 +154,32 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
141
154
|
if (afterLoad) {
|
|
142
155
|
afterLoad(rows);
|
|
143
156
|
}
|
|
144
|
-
//
|
|
157
|
+
// 多选时,找出当前页的默认选中项
|
|
158
|
+
if (multiple) {
|
|
159
|
+
val = formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : (_formRef$current$getF = _formRef$current.getFieldValue) === null || _formRef$current$getF === void 0 ? void 0 : _formRef$current$getF.call(_formRef$current, name);
|
|
160
|
+
if (val) {
|
|
161
|
+
arr = val.split(',');
|
|
162
|
+
pageSelectedRows = rows.filter(function (row) {
|
|
163
|
+
return arr.includes(row[valueField]);
|
|
164
|
+
}); // 过滤 selectRowRef.current 中已存在的行
|
|
165
|
+
pageSelectedRows = pageSelectedRows.filter(function (row) {
|
|
166
|
+
return !selectRowRef.current.some(function (o) {
|
|
167
|
+
return o[valueField] === row[valueField];
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
(_selectRowRef$current = selectRowRef.current).push.apply(_selectRowRef$current, _toConsumableArray(pageSelectedRows));
|
|
171
|
+
selectedKeys.push.apply(selectedKeys, _toConsumableArray(pageSelectedRows.map(function (o) {
|
|
172
|
+
return o[tableKey];
|
|
173
|
+
})));
|
|
174
|
+
setSelectedKeys(Array.from(new Set(selectedKeys)));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
145
177
|
return _context.abrupt("return", {
|
|
146
178
|
data: rows,
|
|
147
179
|
total: Number(result.total || 0),
|
|
148
180
|
success: true
|
|
149
181
|
});
|
|
150
|
-
case
|
|
182
|
+
case 15:
|
|
151
183
|
case "end":
|
|
152
184
|
return _context.stop();
|
|
153
185
|
}
|
|
@@ -164,29 +196,29 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
164
196
|
val = '';
|
|
165
197
|
if (rowKey) {
|
|
166
198
|
try {
|
|
167
|
-
var _formRef$
|
|
168
|
-
var row = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
199
|
+
var _formRef$current2, _formRef$current2$get, _formRef$current2$get2;
|
|
200
|
+
var row = formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : (_formRef$current2$get = _formRef$current2.getFieldsValue) === null || _formRef$current2$get === void 0 ? void 0 : (_formRef$current2$get2 = _formRef$current2$get.call(_formRef$current2)) === null || _formRef$current2$get2 === void 0 ? void 0 : _formRef$current2$get2[rowKey];
|
|
169
201
|
txt = row === null || row === void 0 ? void 0 : row[textNameProp];
|
|
170
202
|
val = row === null || row === void 0 ? void 0 : row[name];
|
|
171
203
|
} catch (_unused) {}
|
|
172
204
|
} else {
|
|
173
|
-
var _formRef$
|
|
174
|
-
txt = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
175
|
-
val = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
205
|
+
var _formRef$current3, _formRef$current3$get, _formRef$current4, _formRef$current4$get;
|
|
206
|
+
txt = formRef === null || formRef === void 0 ? void 0 : (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : (_formRef$current3$get = _formRef$current3.getFieldValue) === null || _formRef$current3$get === void 0 ? void 0 : _formRef$current3$get.call(_formRef$current3, textNameProp);
|
|
207
|
+
val = formRef === null || formRef === void 0 ? void 0 : (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : (_formRef$current4$get = _formRef$current4.getFieldValue) === null || _formRef$current4$get === void 0 ? void 0 : _formRef$current4$get.call(_formRef$current4, name);
|
|
176
208
|
}
|
|
177
209
|
if (txt) {
|
|
178
210
|
setText(txt);
|
|
179
211
|
} else if (val) {
|
|
180
|
-
var _formRef$
|
|
212
|
+
var _formRef$current5, _formRef$current5$set;
|
|
181
213
|
setText(val);
|
|
182
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
214
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : (_formRef$current5$set = _formRef$current5.setFieldsValue) === null || _formRef$current5$set === void 0 ? void 0 : _formRef$current5$set.call(_formRef$current5, _defineProperty({}, textNameProp, val));
|
|
183
215
|
}
|
|
184
216
|
}, 0);
|
|
185
217
|
}, [rowKey]);
|
|
186
218
|
// 处理返回数据
|
|
187
219
|
var handleValue = function handleValue(row) {
|
|
188
|
-
var _formRef$
|
|
189
|
-
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
220
|
+
var _formRef$current6, _formRef$current6$get;
|
|
221
|
+
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : (_formRef$current6$get = _formRef$current6.getFieldsValue) === null || _formRef$current6$get === void 0 ? void 0 : _formRef$current6$get.call(_formRef$current6)) || {};
|
|
190
222
|
if (rowKey) {
|
|
191
223
|
formValue = formValue[rowKey] || {};
|
|
192
224
|
}
|
|
@@ -226,11 +258,11 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
226
258
|
setText(txt);
|
|
227
259
|
setVisible(false);
|
|
228
260
|
if (rowKey) {
|
|
229
|
-
var _formRef$current6, _formRef$current6$set;
|
|
230
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : (_formRef$current6$set = _formRef$current6.setFieldsValue) === null || _formRef$current6$set === void 0 ? void 0 : _formRef$current6$set.call(_formRef$current6, _defineProperty({}, rowKey, formValue));
|
|
231
|
-
} else {
|
|
232
261
|
var _formRef$current7, _formRef$current7$set;
|
|
233
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : (_formRef$current7$set = _formRef$current7.setFieldsValue) === null || _formRef$current7$set === void 0 ? void 0 : _formRef$current7$set.call(_formRef$current7,
|
|
262
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : (_formRef$current7$set = _formRef$current7.setFieldsValue) === null || _formRef$current7$set === void 0 ? void 0 : _formRef$current7$set.call(_formRef$current7, _defineProperty({}, rowKey, formValue));
|
|
263
|
+
} else {
|
|
264
|
+
var _formRef$current8, _formRef$current8$set;
|
|
265
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 ? void 0 : (_formRef$current8$set = _formRef$current8.setFieldsValue) === null || _formRef$current8$set === void 0 ? void 0 : _formRef$current8$set.call(_formRef$current8, _objectSpread({}, formValue));
|
|
234
266
|
}
|
|
235
267
|
onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(row, formRef);
|
|
236
268
|
};
|
|
@@ -261,8 +293,8 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
261
293
|
};
|
|
262
294
|
//直接输入不回车,value 和 text 为同一个值
|
|
263
295
|
var onInput = function onInput(e) {
|
|
264
|
-
var _formRef$
|
|
265
|
-
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
296
|
+
var _formRef$current9, _formRef$current9$get;
|
|
297
|
+
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 ? void 0 : (_formRef$current9$get = _formRef$current9.getFieldsValue) === null || _formRef$current9$get === void 0 ? void 0 : _formRef$current9$get.call(_formRef$current9)) || {};
|
|
266
298
|
if (rowKey) {
|
|
267
299
|
formValue = formValue[rowKey] || {};
|
|
268
300
|
}
|
|
@@ -271,52 +303,55 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
271
303
|
formValue[textNameProp] = val;
|
|
272
304
|
setText(val);
|
|
273
305
|
if (rowKey) {
|
|
274
|
-
var _formRef$current9, _formRef$current9$set;
|
|
275
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 ? void 0 : (_formRef$current9$set = _formRef$current9.setFieldsValue) === null || _formRef$current9$set === void 0 ? void 0 : _formRef$current9$set.call(_formRef$current9, _defineProperty({}, rowKey, formValue));
|
|
276
|
-
} else {
|
|
277
306
|
var _formRef$current10, _formRef$current10$se;
|
|
278
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current10 = formRef.current) === null || _formRef$current10 === void 0 ? void 0 : (_formRef$current10$se = _formRef$current10.setFieldsValue) === null || _formRef$current10$se === void 0 ? void 0 : _formRef$current10$se.call(_formRef$current10,
|
|
307
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current10 = formRef.current) === null || _formRef$current10 === void 0 ? void 0 : (_formRef$current10$se = _formRef$current10.setFieldsValue) === null || _formRef$current10$se === void 0 ? void 0 : _formRef$current10$se.call(_formRef$current10, _defineProperty({}, rowKey, formValue));
|
|
308
|
+
} else {
|
|
309
|
+
var _formRef$current11, _formRef$current11$se;
|
|
310
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current11 = formRef.current) === null || _formRef$current11 === void 0 ? void 0 : (_formRef$current11$se = _formRef$current11.setFieldsValue) === null || _formRef$current11$se === void 0 ? void 0 : _formRef$current11$se.call(_formRef$current11, _objectSpread({}, formValue));
|
|
279
311
|
}
|
|
280
312
|
};
|
|
281
313
|
// 当表单重置或点clear时,处理值
|
|
282
314
|
var clearValue = function clearValue(e) {
|
|
283
315
|
if (!e.target.value) {
|
|
284
|
-
var _formRef$
|
|
316
|
+
var _formRef$current12, _formRef$current12$ge;
|
|
285
317
|
setText('');
|
|
286
|
-
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
318
|
+
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$current12 = formRef.current) === null || _formRef$current12 === void 0 ? void 0 : (_formRef$current12$ge = _formRef$current12.getFieldsValue) === null || _formRef$current12$ge === void 0 ? void 0 : _formRef$current12$ge.call(_formRef$current12)) || {};
|
|
287
319
|
if (rowKey) {
|
|
288
320
|
formValue = formValue[rowKey] || {};
|
|
289
321
|
}
|
|
290
322
|
formValue[name] = '';
|
|
291
323
|
formValue[textNameProp] = '';
|
|
292
324
|
if (rowKey) {
|
|
293
|
-
var _formRef$current12, _formRef$current12$se;
|
|
294
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current12 = formRef.current) === null || _formRef$current12 === void 0 ? void 0 : (_formRef$current12$se = _formRef$current12.setFieldsValue) === null || _formRef$current12$se === void 0 ? void 0 : _formRef$current12$se.call(_formRef$current12, _defineProperty({}, rowKey, formValue));
|
|
295
|
-
} else {
|
|
296
325
|
var _formRef$current13, _formRef$current13$se;
|
|
297
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current13 = formRef.current) === null || _formRef$current13 === void 0 ? void 0 : (_formRef$current13$se = _formRef$current13.setFieldsValue) === null || _formRef$current13$se === void 0 ? void 0 : _formRef$current13$se.call(_formRef$current13,
|
|
326
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current13 = formRef.current) === null || _formRef$current13 === void 0 ? void 0 : (_formRef$current13$se = _formRef$current13.setFieldsValue) === null || _formRef$current13$se === void 0 ? void 0 : _formRef$current13$se.call(_formRef$current13, _defineProperty({}, rowKey, formValue));
|
|
327
|
+
} else {
|
|
328
|
+
var _formRef$current14, _formRef$current14$se;
|
|
329
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current14 = formRef.current) === null || _formRef$current14 === void 0 ? void 0 : (_formRef$current14$se = _formRef$current14.setFieldsValue) === null || _formRef$current14$se === void 0 ? void 0 : _formRef$current14$se.call(_formRef$current14, _objectSpread({}, formValue));
|
|
298
330
|
}
|
|
299
331
|
}
|
|
300
332
|
};
|
|
301
333
|
useEffect(function () {
|
|
302
|
-
if (!text) {
|
|
334
|
+
if (!text && multiple) {
|
|
303
335
|
var _tableRef$current2, _tableRef$current2$cl;
|
|
304
336
|
selectRowRef.current = [];
|
|
305
337
|
(_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : (_tableRef$current2$cl = _tableRef$current2.clearSelected) === null || _tableRef$current2$cl === void 0 ? void 0 : _tableRef$current2$cl.call(_tableRef$current2);
|
|
306
338
|
}
|
|
307
|
-
}, [text]);
|
|
339
|
+
}, [text, multiple]);
|
|
308
340
|
var tableOptions = {};
|
|
309
341
|
if (!multiple) {
|
|
310
342
|
tableOptions.headerTitle = "双击选中当前行数据";
|
|
343
|
+
tableOptions.rowSelection = false;
|
|
344
|
+
} else {
|
|
345
|
+
tableOptions.rowSelection = {
|
|
346
|
+
type: 'checkbox',
|
|
347
|
+
selectedRowKeys: selectedKeys,
|
|
348
|
+
preserveSelectedRowKeys: keepSelect,
|
|
349
|
+
onChange: function onChange(keys, rows) {
|
|
350
|
+
selectRowRef.current = rows;
|
|
351
|
+
setSelectedKeys(keys);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
311
354
|
}
|
|
312
|
-
var rowSelection = tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowSelection;
|
|
313
|
-
rowSelection = rowSelection == undefined || multiple ? {
|
|
314
|
-
type: 'checkbox',
|
|
315
|
-
onChange: function onChange(keys, rows) {
|
|
316
|
-
// console.log(keys, rows, tableRef?.current?.getDatasource());
|
|
317
|
-
selectRowRef.current = rows;
|
|
318
|
-
}
|
|
319
|
-
} : false;
|
|
320
355
|
var tableDom = /*#__PURE__*/React.createElement(ProTable, _extends({
|
|
321
356
|
className: "ls-input-table",
|
|
322
357
|
columns: columns,
|
|
@@ -336,7 +371,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
336
371
|
btnInline: true
|
|
337
372
|
},
|
|
338
373
|
height: 'full',
|
|
339
|
-
|
|
374
|
+
rowKey: tableKey,
|
|
340
375
|
onRow: function onRow(record) {
|
|
341
376
|
return {
|
|
342
377
|
onDoubleClick: function onDoubleClick() {
|
|
@@ -347,7 +382,17 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
347
382
|
};
|
|
348
383
|
},
|
|
349
384
|
toolBarRender: function toolBarRender() {
|
|
350
|
-
return multiple ? [
|
|
385
|
+
return multiple ? [
|
|
386
|
+
/*#__PURE__*/
|
|
387
|
+
// <Button
|
|
388
|
+
// className='ant-btn-gray'
|
|
389
|
+
// key="btnClear"
|
|
390
|
+
// onClick={() => {
|
|
391
|
+
// tableRef.current?.clearSelected?.();
|
|
392
|
+
// handleValue({});
|
|
393
|
+
// }}>清空</Button>,
|
|
394
|
+
React.createElement(_Button, {
|
|
395
|
+
key: "btnConfirm",
|
|
351
396
|
onClick: function onClick() {
|
|
352
397
|
handleValue(selectRowRef.current || []);
|
|
353
398
|
}
|
|
@@ -15,6 +15,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
15
15
|
require("antd/es/button/style");
|
|
16
16
|
var _button = _interopRequireDefault(require("antd/es/button"));
|
|
17
17
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
19
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
19
20
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
20
21
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
@@ -31,17 +32,20 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
31
32
|
//@ts-ignore
|
|
32
33
|
var _useContext = (0, _react.useContext)(_lsProForm.ProFormContext),
|
|
33
34
|
formRef = _useContext.formRef;
|
|
34
|
-
// const inputRef=useRef<any>();
|
|
35
35
|
var tableRef = (0, _react.useRef)();
|
|
36
36
|
var selectRowRef = (0, _react.useRef)([]);
|
|
37
|
-
var _useState = (0, _react.useState)(
|
|
37
|
+
var _useState = (0, _react.useState)([]),
|
|
38
38
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var _useState3 = (0, _react.useState)(
|
|
39
|
+
selectedKeys = _useState2[0],
|
|
40
|
+
setSelectedKeys = _useState2[1];
|
|
41
|
+
var _useState3 = (0, _react.useState)(false),
|
|
42
42
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
visible = _useState4[0],
|
|
44
|
+
setVisible = _useState4[1];
|
|
45
|
+
var _useState5 = (0, _react.useState)(''),
|
|
46
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
47
|
+
text = _useState6[0],
|
|
48
|
+
setText = _useState6[1];
|
|
45
49
|
var inputRef = (0, _react.useRef)();
|
|
46
50
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
47
51
|
return inputRef.current;
|
|
@@ -88,7 +92,16 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
88
92
|
arrowPointAtCenter = _prop$arrowPointAtCen === void 0 ? true : _prop$arrowPointAtCen,
|
|
89
93
|
rowKey = prop.rowKey,
|
|
90
94
|
rest = (0, _objectWithoutProperties2.default)(prop, _excluded);
|
|
91
|
-
|
|
95
|
+
if (!valueField && _utils.isDev) {
|
|
96
|
+
console.error('valueField 属性必须设置');
|
|
97
|
+
}
|
|
98
|
+
if (!url && _utils.isDev) {
|
|
99
|
+
console.error('url 属性必须设置');
|
|
100
|
+
}
|
|
101
|
+
if (!name && _utils.isDev) {
|
|
102
|
+
console.error('name 属性必须设置');
|
|
103
|
+
}
|
|
104
|
+
var tableKey = (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowKey) || valueField || 'id';
|
|
92
105
|
//显示输入框绑定的name,如果不设置textName,设置为$name__text
|
|
93
106
|
var textNameProp = (0, _react.useMemo)(function () {
|
|
94
107
|
return textName || name + '__text';
|
|
@@ -114,7 +127,7 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
114
127
|
}, [columns, searchField, valueField, textField]);
|
|
115
128
|
var loadData = /*#__PURE__*/function () {
|
|
116
129
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(param) {
|
|
117
|
-
var current, pageSize, rest, data, _tableRef$current, _tableRef$current$cle, result, rows;
|
|
130
|
+
var current, pageSize, rest, data, _tableRef$current, _tableRef$current$cle, result, rows, _formRef$current, _formRef$current$getF, val, _selectRowRef$current, arr, pageSelectedRows;
|
|
118
131
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
119
132
|
while (1) switch (_context.prev = _context.next) {
|
|
120
133
|
case 0:
|
|
@@ -149,13 +162,32 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
149
162
|
if (afterLoad) {
|
|
150
163
|
afterLoad(rows);
|
|
151
164
|
}
|
|
152
|
-
//
|
|
165
|
+
// 多选时,找出当前页的默认选中项
|
|
166
|
+
if (multiple) {
|
|
167
|
+
val = formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : (_formRef$current$getF = _formRef$current.getFieldValue) === null || _formRef$current$getF === void 0 ? void 0 : _formRef$current$getF.call(_formRef$current, name);
|
|
168
|
+
if (val) {
|
|
169
|
+
arr = val.split(',');
|
|
170
|
+
pageSelectedRows = rows.filter(function (row) {
|
|
171
|
+
return arr.includes(row[valueField]);
|
|
172
|
+
}); // 过滤 selectRowRef.current 中已存在的行
|
|
173
|
+
pageSelectedRows = pageSelectedRows.filter(function (row) {
|
|
174
|
+
return !selectRowRef.current.some(function (o) {
|
|
175
|
+
return o[valueField] === row[valueField];
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
(_selectRowRef$current = selectRowRef.current).push.apply(_selectRowRef$current, (0, _toConsumableArray2.default)(pageSelectedRows));
|
|
179
|
+
selectedKeys.push.apply(selectedKeys, (0, _toConsumableArray2.default)(pageSelectedRows.map(function (o) {
|
|
180
|
+
return o[tableKey];
|
|
181
|
+
})));
|
|
182
|
+
setSelectedKeys(Array.from(new Set(selectedKeys)));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
153
185
|
return _context.abrupt("return", {
|
|
154
186
|
data: rows,
|
|
155
187
|
total: Number(result.total || 0),
|
|
156
188
|
success: true
|
|
157
189
|
});
|
|
158
|
-
case
|
|
190
|
+
case 15:
|
|
159
191
|
case "end":
|
|
160
192
|
return _context.stop();
|
|
161
193
|
}
|
|
@@ -172,29 +204,29 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
172
204
|
val = '';
|
|
173
205
|
if (rowKey) {
|
|
174
206
|
try {
|
|
175
|
-
var _formRef$
|
|
176
|
-
var row = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
207
|
+
var _formRef$current2, _formRef$current2$get, _formRef$current2$get2;
|
|
208
|
+
var row = formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : (_formRef$current2$get = _formRef$current2.getFieldsValue) === null || _formRef$current2$get === void 0 ? void 0 : (_formRef$current2$get2 = _formRef$current2$get.call(_formRef$current2)) === null || _formRef$current2$get2 === void 0 ? void 0 : _formRef$current2$get2[rowKey];
|
|
177
209
|
txt = row === null || row === void 0 ? void 0 : row[textNameProp];
|
|
178
210
|
val = row === null || row === void 0 ? void 0 : row[name];
|
|
179
211
|
} catch (_unused) {}
|
|
180
212
|
} else {
|
|
181
|
-
var _formRef$
|
|
182
|
-
txt = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
183
|
-
val = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
213
|
+
var _formRef$current3, _formRef$current3$get, _formRef$current4, _formRef$current4$get;
|
|
214
|
+
txt = formRef === null || formRef === void 0 ? void 0 : (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : (_formRef$current3$get = _formRef$current3.getFieldValue) === null || _formRef$current3$get === void 0 ? void 0 : _formRef$current3$get.call(_formRef$current3, textNameProp);
|
|
215
|
+
val = formRef === null || formRef === void 0 ? void 0 : (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : (_formRef$current4$get = _formRef$current4.getFieldValue) === null || _formRef$current4$get === void 0 ? void 0 : _formRef$current4$get.call(_formRef$current4, name);
|
|
184
216
|
}
|
|
185
217
|
if (txt) {
|
|
186
218
|
setText(txt);
|
|
187
219
|
} else if (val) {
|
|
188
|
-
var _formRef$
|
|
220
|
+
var _formRef$current5, _formRef$current5$set;
|
|
189
221
|
setText(val);
|
|
190
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
222
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : (_formRef$current5$set = _formRef$current5.setFieldsValue) === null || _formRef$current5$set === void 0 ? void 0 : _formRef$current5$set.call(_formRef$current5, (0, _defineProperty2.default)({}, textNameProp, val));
|
|
191
223
|
}
|
|
192
224
|
}, 0);
|
|
193
225
|
}, [rowKey]);
|
|
194
226
|
// 处理返回数据
|
|
195
227
|
var handleValue = function handleValue(row) {
|
|
196
|
-
var _formRef$
|
|
197
|
-
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
228
|
+
var _formRef$current6, _formRef$current6$get;
|
|
229
|
+
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : (_formRef$current6$get = _formRef$current6.getFieldsValue) === null || _formRef$current6$get === void 0 ? void 0 : _formRef$current6$get.call(_formRef$current6)) || {};
|
|
198
230
|
if (rowKey) {
|
|
199
231
|
formValue = formValue[rowKey] || {};
|
|
200
232
|
}
|
|
@@ -234,11 +266,11 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
234
266
|
setText(txt);
|
|
235
267
|
setVisible(false);
|
|
236
268
|
if (rowKey) {
|
|
237
|
-
var _formRef$current6, _formRef$current6$set;
|
|
238
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : (_formRef$current6$set = _formRef$current6.setFieldsValue) === null || _formRef$current6$set === void 0 ? void 0 : _formRef$current6$set.call(_formRef$current6, (0, _defineProperty2.default)({}, rowKey, formValue));
|
|
239
|
-
} else {
|
|
240
269
|
var _formRef$current7, _formRef$current7$set;
|
|
241
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : (_formRef$current7$set = _formRef$current7.setFieldsValue) === null || _formRef$current7$set === void 0 ? void 0 : _formRef$current7$set.call(_formRef$current7, (0,
|
|
270
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : (_formRef$current7$set = _formRef$current7.setFieldsValue) === null || _formRef$current7$set === void 0 ? void 0 : _formRef$current7$set.call(_formRef$current7, (0, _defineProperty2.default)({}, rowKey, formValue));
|
|
271
|
+
} else {
|
|
272
|
+
var _formRef$current8, _formRef$current8$set;
|
|
273
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 ? void 0 : (_formRef$current8$set = _formRef$current8.setFieldsValue) === null || _formRef$current8$set === void 0 ? void 0 : _formRef$current8$set.call(_formRef$current8, (0, _objectSpread2.default)({}, formValue));
|
|
242
274
|
}
|
|
243
275
|
onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(row, formRef);
|
|
244
276
|
};
|
|
@@ -269,8 +301,8 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
269
301
|
};
|
|
270
302
|
//直接输入不回车,value 和 text 为同一个值
|
|
271
303
|
var onInput = function onInput(e) {
|
|
272
|
-
var _formRef$
|
|
273
|
-
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
304
|
+
var _formRef$current9, _formRef$current9$get;
|
|
305
|
+
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 ? void 0 : (_formRef$current9$get = _formRef$current9.getFieldsValue) === null || _formRef$current9$get === void 0 ? void 0 : _formRef$current9$get.call(_formRef$current9)) || {};
|
|
274
306
|
if (rowKey) {
|
|
275
307
|
formValue = formValue[rowKey] || {};
|
|
276
308
|
}
|
|
@@ -279,52 +311,55 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
279
311
|
formValue[textNameProp] = val;
|
|
280
312
|
setText(val);
|
|
281
313
|
if (rowKey) {
|
|
282
|
-
var _formRef$current9, _formRef$current9$set;
|
|
283
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 ? void 0 : (_formRef$current9$set = _formRef$current9.setFieldsValue) === null || _formRef$current9$set === void 0 ? void 0 : _formRef$current9$set.call(_formRef$current9, (0, _defineProperty2.default)({}, rowKey, formValue));
|
|
284
|
-
} else {
|
|
285
314
|
var _formRef$current10, _formRef$current10$se;
|
|
286
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current10 = formRef.current) === null || _formRef$current10 === void 0 ? void 0 : (_formRef$current10$se = _formRef$current10.setFieldsValue) === null || _formRef$current10$se === void 0 ? void 0 : _formRef$current10$se.call(_formRef$current10, (0,
|
|
315
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current10 = formRef.current) === null || _formRef$current10 === void 0 ? void 0 : (_formRef$current10$se = _formRef$current10.setFieldsValue) === null || _formRef$current10$se === void 0 ? void 0 : _formRef$current10$se.call(_formRef$current10, (0, _defineProperty2.default)({}, rowKey, formValue));
|
|
316
|
+
} else {
|
|
317
|
+
var _formRef$current11, _formRef$current11$se;
|
|
318
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current11 = formRef.current) === null || _formRef$current11 === void 0 ? void 0 : (_formRef$current11$se = _formRef$current11.setFieldsValue) === null || _formRef$current11$se === void 0 ? void 0 : _formRef$current11$se.call(_formRef$current11, (0, _objectSpread2.default)({}, formValue));
|
|
287
319
|
}
|
|
288
320
|
};
|
|
289
321
|
// 当表单重置或点clear时,处理值
|
|
290
322
|
var clearValue = function clearValue(e) {
|
|
291
323
|
if (!e.target.value) {
|
|
292
|
-
var _formRef$
|
|
324
|
+
var _formRef$current12, _formRef$current12$ge;
|
|
293
325
|
setText('');
|
|
294
|
-
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
326
|
+
var formValue = (formRef === null || formRef === void 0 ? void 0 : (_formRef$current12 = formRef.current) === null || _formRef$current12 === void 0 ? void 0 : (_formRef$current12$ge = _formRef$current12.getFieldsValue) === null || _formRef$current12$ge === void 0 ? void 0 : _formRef$current12$ge.call(_formRef$current12)) || {};
|
|
295
327
|
if (rowKey) {
|
|
296
328
|
formValue = formValue[rowKey] || {};
|
|
297
329
|
}
|
|
298
330
|
formValue[name] = '';
|
|
299
331
|
formValue[textNameProp] = '';
|
|
300
332
|
if (rowKey) {
|
|
301
|
-
var _formRef$current12, _formRef$current12$se;
|
|
302
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current12 = formRef.current) === null || _formRef$current12 === void 0 ? void 0 : (_formRef$current12$se = _formRef$current12.setFieldsValue) === null || _formRef$current12$se === void 0 ? void 0 : _formRef$current12$se.call(_formRef$current12, (0, _defineProperty2.default)({}, rowKey, formValue));
|
|
303
|
-
} else {
|
|
304
333
|
var _formRef$current13, _formRef$current13$se;
|
|
305
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$current13 = formRef.current) === null || _formRef$current13 === void 0 ? void 0 : (_formRef$current13$se = _formRef$current13.setFieldsValue) === null || _formRef$current13$se === void 0 ? void 0 : _formRef$current13$se.call(_formRef$current13, (0,
|
|
334
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current13 = formRef.current) === null || _formRef$current13 === void 0 ? void 0 : (_formRef$current13$se = _formRef$current13.setFieldsValue) === null || _formRef$current13$se === void 0 ? void 0 : _formRef$current13$se.call(_formRef$current13, (0, _defineProperty2.default)({}, rowKey, formValue));
|
|
335
|
+
} else {
|
|
336
|
+
var _formRef$current14, _formRef$current14$se;
|
|
337
|
+
formRef === null || formRef === void 0 ? void 0 : (_formRef$current14 = formRef.current) === null || _formRef$current14 === void 0 ? void 0 : (_formRef$current14$se = _formRef$current14.setFieldsValue) === null || _formRef$current14$se === void 0 ? void 0 : _formRef$current14$se.call(_formRef$current14, (0, _objectSpread2.default)({}, formValue));
|
|
306
338
|
}
|
|
307
339
|
}
|
|
308
340
|
};
|
|
309
341
|
(0, _react.useEffect)(function () {
|
|
310
|
-
if (!text) {
|
|
342
|
+
if (!text && multiple) {
|
|
311
343
|
var _tableRef$current2, _tableRef$current2$cl;
|
|
312
344
|
selectRowRef.current = [];
|
|
313
345
|
(_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : (_tableRef$current2$cl = _tableRef$current2.clearSelected) === null || _tableRef$current2$cl === void 0 ? void 0 : _tableRef$current2$cl.call(_tableRef$current2);
|
|
314
346
|
}
|
|
315
|
-
}, [text]);
|
|
347
|
+
}, [text, multiple]);
|
|
316
348
|
var tableOptions = {};
|
|
317
349
|
if (!multiple) {
|
|
318
350
|
tableOptions.headerTitle = "双击选中当前行数据";
|
|
351
|
+
tableOptions.rowSelection = false;
|
|
352
|
+
} else {
|
|
353
|
+
tableOptions.rowSelection = {
|
|
354
|
+
type: 'checkbox',
|
|
355
|
+
selectedRowKeys: selectedKeys,
|
|
356
|
+
preserveSelectedRowKeys: keepSelect,
|
|
357
|
+
onChange: function onChange(keys, rows) {
|
|
358
|
+
selectRowRef.current = rows;
|
|
359
|
+
setSelectedKeys(keys);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
319
362
|
}
|
|
320
|
-
var rowSelection = tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowSelection;
|
|
321
|
-
rowSelection = rowSelection == undefined || multiple ? {
|
|
322
|
-
type: 'checkbox',
|
|
323
|
-
onChange: function onChange(keys, rows) {
|
|
324
|
-
// console.log(keys, rows, tableRef?.current?.getDatasource());
|
|
325
|
-
selectRowRef.current = rows;
|
|
326
|
-
}
|
|
327
|
-
} : false;
|
|
328
363
|
var tableDom = /*#__PURE__*/_react.default.createElement(_lsProTable.default, (0, _extends2.default)({
|
|
329
364
|
className: "ls-input-table",
|
|
330
365
|
columns: columns,
|
|
@@ -344,7 +379,7 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
344
379
|
btnInline: true
|
|
345
380
|
},
|
|
346
381
|
height: 'full',
|
|
347
|
-
|
|
382
|
+
rowKey: tableKey,
|
|
348
383
|
onRow: function onRow(record) {
|
|
349
384
|
return {
|
|
350
385
|
onDoubleClick: function onDoubleClick() {
|
|
@@ -355,7 +390,17 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
355
390
|
};
|
|
356
391
|
},
|
|
357
392
|
toolBarRender: function toolBarRender() {
|
|
358
|
-
return multiple ? [
|
|
393
|
+
return multiple ? [
|
|
394
|
+
/*#__PURE__*/
|
|
395
|
+
// <Button
|
|
396
|
+
// className='ant-btn-gray'
|
|
397
|
+
// key="btnClear"
|
|
398
|
+
// onClick={() => {
|
|
399
|
+
// tableRef.current?.clearSelected?.();
|
|
400
|
+
// handleValue({});
|
|
401
|
+
// }}>清空</Button>,
|
|
402
|
+
_react.default.createElement(_button.default, {
|
|
403
|
+
key: "btnConfirm",
|
|
359
404
|
onClick: function onClick() {
|
|
360
405
|
handleValue(selectRowRef.current || []);
|
|
361
406
|
}
|