feat:行点击事件关联单选功能

This commit is contained in:
yangchch6 2019-12-13 14:13:13 +08:00
parent 5c6f5ff01b
commit 9af72b045d
7 changed files with 688 additions and 747 deletions

View File

@ -203,11 +203,6 @@ function multiSelect(Table, Checkbox) {
if (checkedAll) { if (checkedAll) {
check = false; check = false;
} else { } else {
// if(indeterminate){
// check = true;
// }else{
// check = true;
// }
check = true; check = true;
} }
var selectList = []; var selectList = [];
@ -273,8 +268,6 @@ function multiSelect(Table, Checkbox) {
return res; return res;
}; };
this.handleClick = function () {};
this.onCheckboxChange = function (text, record, index) { this.onCheckboxChange = function (text, record, index) {
return function () { return function () {
var data = _this2.state.data; var data = _this2.state.data;
@ -340,7 +333,6 @@ function multiSelect(Table, Checkbox) {
className: 'table-checkbox' className: 'table-checkbox'
}, attr, multiSelectConfig, { }, attr, multiSelectConfig, {
checked: record._checked, checked: record._checked,
onClick: _this2.handleClick,
onChange: _this2.onCheckboxChange(text, record, index) onChange: _this2.onCheckboxChange(text, record, index)
})); }));
} }

View File

