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