easy3wui 1.5.55-beta2 → 1.5.55-beta5

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.
@@ -71,8 +71,7 @@ var Easy3wEditBigTable = function (_Component) {
71
71
  };
72
72
 
73
73
  _this.onGridRowsUpdated = function (objUpdated) {
74
- var fromRow = objUpdated.fromRow,
75
- fromRowData = objUpdated.fromRowData;
74
+ var fromRowData = objUpdated.fromRowData;
76
75
  var updated = objUpdated.updated;
77
76
  var _this$props = _this.props,
78
77
  touchAutoCompute = _this$props.touchAutoCompute,
@@ -83,7 +82,6 @@ var Easy3wEditBigTable = function (_Component) {
83
82
  // 数据变更-自动计算行数据
84
83
  updated = touchAutoCompute(objUpdated);
85
84
  }
86
- console.log('onGridRowsUpdated', objUpdated, updated);
87
85
  var autoAddNumberIdxEdit = fromRowData.autoAddNumber_idx_edit;
88
86
 
89
87
  dataList[autoAddNumberIdxEdit] = (0, _extends3['default'])({}, fromRowData, updated);
@@ -98,22 +96,37 @@ var Easy3wEditBigTable = function (_Component) {
98
96
  };
99
97
 
100
98
  _this.onRowsSelected = function (rows) {
101
- _this.setState({
102
- arrSelectedIndexes: _this.state.arrSelectedIndexes.concat(rows.map(function (r) {
103
- return r.rowIdx;
104
- })) // 表格选择行索引
105
- });
99
+ var arrValues = _this.state.arrValues;
100
+ var rowKey = _this.props.rowKey;
101
+
102
+ var arrValuesNew = arrValues.concat(rows.map(function (r) {
103
+ return r.row[rowKey];
104
+ })); // 表格选择行索引
105
+ _this.onSelectedRowsChange(arrValuesNew);
106
106
  };
107
107
 
108
108
  _this.onRowsDeselected = function (rows) {
109
- var rowIndexes = rows.map(function (r) {
110
- return r.rowIdx;
111
- });
112
- _this.setState({
113
- arrSelectedIndexes: _this.state.arrSelectedIndexes.filter(function (i) {
114
- return rowIndexes.indexOf(i) === -1;
115
- }) // 表格选择行索引
109
+ var arrValues = _this.state.arrValues;
110
+ var rowKey = _this.props.rowKey;
111
+
112
+ var arrValuesNew = arrValues.filter(function (key) {
113
+ var flag = true;
114
+ rows.map(function (r) {
115
+ var row = r.row;
116
+
117
+ if (key === row[rowKey]) {
118
+ // 删除已取消选择的行
119
+ flag = false;
120
+ }
121
+ return r;
122
+ });
123
+ return flag;
116
124
  });
125
+ _this.onSelectedRowsChange(arrValuesNew);
126
+ };
127
+
128
+ _this.onSelectedRowsChange = function (arrValues) {
129
+ _this.setState({ arrValues: arrValues });
117
130
  };
118
131
 
119
132
  _this.touchAddRow = function () {
@@ -132,14 +145,14 @@ var Easy3wEditBigTable = function (_Component) {
132
145
  var _this$props3 = _this.props,
133
146
  onGridRowsUpdated = _this$props3.onGridRowsUpdated,
134
147
  dataList = _this$props3.dataList;
135
- var arrSelectedIndexes = _this.state.arrSelectedIndexes;
148
+ var arrValues = _this.state.arrValues;
136
149
 
137
- if (arrSelectedIndexes.length) {
150
+ if (arrValues.length) {
138
151
  var newArr = []; // 复制的新数组
139
- arrSelectedIndexes.forEach(function (rowIdx) {
140
- var newRow = (0, _extends3['default'])({}, dataList[rowIdx]);
152
+ arrValues.forEach(function (key) {
153
+ var newRow = (0, _extends3['default'])({}, dataList[key]);
141
154
  newArr.push(newRow);
142
- return rowIdx;
155
+ return key;
143
156
  });
144
157
  var dataListNew = [].concat(dataList, newArr);
145
158
  if (onGridRowsUpdated && typeof onGridRowsUpdated === 'function') {
@@ -157,21 +170,36 @@ var Easy3wEditBigTable = function (_Component) {
157
170
  _this.deleteRow = function () {
158
171
  var _this$props4 = _this.props,
159
172
  dataList = _this$props4.dataList,
160
- onGridRowsUpdated = _this$props4.onGridRowsUpdated;
161
- var arrSelectedIndexes = _this.state.arrSelectedIndexes;
162
-
163
- if (arrSelectedIndexes.length) {
164
- var dataListNew = []; // 复制的新数组
165
- dataList.forEach(function (row, index) {
166
- if (arrSelectedIndexes.indexOf(index) === -1) {
167
- dataListNew.push(row);
168
- }
169
- return index;
173
+ onGridRowsUpdated = _this$props4.onGridRowsUpdated,
174
+ objToolbarProps = _this$props4.objToolbarProps,
175
+ rowKey = _this$props4.rowKey;
176
+ var deleteRowInterface = objToolbarProps.deleteRowInterface;
177
+ var arrValues = _this.state.arrValues;
178
+
179
+ if (arrValues.length) {
180
+ // const dataListNew = []; // 删除选择行后的新数组
181
+ var dataListDel = []; // 要删除的行数组
182
+ var dataListNew = dataList.filter(function (row) {
183
+ var flag = true;
184
+ arrValues.map(function (key) {
185
+ if (key === row[rowKey]) {
186
+ dataListDel.push(row);
187
+ // 删除选择的行
188
+ flag = false;
189
+ }
190
+ return key;
191
+ });
192
+ return flag;
170
193
  });
194
+ if (deleteRowInterface && typeof deleteRowInterface === 'function') {
195
+ // 删除行接口
196
+ deleteRowInterface(dataListDel, arrValues);
197
+ }
171
198
  if (onGridRowsUpdated && typeof onGridRowsUpdated === 'function') {
172
199
  // 数据变更-回调函数
173
200
  onGridRowsUpdated('deleteRow', dataListNew);
174
201
  }
202
+ _this.onSelectedRowsChange([]); // 选择行清空
175
203
  } else {
176
204
  _modal2['default'].error({
177
205
  title: '错误',
@@ -255,7 +283,8 @@ var Easy3wEditBigTable = function (_Component) {
255
283
  var _this$props5 = _this.props,
256
284
  touchAutoCompute = _this$props5.touchAutoCompute,
257
285
  onGridRowsUpdated = _this$props5.onGridRowsUpdated,
258
- dataList = _this$props5.dataList;
286
+ dataList = _this$props5.dataList,
287
+ rowKey = _this$props5.rowKey;
259
288
  // if (touchAutoCompute && typeof touchAutoCompute === 'function') { // 数据变更-自动计算行数据
260
289
  // updated = touchAutoCompute(objUpdated);
261
290
  // }
@@ -277,8 +306,6 @@ var Easy3wEditBigTable = function (_Component) {
277
306
  // toRow 改变的单元格的新行序号
278
307
  // toRowId 改变的单元格的新行id
279
308
  // updated 改变的单元格的新值
280
- var rowKey = _this.ReactDataGridRef.props.rowKey;
281
-
282
309
  updated = touchAutoCompute({ cellKey: objColumn.key, fromRow: autoAddNumberIdxView, toRow: autoAddNumberIdxView, fromRowId: row[rowKey], toRowId: row[rowKey], rowIds: [row[rowKey]], updated: updated, action: 'CELL_BATCH_CHANGE', fromRowData: row });
283
310
  }
284
311
  dataList[autoAddNumberIdxEdit] = (0, _extends3['default'])({}, row, updated);
@@ -297,10 +324,11 @@ var Easy3wEditBigTable = function (_Component) {
297
324
  sortDirection = _this$state.sortDirection;
298
325
  var _this$props6 = _this.props,
299
326
  dataList = _this$props6.dataList,
300
- enableCellSelect = _this$props6.enableCellSelect;
327
+ enableCellSelect = _this$props6.enableCellSelect,
328
+ rowSelection = _this$props6.rowSelection;
301
329
 
302
330
  var rows = dataList;
303
- if (enableCellSelect) {
331
+ if (enableCellSelect || rowSelection) {
304
332
  rows = _this.touchLoopDataBefore();
305
333
  }
306
334
  return Selectors.getRows({ rows: rows, filters: filters, sortColumn: sortColumn, sortDirection: sortDirection });
@@ -319,11 +347,12 @@ var Easy3wEditBigTable = function (_Component) {
319
347
  _this.touchLoopDataBefore = function () {
320
348
  var dataList = _this.props.dataList;
321
349
 
322
- var rows = dataList.map(function (row, index) {
350
+ dataList.map(function (row, index) {
323
351
  // autoAddNumber_idx_edit 自动添加序号 数据更新时使用确定当前更新的行
324
- return (0, _extends3['default'])({}, row, { autoAddNumber_idx_edit: index });
352
+ dataList[index] = (0, _extends3['default'])({}, row, { autoAddNumber_idx_edit: index });
353
+ return row;
325
354
  });
326
- return rows;
355
+ return dataList;
327
356
  };
328
357
 
329
358
  _this.touchLoopData = function () {
@@ -485,11 +514,57 @@ var Easy3wEditBigTable = function (_Component) {
485
514
  return toolbar;
486
515
  };
487
516
 
517
+ _this.onCheckCellIsEditable = function (obj) {
518
+ var column = obj.column;
519
+ // column:当前列的信息。
520
+ // idx:当前单元格的索引。
521
+ // row:当前行的数据。
522
+ // rowIdx:当前行的索引
523
+
524
+ var editable = column.editable,
525
+ editor = column.editor;
526
+
527
+ if (editable || editor) {
528
+ // 单元格可编辑
529
+ return true; // 返回 true 表示允许编辑
530
+ } else {
531
+ return false; // 返回 false 表示禁止编辑
532
+ }
533
+ };
534
+
535
+ _this.touchRowRenderer = function (obj) {
536
+ var onCheckCellIsEditable = _this.props.onCheckCellIsEditable;
537
+ var renderBaseRow = obj.renderBaseRow,
538
+ columns = obj.columns,
539
+ row = obj.row,
540
+ idx = obj.idx;
541
+
542
+ var onCheckCellIsEditableNew = onCheckCellIsEditable || _this.onCheckCellIsEditable;
543
+ var columnsNew = [].concat(columns);
544
+ columns.map(function (column, index) {
545
+ if (onCheckCellIsEditableNew({ column: column, idx: idx, row: row })) {
546
+ columnsNew[index] = (0, _extends3['default'])({}, column, { cellClass: (column.cellClass || '') + ' custom-edit-cell' });
547
+ }
548
+ return column;
549
+ });
550
+ return _react2['default'].createElement(
551
+ 'span',
552
+ null,
553
+ renderBaseRow((0, _extends3['default'])({}, obj, {
554
+ columns: [].concat(columnsNew)
555
+ }))
556
+ );
557
+ };
558
+
488
559
  _this.getReactDataGridProps = function () {
560
+ var arrValues = _this.state.arrValues;
489
561
  var _this$props8 = _this.props,
490
562
  enableCellSelect = _this$props8.enableCellSelect,
563
+ rowKey = _this$props8.rowKey,
491
564
  objToolbarProps = _this$props8.objToolbarProps,
492
- rowSelection = _this$props8.rowSelection;
565
+ rowSelection = _this$props8.rowSelection,
566
+ onCheckCellIsEditable = _this$props8.onCheckCellIsEditable,
567
+ touchRowRenderer = _this$props8.touchRowRenderer;
493
568
 
494
569
  var objReactDataGridProps = {}; // ReactDataGrid属性对象
495
570
  // toolbar属性
@@ -506,6 +581,10 @@ var Easy3wEditBigTable = function (_Component) {
506
581
  if (enableCellSelect && typeof enableCellSelect === 'boolean') {
507
582
  objReactDataGridProps.enableCellSelect = enableCellSelect;
508
583
  objReactDataGridProps.onGridRowsUpdated = _this.onGridRowsUpdated; // 表格编辑
584
+ if (onCheckCellIsEditable) {
585
+ objReactDataGridProps.onCheckCellIsEditable = onCheckCellIsEditable; // 单元格是否可编辑
586
+ }
587
+ objReactDataGridProps.rowRenderer = touchRowRenderer || _this.touchRowRenderer; // 表格行渲染
509
588
  }
510
589
  // 表格行选择
511
590
  if (rowSelection && typeof rowSelection === 'boolean') {
@@ -515,8 +594,11 @@ var Easy3wEditBigTable = function (_Component) {
515
594
  onRowsSelected: _this.onRowsSelected,
516
595
  onRowsDeselected: _this.onRowsDeselected,
517
596
  selectBy: {
518
- rowKey: 'id',
519
- indexes: _this.state.arrSelectedIndexes
597
+ keys: {
598
+ rowKey: rowKey || 'id',
599
+ values: arrValues
600
+ }
601
+ // indexes: this.state.arrValues,
520
602
  }
521
603
  };
522
604
  } else if (rowSelection) {
@@ -534,7 +616,11 @@ var Easy3wEditBigTable = function (_Component) {
534
616
 
535
617
  var columnsNew = [].concat(columns);
536
618
  if (autoAddNumber && typeof autoAddNumber === 'boolean') {
537
- columnsNew = [{ name: '序号', key: 'autoAddNumber_idx_view', resizable: true, width: 50 }].concat(columnsNew);
619
+ var objColumns = columns && columns.length > 0 ? columns[0] : {};
620
+ var _objColumns$frozen = objColumns.frozen,
621
+ frozen = _objColumns$frozen === undefined ? false : _objColumns$frozen;
622
+
623
+ columnsNew = [{ name: '序号', key: 'autoAddNumber_idx_view', resizable: true, width: 50, frozen: frozen }].concat(columnsNew);
538
624
  }
539
625
  _this.columns = columnsNew;
540
626
  return columnsNew;
@@ -616,7 +702,7 @@ var Easy3wEditBigTable = function (_Component) {
616
702
  }
617
703
  _this.state = {
618
704
  // 表格选择
619
- arrSelectedIndexes: [], // 表格选择行索引
705
+ arrValues: [], // 表格选择行索引
620
706
  // 查询条件
621
707
  filters: {},
622
708
  // 排序--sort
@@ -644,6 +730,8 @@ var Easy3wEditBigTable = function (_Component) {
644
730
 
645
731
  // 表格选择---取消选择
646
732
 
733
+ // 改变选择状态
734
+
647
735
  // #endregion 表格选择
648
736
  // #region 右上角按钮处理--toolbar
649
737
  // 新增
@@ -687,6 +775,9 @@ var Easy3wEditBigTable = function (_Component) {
687
775
 
688
776
  // #endregion toolbar处理
689
777
  // #region 设置ReactDataGrid属性
778
+ // 在单元格设置为活动状态之前调用,返回一个布尔值以确定单元格是否可编辑
779
+
780
+ // 表格行渲染
690
781
 
691
782
  // 创建columns
692
783
 
@@ -707,7 +798,9 @@ var Easy3wEditBigTable = function (_Component) {
707
798
  var _props = this.props,
708
799
  totalFlag = _props.totalFlag,
709
800
  objOtherProps = _props.objOtherProps,
710
- objToolbarProps = _props.objToolbarProps;
801
+ objToolbarProps = _props.objToolbarProps,
802
+ strReactDataGridStyle = _props.strReactDataGridStyle,
803
+ strAddReactDataGridStyle = _props.strAddReactDataGridStyle;
711
804
 
712
805
  var objReactDataGridProps = this.getReactDataGridProps();
713
806
  var columns = this.createColumns(); // 表头
@@ -715,7 +808,12 @@ var Easy3wEditBigTable = function (_Component) {
715
808
  return _react2['default'].createElement(
716
809
  'div',
717
810
  { style: { backgroundColor: '#fff' } },
718
- _react2['default'].createElement(_reactDataGrid2['default'], (0, _extends3['default'])({
811
+ _react2['default'].createElement(
812
+ 'style',
813
+ null,
814
+ strReactDataGridStyle || (strAddReactDataGridStyle || '') + '\n .custom-edit-cell { \n background-color: #f6ffed;\n }\n '
815
+ ),
816
+ _react2['default'].createElement(_reactDataGrid2['default'], (0, _extends3['default'])({}, this.props, {
719
817
  ref: this.ReactDataGridRef,
720
818
  columns: columns // 表头
721
819
  // rows={rows}
@@ -762,5 +860,8 @@ var Easy3wEditBigTable = function (_Component) {
762
860
  return Easy3wEditBigTable;
763
861
  }(_react.Component);
764
862
 
863
+ Easy3wEditBigTable.defaultProps = {
864
+ rowKey: 'autoAddNumber_idx_edit'
865
+ };
765
866
  exports['default'] = Easy3wEditBigTable;
766
867
  module.exports = exports['default'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy3wui",
3
- "version": "1.5.55-beta2",
3
+ "version": "1.5.55-beta5",
4
4
  "description": "easy3wui components for react",
5
5
  "keywords": [
6
6
  "react",