@ -41,6 +41,10 @@ function singleSelect(Table, Radio) {
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.handleRadioClick = function (e) {
e.stopPropagation();
};
_this.onRadioChange = function (value, record, index) { _this.onRadioChange = function (value, record, index) {
var selectedRowIndex = _this.state.selectedRowIndex; var selectedRowIndex = _this.state.selectedRowIndex;
@ -70,6 +74,7 @@ function singleSelect(Table, Radio) {
className: "table-radio", className: "table-radio",
name: "table-radio", name: "table-radio",
selectedValue: selectedRowIndex, selectedValue: selectedRowIndex,
onClick: _this.handleRadioClick,
onChange: function onChange(value) { onChange: function onChange(value) {
return _this.onRadioChange(value, record, index); return _this.onRadioChange(value, record, index);
}, },
@ -81,6 +86,17 @@ function singleSelect(Table, Radio) {
return _defaultColumns.concat(columns); return _defaultColumns.concat(columns);
}; };
_this.onRowClick = function (record, index, event) {
var _this$props = _this.props,
autoCheckedByClickRows = _this$props.autoCheckedByClickRows,
onRowClick = _this$props.onRowClick;
if (autoCheckedByClickRows) {
_this.onRadioChange('', record, index);
}
onRowClick && onRowClick(record, index, event);
};
_this.state = { _this.state = {
data: (0, _util.ObjectAssign)(props.data), data: (0, _util.ObjectAssign)(props.data),
selectedRowIndex: props.selectedRowIndex selectedRowIndex: props.selectedRowIndex
@ -110,6 +126,8 @@ function singleSelect(Table, Radio) {
SingleSelect.prototype.isArray = function isArray(o) { SingleSelect.prototype.isArray = function isArray(o) {
return Object.prototype.toString.call(o) == '[object Array]'; return Object.prototype.toString.call(o) == '[object Array]';
}; };
// 实现行点击时触发单选框勾选的需求
SingleSelect.prototype.render = function render() { SingleSelect.prototype.render = function render() {
var columns = this.props.columns; var columns = this.props.columns;
@ -117,14 +135,18 @@ function singleSelect(Table, Radio) {
return _react2["default"].createElement(Table, _extends({}, this.props, { return _react2["default"].createElement(Table, _extends({}, this.props, {
columns: this.getDefaultColumns(columns), columns: this.getDefaultColumns(columns),
data: data })); data: data,
onRowClick: this.onRowClick }));
}; };
return SingleSelect; return SingleSelect;
}(_react.Component), _class.defaultProps = { }(_react.Component), _class.propTypes = {
autoCheckedByClickRows: PropTypes.bool //行点击时,是否自动勾选单选框
}, _class.defaultProps = {
prefixCls: "u-table-single-select", prefixCls: "u-table-single-select",
getSelectedDataFunc: function getSelectedDataFunc() {}, getSelectedDataFunc: function getSelectedDataFunc() {},
selectedRowIndex: '' selectedRowIndex: '',
autoCheckedByClickRows: true
}, _temp; }, _temp;
} }
module.exports = exports["default"]; module.exports = exports["default"];

File diff suppressed because one or more lines are too long

1363
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -133,11 +133,6 @@ export default function multiSelect(Table, Checkbox) {
if(checkedAll){ if(checkedAll){
check = false; check = false;
}else{ }else{
// if(indeterminate){
// check = true;
// }else{
// check = true;
// }
check = true; check = true;
} }
let selectList = []; let selectList = [];
@ -209,10 +204,6 @@ export default function multiSelect(Table, Checkbox) {
getTreeNodeByFlag(node); getTreeNodeByFlag(node);
return res; return res;
} }
handleClick=()=>{
}
onCheckboxChange = (text, record, index) => () => { onCheckboxChange = (text, record, index) => () => {
let {data} = this.state; let {data} = this.state;
@ -282,7 +273,6 @@ export default function multiSelect(Table, Checkbox) {
{...attr} {...attr}
{...multiSelectConfig} {...multiSelectConfig}
checked={record._checked} checked={record._checked}
onClick={this.handleClick}
onChange={this.onCheckboxChange(text, record, index)} onChange={this.onCheckboxChange(text, record, index)}
/> />
} }

View File

@ -9,10 +9,14 @@ import {ObjectAssign} from './util';
export default function singleSelect(Table, Radio) { export default function singleSelect(Table, Radio) {
return class SingleSelect extends Component { return class SingleSelect extends Component {
static propTypes = {
autoCheckedByClickRows: PropTypes.bool, //行点击时,是否自动勾选单选框
};
static defaultProps = { static defaultProps = {
prefixCls: "u-table-single-select", prefixCls: "u-table-single-select",
getSelectedDataFunc:()=>{}, getSelectedDataFunc:()=>{},
selectedRowIndex: '' selectedRowIndex: '',
autoCheckedByClickRows: true
} }
constructor(props) { constructor(props) {
@ -44,6 +48,10 @@ export default function singleSelect(Table, Radio) {
return Object.prototype.toString.call(o)=='[object Array]'; return Object.prototype.toString.call(o)=='[object Array]';
} }
handleRadioClick = (e) => {
e.stopPropagation();
}
onRadioChange = (value, record, index) => { onRadioChange = (value, record, index) => {
let { selectedRowIndex } = this.state; let { selectedRowIndex } = this.state;
if(selectedRowIndex === index){ if(selectedRowIndex === index){
@ -69,6 +77,7 @@ export default function singleSelect(Table, Radio) {
className="table-radio" className="table-radio"
name="table-radio" name="table-radio"
selectedValue={selectedRowIndex} selectedValue={selectedRowIndex}
onClick={this.handleRadioClick}
onChange={value => this.onRadioChange(value, record, index)} onChange={value => this.onRadioChange(value, record, index)}
style={{width:'14px', height:'14px', display:'block', marginLeft:'4px'}}> style={{width:'14px', height:'14px', display:'block', marginLeft:'4px'}}>
<Radio value={index}/> <Radio value={index}/>
@ -77,6 +86,14 @@ export default function singleSelect(Table, Radio) {
}] }]
return _defaultColumns.concat(columns); return _defaultColumns.concat(columns);
} }
// 实现行点击时触发单选框勾选的需求
onRowClick = (record,index,event) =>{
let { autoCheckedByClickRows, onRowClick } = this.props;
if(autoCheckedByClickRows) {
this.onRadioChange('',record, index);
}
onRowClick && onRowClick(record,index,event);
}
render() { render() {
const {columns} = this.props; const {columns} = this.props;
@ -84,7 +101,8 @@ export default function singleSelect(Table, Radio) {
return <Table return <Table
{...this.props} {...this.props}
columns={this.getDefaultColumns(columns)} columns={this.getDefaultColumns(columns)}
data={data} /> data={data}
onRowClick={this.onRowClick}/>
} }
}; };
} }