jrs-react 1.1.30 → 1.2.2

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/build/index.es.js CHANGED
@@ -6056,6 +6056,25 @@ const flexType = (type, me, payload, doElse) => {
6056
6056
  const result = typeof type === 'function' ? type?.bind(me)(payload) : type ?? doElse;
6057
6057
  return result;
6058
6058
  };
6059
+ const whatType = ({
6060
+ type,
6061
+ typeStyle: _typeStyle,
6062
+ render,
6063
+ ...config
6064
+ }, me, doElse) => {
6065
+ if (type) {
6066
+ // const style=flexType(typeStyle,me,{},{})
6067
+ // return 'type'
6068
+ const typeStyle = typeof _typeStyle === 'function' ? _typeStyle?.bind(me)() : _typeStyle;
6069
+ return /*#__PURE__*/React.createElement(type, {
6070
+ style: typeStyle
6071
+ });
6072
+ } else if (render) {
6073
+ return render.bind(me)();
6074
+ } else {
6075
+ return doElse;
6076
+ }
6077
+ };
6059
6078
 
6060
6079
  // import { IconSpinner } from '../assets/image';
6061
6080
 
@@ -6444,13 +6463,25 @@ class JRSubmit extends React.Component {
6444
6463
  response = config?.response?.bind(this)(response, payload) ?? response;
6445
6464
  const isSuccess = response.status >= 200 && response.status <= 299;
6446
6465
  this.setRes(isSuccess, response, config);
6447
- if (isSuccess) {
6448
- if (config.successMessage) ;
6449
- } else {
6450
- if (config.failedMessage) ;
6451
- }
6466
+ this.showMessage(isSuccess, isSuccess ? config.successMessage : config.failedMessage);
6467
+
6468
+ // if (isSuccess) {
6469
+ // if (config.successMessage) {
6470
+ // // msg.success({ message:config.successMessage })
6471
+ // // alert(config.successMessage)
6472
+ // }
6473
+ // } else {
6474
+ // if (config.failedMessage) {
6475
+ // // msg.error({ message:config.failedMessage })
6476
+ // // alert(config.failedMessage)
6477
+ // }
6478
+ // }
6452
6479
  config.callback?.bind(this)(isSuccess, response, payload);
6453
6480
  };
6481
+ showMessage(success, message) {
6482
+ po('success', success);
6483
+ po('message', message);
6484
+ }
6454
6485
  renderer() {
6455
6486
  return;
6456
6487
  }
@@ -6558,6 +6589,840 @@ class JRFrame extends JRSubmit {
6558
6589
  }
6559
6590
  }
6560
6591
 
