From c3bb62564ac1a106fc3e9e2fffe38f142e5e9909 Mon Sep 17 00:00:00 2001 From: wanghaoo Date: Mon, 19 Nov 2018 15:13:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9FnewMultiSelect=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/newMultiSelect.js | 134 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/lib/newMultiSelect.js diff --git a/src/lib/newMultiSelect.js b/src/lib/newMultiSelect.js new file mode 100644 index 0000000..72255e7 --- /dev/null +++ b/src/lib/newMultiSelect.js @@ -0,0 +1,134 @@ +import React, { Component } from "react"; +import Checkbox from 'bee-checkbox'; +import {ObjectAssign} from './util'; +/** + * 参数: 过滤表头 + * @param {*} Table + * @param {*} Checkbox + * @param {*} Popover + * @param {*} Icon + */ + +export default function newMultiSelect(Table, Checkbox) { + + return class NewMultiSelect extends Component { + static defaultProps = { + prefixCls: "u-table-mult-select" + } + + constructor(props) { + super(props); + let checkedAll = this.setChecked(props.data); + this.state = { + checkedAll, + data:ObjectAssign(props.data), + } + } + + componentWillReceiveProps(nextProps){ + if(this.props.data != nextProps.data){ + this.setState({ + data:ObjectAssign(nextProps.data), + checkedAll:this.setChecked(nextProps.data), + }) + } + } + + setChecked(data){ + let allCheck = true; + if(data){ + for (const da of data) { + if(!da._checked){ + allCheck = false; + break; + } + } + } + return allCheck; + } + + onAllCheckChange=()=>{ + let {data,checkedAll} = this.state; + let selectList = []; + let check = checkedAll?false:true; + data.forEach(item => { + item._checked = check; + if(item._checked){ + selectList.push(item); + } + }); + this.setState({ + checkedAll:check + }); + this.props.getSelectedDataFunc(selectList); + } + + handleClick=()=>{ + + } + + onCheckboxChange = (text, record, index) => () => { + let {data} = this.state; + let selectList = []; + record._checked = record._checked?false:true; + let checkedAll = true; + for(let i=0;i{ + if(da._checked){ + selectList.push(da); + } + }) + this.props.getSelectedDataFunc(selectList,record,index); + }; + + + + getDefaultColumns=(columns)=>{ + // let checkedAll = init?false:this.state.checkedAll; + let {checkedAll} = this.state; + let _defaultColumns =[{ + title: ( + + ), + key: "checkbox", + dataIndex: "checkbox", + fixed:"left", + width: 50, + render: (text, record, index) => { + let attr = {}; + record._disabled?attr.disabled = record._disabled:""; + return + } + }] + return _defaultColumns.concat(columns); + } + + render() { + const {columns} = this.props; + const {data} = this.state; + return + } + }; +} \ No newline at end of file