ls-pro-common 3.0.17 → 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 -41
- package/es/components/antd-custom.less +1 -0
- package/lib/components/InputTable.js +93 -40
- package/lib/components/antd-custom.less +1 -0
- package/package.json +2 -2
|
@@ -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,21 +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
27
|
var tableRef = useRef();
|
|
27
28
|
var selectRowRef = useRef([]);
|
|
28
|
-
var _useState = useState(
|
|
29
|
+
var _useState = useState([]),
|
|
29
30
|
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var _useState3 = useState(
|
|
31
|
+
selectedKeys = _useState2[0],
|
|
32
|
+
setSelectedKeys = _useState2[1];
|
|
33
|
+
var _useState3 = useState(false),
|
|
33
34
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
-
|
|
35
|
-
|
|
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];
|
|
36
41
|
var inputRef = useRef();
|
|
37
42
|
useImperativeHandle(ref, function () {
|
|
38
43
|
return inputRef.current;
|
|
@@ -79,6 +84,16 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
79
84
|
arrowPointAtCenter = _prop$arrowPointAtCen === void 0 ? true : _prop$arrowPointAtCen,
|
|
80
85
|
rowKey = prop.rowKey,
|
|
81
86
|
rest = _objectWithoutProperties(prop, _excluded);
|
|
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';
|
|
82
97
|
//显示输入框绑定的name,如果不设置textName,设置为$name__text
|
|
83
98
|
var textNameProp = useMemo(function () {
|
|
84
99
|
return textName || name + '__text';
|
|
@@ -104,7 +119,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
104
119
|
}, [columns, searchField, valueField, textField]);
|
|
105
120
|
var loadData = /*#__PURE__*/function () {
|
|
106
121
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
|
|
107
|
-
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;
|
|
108
123
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
109
124
|
while (1) switch (_context.prev = _context.next) {
|
|
110
125
|
case 0:
|
|
@@ -139,12 +154,32 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
139
154
|
if (afterLoad) {
|
|
140
155
|
afterLoad(rows);
|
|
141
156
|
}
|
|
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
|
+
}
|
|
142
177
|
return _context.abrupt("return", {
|
|
143
178
|
data: rows,
|
|
144
179
|
total: Number(result.total || 0),
|
|
145
180
|
success: true
|
|
146
181
|
});
|
|
147
|
-
case
|
|
182
|
+
case 15:
|
|
148
183
|
case "end":
|
|
149
184
|
return _context.stop();
|
|
150
185
|
}
|
|
@@ -161,27 +196,29 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
161
196
|
val = '';
|
|
162
197
|
if (rowKey) {
|
|
163
198
|
try {
|
|
164
|
-
var _formRef$
|
|
165
|
-
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];
|
|
166
201
|
txt = row === null || row === void 0 ? void 0 : row[textNameProp];
|
|
167
202
|
val = row === null || row === void 0 ? void 0 : row[name];
|
|
168
203
|
} catch (_unused) {}
|
|
169
204
|
} else {
|
|
170
|
-
var _formRef$
|
|
171
|
-
txt = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
172
|
-
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);
|
|
173
208
|
}
|
|
174
209
|
if (txt) {
|
|
175
210
|
setText(txt);
|
|
176
211
|
} else if (val) {
|
|
212
|
+
var _formRef$current5, _formRef$current5$set;
|
|
177
213
|
setText(val);
|
|
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));
|
|
178
215
|
}
|
|
179
216
|
}, 0);
|
|
180
217
|
}, [rowKey]);
|
|
181
218
|
// 处理返回数据
|
|
182
219
|
var handleValue = function handleValue(row) {
|
|
183
|
-
var _formRef$
|
|
184
|
-
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)) || {};
|
|
185
222
|
if (rowKey) {
|
|
186
223
|
formValue = formValue[rowKey] || {};
|
|
187
224
|
}
|
|
@@ -221,11 +258,11 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
221
258
|
setText(txt);
|
|
222
259
|
setVisible(false);
|
|
223
260
|
if (rowKey) {
|
|
224
|
-
var _formRef$
|
|
225
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
261
|
+
var _formRef$current7, _formRef$current7$set;
|
|
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));
|
|
226
263
|
} else {
|
|
227
|
-
var _formRef$
|
|
228
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
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));
|
|
229
266
|
}
|
|
230
267
|
onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(row, formRef);
|
|
231
268
|
};
|
|
@@ -256,8 +293,8 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
256
293
|
};
|
|
257
294
|
//直接输入不回车,value 和 text 为同一个值
|
|
258
295
|
var onInput = function onInput(e) {
|
|
259
|
-
var _formRef$
|
|
260
|
-
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)) || {};
|
|
261
298
|
if (rowKey) {
|
|
262
299
|
formValue = formValue[rowKey] || {};
|
|
263
300
|
}
|
|
@@ -266,43 +303,54 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
266
303
|
formValue[textNameProp] = val;
|
|
267
304
|
setText(val);
|
|
268
305
|
if (rowKey) {
|
|
269
|
-
var _formRef$
|
|
270
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
306
|
+
var _formRef$current10, _formRef$current10$se;
|
|
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));
|
|
271
308
|
} else {
|
|
272
|
-
var _formRef$
|
|
273
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
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));
|
|
274
311
|
}
|
|
275
312
|
};
|
|
276
313
|
// 当表单重置或点clear时,处理值
|
|
277
314
|
var clearValue = function clearValue(e) {
|
|
278
315
|
if (!e.target.value) {
|
|
279
|
-
var _formRef$
|
|
316
|
+
var _formRef$current12, _formRef$current12$ge;
|
|
280
317
|
setText('');
|
|
281
|
-
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)) || {};
|
|
282
319
|
if (rowKey) {
|
|
283
320
|
formValue = formValue[rowKey] || {};
|
|
284
321
|
}
|
|
285
322
|
formValue[name] = '';
|
|
286
323
|
formValue[textNameProp] = '';
|
|
287
324
|
if (rowKey) {
|
|
288
|
-
var _formRef$
|
|
289
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
325
|
+
var _formRef$current13, _formRef$current13$se;
|
|
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));
|
|
290
327
|
} else {
|
|
291
|
-
var _formRef$
|
|
292
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
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));
|
|
293
330
|
}
|
|
294
331
|
}
|
|
295
332
|
};
|
|
296
333
|
useEffect(function () {
|
|
297
|
-
if (!text) {
|
|
334
|
+
if (!text && multiple) {
|
|
298
335
|
var _tableRef$current2, _tableRef$current2$cl;
|
|
299
336
|
selectRowRef.current = [];
|
|
300
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);
|
|
301
338
|
}
|
|
302
|
-
}, [text]);
|
|
339
|
+
}, [text, multiple]);
|
|
303
340
|
var tableOptions = {};
|
|
304
341
|
if (!multiple) {
|
|
305
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
|
+
};
|
|
306
354
|
}
|
|
307
355
|
var tableDom = /*#__PURE__*/React.createElement(ProTable, _extends({
|
|
308
356
|
className: "ls-input-table",
|
|
@@ -323,12 +371,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
323
371
|
btnInline: true
|
|
324
372
|
},
|
|
325
373
|
height: 'full',
|
|
326
|
-
|
|
327
|
-
type: multiple ? 'checkbox' : 'radio',
|
|
328
|
-
onChange: function onChange(keys, rows) {
|
|
329
|
-
selectRowRef.current = rows;
|
|
330
|
-
}
|
|
331
|
-
},
|
|
374
|
+
rowKey: tableKey,
|
|
332
375
|
onRow: function onRow(record) {
|
|
333
376
|
return {
|
|
334
377
|
onDoubleClick: function onDoubleClick() {
|
|
@@ -339,7 +382,17 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
|
|
|
339
382
|
};
|
|
340
383
|
},
|
|
341
384
|
toolBarRender: function toolBarRender() {
|
|
342
|
-
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",
|
|
343
396
|
onClick: function onClick() {
|
|
344
397
|
handleValue(selectRowRef.current || []);
|
|
345
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"));
|
|
@@ -33,14 +34,18 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
33
34
|
formRef = _useContext.formRef;
|
|
34
35
|
var tableRef = (0, _react.useRef)();
|
|
35
36
|
var selectRowRef = (0, _react.useRef)([]);
|
|
36
|
-
var _useState = (0, _react.useState)(
|
|
37
|
+
var _useState = (0, _react.useState)([]),
|
|
37
38
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var _useState3 = (0, _react.useState)(
|
|
39
|
+
selectedKeys = _useState2[0],
|
|
40
|
+
setSelectedKeys = _useState2[1];
|
|
41
|
+
var _useState3 = (0, _react.useState)(false),
|
|
41
42
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
42
|
-
|
|
43
|
-
|
|
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];
|
|
44
49
|
var inputRef = (0, _react.useRef)();
|
|
45
50
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
46
51
|
return inputRef.current;
|
|
@@ -87,6 +92,16 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
87
92
|
arrowPointAtCenter = _prop$arrowPointAtCen === void 0 ? true : _prop$arrowPointAtCen,
|
|
88
93
|
rowKey = prop.rowKey,
|
|
89
94
|
rest = (0, _objectWithoutProperties2.default)(prop, _excluded);
|
|
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';
|
|
90
105
|
//显示输入框绑定的name,如果不设置textName,设置为$name__text
|
|
91
106
|
var textNameProp = (0, _react.useMemo)(function () {
|
|
92
107
|
return textName || name + '__text';
|
|
@@ -112,7 +127,7 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
112
127
|
}, [columns, searchField, valueField, textField]);
|
|
113
128
|
var loadData = /*#__PURE__*/function () {
|
|
114
129
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(param) {
|
|
115
|
-
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;
|
|
116
131
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
117
132
|
while (1) switch (_context.prev = _context.next) {
|
|
118
133
|
case 0:
|
|
@@ -147,12 +162,32 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
147
162
|
if (afterLoad) {
|
|
148
163
|
afterLoad(rows);
|
|
149
164
|
}
|
|
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
|
+
}
|
|
150
185
|
return _context.abrupt("return", {
|
|
151
186
|
data: rows,
|
|
152
187
|
total: Number(result.total || 0),
|
|
153
188
|
success: true
|
|
154
189
|
});
|
|
155
|
-
case
|
|
190
|
+
case 15:
|
|
156
191
|
case "end":
|
|
157
192
|
return _context.stop();
|
|
158
193
|
}
|
|
@@ -169,27 +204,29 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
169
204
|
val = '';
|
|
170
205
|
if (rowKey) {
|
|
171
206
|
try {
|
|
172
|
-
var _formRef$
|
|
173
|
-
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];
|
|
174
209
|
txt = row === null || row === void 0 ? void 0 : row[textNameProp];
|
|
175
210
|
val = row === null || row === void 0 ? void 0 : row[name];
|
|
176
211
|
} catch (_unused) {}
|
|
177
212
|
} else {
|
|
178
|
-
var _formRef$
|
|
179
|
-
txt = formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
180
|
-
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);
|
|
181
216
|
}
|
|
182
217
|
if (txt) {
|
|
183
218
|
setText(txt);
|
|
184
219
|
} else if (val) {
|
|
220
|
+
var _formRef$current5, _formRef$current5$set;
|
|
185
221
|
setText(val);
|
|
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));
|
|
186
223
|
}
|
|
187
224
|
}, 0);
|
|
188
225
|
}, [rowKey]);
|
|
189
226
|
// 处理返回数据
|
|
190
227
|
var handleValue = function handleValue(row) {
|
|
191
|
-
var _formRef$
|
|
192
|
-
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)) || {};
|
|
193
230
|
if (rowKey) {
|
|
194
231
|
formValue = formValue[rowKey] || {};
|
|
195
232
|
}
|
|
@@ -229,11 +266,11 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
229
266
|
setText(txt);
|
|
230
267
|
setVisible(false);
|
|
231
268
|
if (rowKey) {
|
|
232
|
-
var _formRef$
|
|
233
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
269
|
+
var _formRef$current7, _formRef$current7$set;
|
|
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));
|
|
234
271
|
} else {
|
|
235
|
-
var _formRef$
|
|
236
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
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));
|
|
237
274
|
}
|
|
238
275
|
onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(row, formRef);
|
|
239
276
|
};
|
|
@@ -264,8 +301,8 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
264
301
|
};
|
|
265
302
|
//直接输入不回车,value 和 text 为同一个值
|
|
266
303
|
var onInput = function onInput(e) {
|
|
267
|
-
var _formRef$
|
|
268
|
-
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)) || {};
|
|
269
306
|
if (rowKey) {
|
|
270
307
|
formValue = formValue[rowKey] || {};
|
|
271
308
|
}
|
|
@@ -274,43 +311,54 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
274
311
|
formValue[textNameProp] = val;
|
|
275
312
|
setText(val);
|
|
276
313
|
if (rowKey) {
|
|
277
|
-
var _formRef$
|
|
278
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
314
|
+
var _formRef$current10, _formRef$current10$se;
|
|
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));
|
|
279
316
|
} else {
|
|
280
|
-
var _formRef$
|
|
281
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
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));
|
|
282
319
|
}
|
|
283
320
|
};
|
|
284
321
|
// 当表单重置或点clear时,处理值
|
|
285
322
|
var clearValue = function clearValue(e) {
|
|
286
323
|
if (!e.target.value) {
|
|
287
|
-
var _formRef$
|
|
324
|
+
var _formRef$current12, _formRef$current12$ge;
|
|
288
325
|
setText('');
|
|
289
|
-
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)) || {};
|
|
290
327
|
if (rowKey) {
|
|
291
328
|
formValue = formValue[rowKey] || {};
|
|
292
329
|
}
|
|
293
330
|
formValue[name] = '';
|
|
294
331
|
formValue[textNameProp] = '';
|
|
295
332
|
if (rowKey) {
|
|
296
|
-
var _formRef$
|
|
297
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
333
|
+
var _formRef$current13, _formRef$current13$se;
|
|
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));
|
|
298
335
|
} else {
|
|
299
|
-
var _formRef$
|
|
300
|
-
formRef === null || formRef === void 0 ? void 0 : (_formRef$
|
|
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));
|
|
301
338
|
}
|
|
302
339
|
}
|
|
303
340
|
};
|
|
304
341
|
(0, _react.useEffect)(function () {
|
|
305
|
-
if (!text) {
|
|
342
|
+
if (!text && multiple) {
|
|
306
343
|
var _tableRef$current2, _tableRef$current2$cl;
|
|
307
344
|
selectRowRef.current = [];
|
|
308
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);
|
|
309
346
|
}
|
|
310
|
-
}, [text]);
|
|
347
|
+
}, [text, multiple]);
|
|
311
348
|
var tableOptions = {};
|
|
312
349
|
if (!multiple) {
|
|
313
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
|
+
};
|
|
314
362
|
}
|
|
315
363
|
var tableDom = /*#__PURE__*/_react.default.createElement(_lsProTable.default, (0, _extends2.default)({
|
|
316
364
|
className: "ls-input-table",
|
|
@@ -331,12 +379,7 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
331
379
|
btnInline: true
|
|
332
380
|
},
|
|
333
381
|
height: 'full',
|
|
334
|
-
|
|
335
|
-
type: multiple ? 'checkbox' : 'radio',
|
|
336
|
-
onChange: function onChange(keys, rows) {
|
|
337
|
-
selectRowRef.current = rows;
|
|
338
|
-
}
|
|
339
|
-
},
|
|
382
|
+
rowKey: tableKey,
|
|
340
383
|
onRow: function onRow(record) {
|
|
341
384
|
return {
|
|
342
385
|
onDoubleClick: function onDoubleClick() {
|
|
@@ -347,7 +390,17 @@ var InputTable = /*#__PURE__*/_react.default.forwardRef(function (prop, ref) {
|
|
|
347
390
|
};
|
|
348
391
|
},
|
|
349
392
|
toolBarRender: function toolBarRender() {
|
|
350
|
-
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",
|
|
351
404
|
onClick: function onClick() {
|
|
352
405
|
handleValue(selectRowRef.current || []);
|
|
353
406
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ls-pro-common",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.19",
|
|
4
4
|
"description": "ls-pro-common",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@ant-design/icons": "^4.3.0",
|
|
24
|
-
"ls-pro-table": "^3.0.
|
|
24
|
+
"ls-pro-table": "^3.0.11",
|
|
25
25
|
"ls-pro-form": "^3.0.6",
|
|
26
26
|
"ls-pro-descriptions": "^3.0.1",
|
|
27
27
|
"ls-pro-card": "^3.0.3",
|