6592
+ const StyledSlider = styled.div`
6593
+ position: absolute;
6594
+ top: 0;
6595
+ right: 0;
6596
+ height:100%;
6597
+ width:6px;
6598
+ user-select: none;
6599
+ &.resizing:hover,&.resizing{
6600
+ border-right:1px dashed black;
6601
+ }
6602
+ &:hover{
6603
+ cursor: col-resize;
6604
+ border-right:1px dashed gray;
6605
+ }
6606
+ `;
6607
+ class Slider extends React.Component {
6608
+ constructor() {
6609
+ super();
6610
+ this.sliderRef = /*#__PURE__*/React.createRef();
6611
+ }
6612
+ stop = e => {
6613
+ this.sliderRef.current.classList.remove('resizing');
6614
+ document.body.style.cursor = 'default';
6615
+ window.removeEventListener('mousemove', this.move);
6616
+ window.removeEventListener('mouseup', this.stop);
6617
+ };
6618
+ move = ({
6619
+ clientX
6620
+ }) => {
6621
+ const {
6622
+ th,
6623
+ selectedCols,
6624
+ widthRates
6625
+ } = this.data;
6626
+ const {
6627
+ left
6628
+ } = th.getBoundingClientRect();
6629
+ const min = left + 10;
6630
+ const x = clientX >= min ? clientX : min;
6631
+ const width = x - left;
6632
+ selectedCols.forEach((col, index) => {
6633
+ const _width = Math.round(width / 100 * widthRates[index]);
6634
+ col.style.width = _width + 'px';
6635
+ });
6636
+ };
6637
+ start(thPRef, column) {
6638
+ const selectedCols = [...this.props.table.colGroupRef.current.children].slice(column.columnNo, column.columnNo + (column.colSpan ?? 1));
6639
+ const totalWidth = selectedCols.reduce((aco, {
6640
+ offsetWidth
6641
+ }) => aco + offsetWidth, 0);
6642
+ const widthRates = selectedCols.map(({
6643
+ offsetWidth
6644
+ }) => {
6645
+ return 100 * (offsetWidth / totalWidth);
6646
+ });
6647
+ this.data = {
6648
+ selectedCols,
6649
+ th: thPRef.current,
6650
+ widthRates
6651
+ };
6652
+ this.sliderRef.current.classList.add('resizing');
6653
+ document.body.style.cursor = 'col-resize';
6654
+ window.addEventListener('mousemove', this.move);
6655
+ window.addEventListener('mouseup', this.stop);
6656
+ }
6657
+ render() {
6658
+ const column = this.props.column;
6659
+ return /*#__PURE__*/React.createElement(StyledSlider, {
6660
+ ref: this.sliderRef,
6661
+ onMouseDown: e => {
6662
+ this.start(this.props.thRef, column);
6663
+ }
6664
+ });
6665
+ }
6666
+ }
6667
+
6668
+ const Colgroup = ({
6669
+ leafColumns,
6670
+ colGroupRef
6671
+ }) => {
6672
+ return /*#__PURE__*/React.createElement("colgroup", {
6673
+ ref: colGroupRef
6674
+ }, leafColumns?.map((_column, index) => {
6675
+ const {
6676
+ width,
6677
+ ...column
6678
+ } = _column;
6679
+ const style = {
6680
+ width
6681
+ };
6682
+ return /*#__PURE__*/React.createElement("col", {
6683
+ style: style,
6684
+ key: index
6685
+ });
6686
+ }));
6687
+ };
6688
+ const Ths$1 = ({
6689
+ deep,
6690
+ rowColumn,
6691
+ rowIndex,
6692
+ table
6693
+ }) => {
6694
+ return rowColumn?.map((column, colIndex) => {
6695
+ const thRef = /*#__PURE__*/React.createRef();
6696
+ return /*#__PURE__*/React.createElement("th", {
6697
+ key: colIndex,
6698
+ ref: thRef,
6699
+ colSpan: column.colSpan,
6700
+ rowSpan: column.rowSpan ?? (column.isLeaf && deep > rowIndex ? deep - rowIndex + 1 : null)
6701
+ }, flexType(column.label, table), table.props.resizableColumns === true && /*#__PURE__*/React.createElement(Slider, {
6702
+ table: table,
6703
+ thRef: thRef,
6704
+ column: column
6705
+ }));
6706
+ });
6707
+ };
6708
+ const HeadTrs = ({
6709
+ columns: _columns,
6710
+ trClassName,
6711
+ table
6712
+ }) => {
6713
+ const columns = Array.isArray(_columns?.[0]) ? _columns : [_columns];
6714
+ return columns?.map((rowColumn, rowIndex) => {
6715
+ return /*#__PURE__*/React.createElement("tr", {
6716
+ className: trClassName,
6717
+ key: rowIndex
6718
+ }, /*#__PURE__*/React.createElement(Ths$1, {
6719
+ deep: columns.length - 1,
6720
+ rowColumn: rowColumn,
6721
+ rowIndex: rowIndex,
6722
+ table: table
6723
+ }));
6724
+ });
6725
+ };
6726
+ const THead = ({
6727
+ columns,
6728
+ leafColumns,
6729
+ table
6730
+ }) => {
6731
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement(HeadTrs, {
6732
+ columns: columns,
6733
+ table: table
6734
+ })), /*#__PURE__*/React.createElement(Colgroup, {
6735
+ leafColumns: leafColumns,
6736
+ colGroupRef: table.colGroupRef
6737
+ }));
6738
+ };
6739
+ const FootThs = ({
6740
+ table,
6741
+ groupData,
6742
+ groupIndex,
6743
+ deep,
6744
+ columns,
6745
+ rowIndex
6746
+ }) => {
6747
+ return columns?.map((column, colIndex) => {
6748
+ // let content
6749
+ // if(type){
6750
+ // content='type'
6751
+ // }else if(render){
6752
+
6753
+ // content=render?.bind(table)({groupData,groupIndex,ths:111})
6754
+ // }else{
6755
+ // content=column.label
6756
+ // }
6757
+ let style = flexType(column.style, table, {}, {});
6758
+ const content = whatType(column, table, column.label);
6759
+ return /*#__PURE__*/React.createElement("th", {
6760
+ style: style,
6761
+ colSpan: column.colSpan,
6762
+ rowSpan: column.rowSpan
6763
+ }, content);
6764
+ });
6765
+ };
6766
+ const TFoot = ({
6767
+ table,
6768
+ columns
6769
+ }) => {
6770
+ const trs = columns?.map((rowColumn, rowIndex) => {
6771
+ return /*#__PURE__*/React.createElement("tr", {
6772
+ key: rowIndex
6773
+ }, /*#__PURE__*/React.createElement(FootThs, {
6774
+ columns: rowColumn,
6775
+ table: table
6776
+ }));
6777
+ });
6778
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("tfoot", null, trs));
6779
+ };
6780
+
6781
+ function _extends() {
6782
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
6783
+ for (var e = 1; e < arguments.length; e++) {
6784
+ var t = arguments[e];
6785
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
6786
+ }
6787
+ return n;
6788
+ }, _extends.apply(null, arguments);
6789
+ }
6790
+
6791
+ styled.tbody`
6792
+ th{
6793
+ height:4px;
6794
+ background:#c6c6c6;
6795
+ }
6796
+ `;
6797
+
6798
+ ////////////////////////////////////////////////////////////////////////////
6799
+
6800
+ const Ths = ({
6801
+ table,
6802
+ groupData,
6803
+ groupIndex,
6804
+ deep,
6805
+ rowColumn,
6806
+ rowIndex
6807
+ }) => {
6808
+ return rowColumn?.map(({
6809
+ style: _style,
6810
+ align,
6811
+ type,
6812
+ render,
6813
+ ...column
6814
+ }, colIndex) => {
6815
+ const style = flexType(_style, table, {}, {});
6816
+ let content;
6817
+ if (type) {
6818
+ content = 'type';
6819
+ } else if (render) {
6820
+ content = render?.bind(table)({
6821
+ groupData,
6822
+ groupIndex,
6823
+ ths: 111
6824
+ });
6825
+ } else {
6826
+ content = column.label;
6827
+ }
6828
+ // style.textAlign=align
6829
+ return /*#__PURE__*/React.createElement("th", {
6830
+ key: colIndex,
6831
+ style: {
6832
+ textAlign: align,
6833
+ ...style
6834
+ },
6835
+ colSpan: column.colSpan,
6836
+ rowSpan: column.isLeaf && deep > rowIndex ? deep - rowIndex + 1 : null
6837
+ }, content);
6838
+ });
6839
+ };
6840
+ const GroupColumns = ({
6841
+ table,
6842
+ columns: _columns,
6843
+ trClassName,
6844
+ groupData,
6845
+ tbodyIndex
6846
+ }) => {
6847
+ const columns = Array.isArray(_columns?.[0]) ? _columns : [_columns];
6848
+ return columns?.map((rowColumn, rowIndex) => {
6849
+ return /*#__PURE__*/React.createElement("tr", {
6850
+ className: trClassName,
6851
+ key: rowIndex
6852
+ }, /*#__PURE__*/React.createElement(Ths, {
6853
+ table: table,
6854
+ groupData: groupData,
6855
+ groupIndex: tbodyIndex,
6856
+ deep: columns.length - 1,
6857
+ rowColumn: rowColumn,
6858
+ rowIndex: rowIndex
6859
+ }));
6860
+ });
6861
+ };
6862
+ styled.tr`
6863
+ z-index: 1;
6864
+ XXposition: sticky;
6865
+ XXtop: 50px;
6866
+ th{
6867
+ text-align: left;
6868
+ border:1px solid #222222;
6869
+ }
6870
+ `;
6871
+ const GroupHeader = props => {
6872
+ return /*#__PURE__*/React.createElement(GroupColumns, _extends({
6873
+ trClassName: 'jr-group-header'
6874
+ }, props));
6875
+ };
6876
+ styled.tr`
6877
+ th{
6878
+ border:1px solid #222222;
6879
+ text-align: left;
6880
+ }
6881
+ `;
6882
+ const GroupFooter = props => {
6883
+ return /*#__PURE__*/React.createElement(GroupColumns, _extends({
6884
+ trClassName: 'jr-group-footer'
6885
+ }, props));
6886
+ };
6887
+
6888
+ ////////////////////////////////////////////////////////////////////////////
6889
+ const Td = ({
6890
+ column: _column,
6891
+ record,
6892
+ tbodyIndex,
6893
+ trIndex,
6894
+ tdIndex,
6895
+ table
6896
+ }) => {
6897
+ let content;
6898
+ const {
6899
+ style: _style,
6900
+ align,
6901
+ vAlign = 'baseline',
6902
+ type,
6903
+ typeStyle: _typeStyle,
6904
+ render,
6905
+ setValue,
6906
+ getValue,
6907
+ onChange: _onChange,
6908
+ funcProps,
6909
+ ...column
6910
+ } = _column;
6911
+ const onChange = inputValue => {
6912
+ const targetValue = inputValue?.target?.value ?? inputValue;
6913
+ setValue(record, targetValue);
6914
+ table.setValue(table.getValue());
6915
+ };
6916
+ const value = getValue(record);
6917
+ let style = render ? {} : flexType(_style, table, {
6918
+ value,
6919
+ record
6920
+ }, {});
6921
+ const setStyle = _style => {
6922
+ style = _style;
6923
+ };
6924
+ setStyle.bind(table);
6925
+ render?.bind(table);
6926
+ if (type) {
6927
+ const typeStyle = flexType(_typeStyle, table, {
6928
+ record
6929
+ }, {});
6930
+ content = /*#__PURE__*/React.createElement(type, {
6931
+ onChange: _onChange ? e => {
6932
+ _onChange?.bind(table)(e, {
6933
+ value,
6934
+ onChange,
6935
+ me: content
6936
+ });
6937
+ } : onChange,
6938
+ value,
6939
+ style: typeStyle,
6940
+ render,
6941
+ ...column,
6942
+ ...funcProps?.bind(table)({
6943
+ value
6944
+ })
6945
+ });
6946
+ } else if (render) {
6947
+ content = render({
6948
+ index: trIndex,
6949
+ groupIndex: tbodyIndex,
6950
+ value,
6951
+ record,
6952
+ onChange,
6953
+ setStyle
6954
+ });
6955
+ } else {
6956
+ content = value;
6957
+ }
6958
+ return /*#__PURE__*/React.createElement("td", {
6959
+ colSpan: style.colSpan,
6960
+ rowSpan: style.rowSpan,
6961
+ style: {
6962
+ textAlign: align,
6963
+ verticalAlign: vAlign,
6964
+ ...style
6965
+ },
6966
+ key: tdIndex
6967
+ }, content);
6968
+ };
6969
+ const Tds = ({
6970
+ leafColumns,
6971
+ record,
6972
+ table,
6973
+ tbodyIndex,
6974
+ trIndex
6975
+ }) => {
6976
+ return leafColumns?.map((column, tdIndex) => {
6977
+ return /*#__PURE__*/React.createElement(Td, {
6978
+ column: column,
6979
+ key: tdIndex,
6980
+ record: record,
6981
+ table: table,
6982
+ tbodyIndex: tbodyIndex,
6983
+ trIndex: trIndex,
6984
+ tdIndex: tdIndex
6985
+ });
6986
+ });
6987
+ };
6988
+ ////////////////////////////////////////////////////////////////////////////
6989
+
6990
+ const TBody = ({
6991
+ groupData,
6992
+ groupHeader,
6993
+ leafColumns,
6994
+ groupFooter,
6995
+ table,
6996
+ tbodyIndex
6997
+ }) => {
6998
+ const neededProps = {
6999
+ table,
7000
+ tbodyIndex
7001
+ };
7002
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("tbody", {
7003
+ key: `tbody${tbodyIndex}`
7004
+ }, groupData?.length > 0 && /*#__PURE__*/React.createElement(GroupHeader, _extends({
7005
+ groupData: groupData,
7006
+ columns: groupHeader
7007
+ }, neededProps)), groupData?.map((record, trIndex) => {
7008
+ const onRowClick = table.props.onRowClick?.bind(table);
7009
+ return /*#__PURE__*/React.createElement("tr", {
7010
+ key: trIndex,
7011
+ onClick: () => {
7012
+ onRowClick?.({
7013
+ record,
7014
+ index: trIndex,
7015
+ groupIndex: tbodyIndex
7016
+ });
7017
+ }
7018
+ }, /*#__PURE__*/React.createElement(Tds, _extends({
7019
+ record: record,
7020
+ trIndex: trIndex
7021
+ }, neededProps, {
7022
+ leafColumns: leafColumns
7023
+ })));
7024
+ }), groupData?.length > 0 && /*#__PURE__*/React.createElement(GroupFooter, _extends({
7025
+ groupData: groupData,
7026
+ columns: groupFooter
7027
+ }, neededProps))));
7028
+ };
7029
+ const TBodies = ({
7030
+ groupHeader,
7031
+ leafColumns,
7032
+ groupFooter,
7033
+ dataSource: _dataSource,
7034
+ table
7035
+ }) => {
7036
+ // po('--TBodies--')
7037
+ const isGroupDataType = Array.isArray(_dataSource?.[0]);
7038
+ const dataSource = isGroupDataType ? _dataSource : [_dataSource];
7039
+
7040
+ // po('dataSource',dataSource)
7041
+ return dataSource?.map((groupData, tbodyIndex, c) => {
7042
+ return /*#__PURE__*/React.createElement(TBody, {
7043
+ key: `tbody${tbodyIndex}`,
7044
+ table: table
7045
+ // dataSource={dataSource}
7046
+ // dataGroup={groupData}
7047
+ ,
7048
+ groupData: groupData,
7049
+ tbodyIndex: tbodyIndex,
7050
+ groupHeader: groupHeader,
7051
+ leafColumns: leafColumns,
7052
+ groupFooter: groupFooter
7053
+ });
7054
+ });
7055
+ };
7056
+
7057
+ const StyledJRTable = styled.div`
7058
+ --column-bd-color:#cccccc;
7059
+ --column-b-color:#eeeeee;
7060
+ --column-b-hover-color:#ffffff;
7061
+
7062
+ position: relative;
7063
+ background: var(--column-b-color);
7064
+ border:1px solid var(--column-bd-color);
7065
+
7066
+ display:flex;
7067
+ flex-direction: column;
7068
+ flex:1;
7069
+ overflow: overlay;
7070
+
7071
+
7072
+
7073
+
7074
+ &.row-highlightable{
7075
+ tbody{
7076
+ tr:not(.jr-group-header,.jr-group-footer):hover{
7077
+ background:var(--column-b-hover-color);
7078
+ cursor: pointer;
7079
+ transition: background-color .8s;
7080
+ td{
7081
+ color:black;
7082
+ transition:color .8s;
7083
+ }
7084
+
7085
+ }
7086
+ }
7087
+ }
7088
+
7089
+ table{
7090
+ Xheight: 100%;
7091
+ min-width:100%;
7092
+ width: max-content;
7093
+ border-spacing: 0;
7094
+
7095
+ thead{
7096
+ position: sticky;
7097
+ top: 0;
7098
+
7099
+ th{
7100
+ position: relative;
7101
+ height:32px;
7102
+ padding: 4px;
7103
+ background: linear-gradient(180deg, rgba(227, 227, 226, 1) 0%, rgba(255, 255, 255, 1) 25%, rgba(210, 210, 210, 1) 100%);
7104
+ box-shadow: 2px 2px 2px 0 #ffffffd6 inset, -1px -1px 2px 0px #8a847dbf inset;
7105
+ color: #525252;
7106
+ white-space: nowrap;
7107
+ }
7108
+ }
7109
+
7110
+ tfoot{
7111
+ position: sticky;
7112
+ bottom: -1px;
7113
+
7114
+ Xtr:nth-child(1){
7115
+ th{
7116
+ Xborder-top:1px solid var(--column-bd-color);
7117
+ }
7118
+ }
7119
+ Xth:nth-child(1){
7120
+ Xborder-left:1px solid var(--column-bd-color);
7121
+ }
7122
+
7123
+ th{
7124
+ height:32px;
7125
+ padding: 4px;
7126
+ background: #e4e4e4;
7127
+ xbackground: linear-gradient(180deg, rgba(227, 227, 226, 1) 0%, rgba(255, 255, 255, 1) 25%, rgba(210, 210, 210, 1) 100%);
7128
+ xbox-shadow: 2px 2px 2px 0 #ffffffd6 inset, -1px -1px 2px 0px #8a847dbf inset;
7129
+ color: #525252;
7130
+ white-space: nowrap;
7131
+
7132
+ border-left:2px solid #f4f4f4;
7133
+ border-top:2px solid #f4f4f4;
7134
+ border-right:2px solid var(--column-bd-color);
7135
+ border-bottom:2px solid var(--column-bd-color);
7136
+ }
7137
+ }
7138
+
7139
+ tbody{
7140
+ tr{
7141
+ transition: background .3s linear;
7142
+ background:var(--column-b-color);
7143
+ a:#ededed;
7144
+ th{
7145
+ color:#444444;
7146
+ }
7147
+ td{
7148
+ border-bottom: 1px solid var(--column-bd-color);
7149
+ color:#2e2e2e;
7150
+ padding: 4px;
7151
+ }
7152
+ }
7153
+ tr:hover{
7154
+ background:var(--column-b-hover-color);
7155
+
7156
+ }
7157
+
7158
+ tr.jr-group-header
7159
+ ,tr.jr-group-footer{
7160
+ text-align:left;
7161
+ background:#dddbdb;
7162
+
7163
+ th{
7164
+ border-bottom: 1px solid var(--column-bd-color);
7165
+ border-right: 1px solid var(--column-bd-color);
7166
+ padding: 4px 8px;
7167
+ }
7168
+ }
7169
+ }
7170
+ tbody.empty-tbody{
7171
+ td{
7172
+ border:10px solid red;
7173
+ }
7174
+ }
7175
+ }
7176
+
7177
+
7178
+
7179
+
7180
+ > .empty{
7181
+ user-select: none;
7182
+ color:#848484;
7183
+ height:100%;
7184
+ flex:1;
7185
+ display:flex;
7186
+ justify-content: center;
7187
+ align-items: center;
7188
+ }
7189
+ `;
7190
+
7191
+ const getMapObject = (map, names) => {
7192
+ const name = names.shift(names);
7193
+ if (names.length) {
7194
+ return getMapObject(map?.[name], names);
7195
+ } else {
7196
+ return map;
7197
+ }
7198
+ };
7199
+ const setMapObject = (map, names, value) => {
7200
+ const name = names.shift(names);
7201
+ if (names?.length) {
7202
+ if (typeof map[name] != 'object') {
7203
+ map[name] = {};
7204
+ }
7205
+ setMapObject(map[name], names, value);
7206
+ } else {
7207
+ map[name] = value;
7208
+ }
7209
+ };
7210
+ class JRTable extends JRFrame {
7211
+ constructor(props) {
7212
+ super(props);
7213
+ this.colGroupRef = /*#__PURE__*/React.createRef();
7214
+ }
7215
+ UNSAFE_componentWillMount() {
7216
+ this.setColumns(this.props.columns);
7217
+ }
7218
+
7219
+ //------------------------------------------------------------------------------------
7220
+ getChecked() {
7221
+ return [1, 2, 3, 4];
7222
+ }
7223
+ checkableColumn(props) {
7224
+ return {
7225
+ //方法1
7226
+ render({
7227
+ value,
7228
+ onChange
7229
+ }) {
7230
+ return /*#__PURE__*/React.createElement("checkbox", {
7231
+ checked: value,
7232
+ onChange: e => {
7233
+ onChange(e.target.checked);
7234
+ }
7235
+ });
7236
+ },
7237
+ align: 'center',
7238
+ name: 'checked',
7239
+ ...props
7240
+ };
7241
+ // return {//方法2
7242
+ // type:Checkbox
7243
+ // ,funcProps({value}){
7244
+ // po('fffffffffffff',value)
7245
+ // return {
7246
+ // align:'center'
7247
+ // ,checked:value
7248
+ // }
7249
+ // }
7250
+ // // ,label:'A'
7251
+ // ,onChange(e,{value,onChange,me}){
7252
+ // onChange(e.target.checked)
7253
+ // }
7254
+ // ,...props
7255
+ // }
7256
+ }
7257
+ deletableColumn({
7258
+ name = 'deletable',
7259
+ sendValue,
7260
+ sendName,
7261
+ valueName,
7262
+ ...props
7263
+ }) {
7264
+ return {
7265
+ render({
7266
+ value,
7267
+ onChange
7268
+ }) {
7269
+ return /*#__PURE__*/React.createElement("checkbox", {
7270
+ checked: value,
7271
+ onChange: e => {
7272
+ onChange(e.target.checked);
7273
+ }
7274
+ });
7275
+ },
7276
+ align: 'center',
7277
+ name,
7278
+ label() {
7279
+ return /*#__PURE__*/React.createElement("button", {
7280
+ onClick: () => {
7281
+ const value = this.props.delete.value ?? this.getDataSource()?.filter(record => record[name]).map(record => sendValue ? record[sendValue] : record);
7282
+ const callback = this.props.delete.callback ?? function (a, b, c) {
7283
+ this.reload();
7284
+ };
7285
+ this.delete({
7286
+ value: sendName ? {
7287
+ [sendName]: value
7288
+ } : value,
7289
+ callback,
7290
+ ...props
7291
+ });
7292
+ }
7293
+ }, "\u522A\u9664");
7294
+ },
7295
+ ...props
7296
+ };
7297
+ }
7298
+ initColumn(column, level, result, leafColumns, names, lastColSpan) {
7299
+ const isBranch = column.type === undefined && column?.columns && column?.columns.length;
7300
+ const _names = column.name ? [...names, column.name] : names;
7301
+ if (isBranch) {
7302
+ if (column.label !== null) result[level].push(column);
7303
+ const c = this.initColumns(column.columns, level + (column.label !== null ? 1 : 0) + (column.rowSpan != null ? column.rowSpan - 1 : 0), result, leafColumns, _names, lastColSpan);
7304
+ column.colSpan = c.colSpan;
7305
+ column.columnNo = lastColSpan;
7306
+ return {
7307
+ colSpan: column.colSpan
7308
+ };
7309
+ } else {
7310
+ column.columnNo = lastColSpan;
7311
+ result[level].push({
7312
+ ...column,
7313
+ isLeaf: true
7314
+ });
7315
+ leafColumns.push(column);
7316
+ column.names = _names;
7317
+ if (_names?.length > 1) {
7318
+ column.setValue = function (record, value) {
7319
+ try {
7320
+ getMapObject(record, [..._names])[column.name] = value;
7321
+ } catch {
7322
+ setMapObject(record, [..._names], value);
7323
+ }
7324
+ };
7325
+ column.getValue = function (record) {
7326
+ return _names.reduce((acc, name) => {
7327
+ return acc?.[name];
7328
+ }, record);
7329
+ };
7330
+ } else {
7331
+ column.setValue = function (record, value) {
7332
+ record[column.name] = value;
7333
+ };
7334
+ column.getValue = function (record) {
7335
+ return record[column.name];
7336
+ };
7337
+ }
7338
+ return {
7339
+ colSpan: 1
7340
+ };
7341
+ }
7342
+ }
7343
+ initColumns(columns, level, result, leafColumns, names, lastColSpan) {
7344
+ for (let i = result.length; i <= level; i++) {
7345
+ if (!result[i]) {
7346
+ result.push([]);
7347
+ }
7348
+ }
7349
+ let _lastColSpan = lastColSpan;
7350
+ const childrenLength = columns?.reduce((acc, column) => {
7351
+ const c = this.initColumn(column, level, result, leafColumns, names, _lastColSpan);
7352
+ acc.colSpan += c.colSpan;
7353
+ _lastColSpan += c.colSpan;
7354
+ return acc;
7355
+ }, {
7356
+ colSpan: 0
7357
+ });
7358
+ return childrenLength;
7359
+ }
7360
+ setColumns([..._columns]) {
7361
+ if (this.props.checkable) _columns.unshift(this.checkableColumn(this.props.checkable));
7362
+ if (this.props.deletable) {
7363
+ _columns.unshift(this.deletableColumn(this.props.deletable));
7364
+ }
7365
+ const columns = [];
7366
+ const leafColumns = [];
7367
+ this.initColumns(_columns, 0, columns, leafColumns, [], 0);
7368
+ // po('initColumns',initColumns)
7369
+ this.setState({
7370
+ columns,
7371
+ leafColumns
7372
+ });
7373
+ }
7374
+ //------------------------------------------------------------------------------------
7375
+ setDataSource(dataSource) {}
7376
+ getDataSource() {
7377
+ return this.props.dataSourceName ? this.getValue()?.[this.props.dataSourceName] : this.getValue();
7378
+ }
7379
+ add(record, index = this.getDataSource()?.length ?? 0, group) {
7380
+ //group 還沒有考慮到
7381
+
7382
+ if (this.getDataSource()) {
7383
+ if (group === undefined) {
7384
+ this.getDataSource().splice(index, 0, record); //.push(record)
7385
+ } else {
7386
+ this.getDataSource()[group].splice(index, 0, record); //.push(record)
7387
+ }
7388
+ this.setValue(this.getValue());
7389
+ } else {
7390
+ //未完成. 沒有資料的時候, 要考慮有或沒有dataSourceName的不同處理
7391
+ this.setValue({
7392
+ [this.props.dataSourceName]: [record]
7393
+ });
7394
+ }
7395
+ }
7396
+ noData() {
7397
+ const data = this.getDataSource();
7398
+ return data == null || data.length == 0;
7399
+ }
7400
+ //------------------------------------------------------------------------------------
7401
+ renderMe() {
7402
+ return /*#__PURE__*/React.createElement(StyledJRTable, {
7403
+ className: `${this.props.className ?? ''} jr-table ${this.props.onRowClick ? 'row-highlightable' : ''}`
7404
+ }, /*#__PURE__*/React.createElement("table", {
7405
+ className: 'jr-table-table'
7406
+ }, /*#__PURE__*/React.createElement(TBodies, {
7407
+ table: this,
7408
+ leafColumns: this.state.leafColumns,
7409
+ groupHeader: this.props.groupHeader,
7410
+ groupFooter: this.props.groupFooter,
7411
+ dataSource: this.getDataSource(),
7412
+ onRowClick: this.props.onRowClick
7413
+ }), /*#__PURE__*/React.createElement(TFoot, {
7414
+ columns: this.props.footColumns,
7415
+ table: this
7416
+ }), /*#__PURE__*/React.createElement(THead, {
7417
+ columns: this.state.columns,
7418
+ leafColumns: this.state.leafColumns,
7419
+ table: this
7420
+ })), /*#__PURE__*/React.createElement("div", {
7421
+ className: 'empty'
7422
+ }, this.noData() && '無資料'));
7423
+ }
7424
+ }
7425
+
6561
7426
  const StyledJRFrame = styled.div`
6562
7427
  display:flex;
6563
7428
  flex:1;
@@ -6657,4 +7522,4 @@ class JRTestReact extends JRSubmit {
6657
7522
  }
6658
7523
  }
6659
7524
 
6660
- export { JRFrame, JRSubmit, JRTestReact };
7525
+ export { JRFrame, JRSubmit, JRTable, JRTestReact };