合计高阶组件 by zhanghaoyu
This commit is contained in:
commit
e68606c04b
|
@ -12,19 +12,21 @@ import Animate from "bee-animate";
|
||||||
import Icon from "bee-icon";
|
import Icon from "bee-icon";
|
||||||
import Input from "bee-form-control";
|
import Input from "bee-form-control";
|
||||||
import Checkbox from "bee-checkbox";
|
import Checkbox from "bee-checkbox";
|
||||||
import Select from 'bee-select';
|
import Select from "bee-select";
|
||||||
import Popconfirm from "bee-popconfirm";
|
import Popconfirm from "bee-popconfirm";
|
||||||
import InputRender from "../../src/render/InputRender.js";
|
import InputRender from "../../src/render/InputRender.js";
|
||||||
|
import DateRender from "../../src/render/DateRender.js";
|
||||||
|
import SelectRender from "../../src/render/SelectRender.js";
|
||||||
|
|
||||||
//日期控件引入
|
//日期控件引入
|
||||||
import DatePicker from 'bee-datepicker';
|
import DatePicker from "bee-datepicker";
|
||||||
import MonthPicker,{ WeekPicker, RangePicker } from 'bee-datepicker';
|
import MonthPicker, { WeekPicker, RangePicker } from "bee-datepicker";
|
||||||
|
|
||||||
const format = 'YYYY-MM-DD';
|
const format = "YYYY-MM-DD";
|
||||||
const format2 = 'YYYY-MM';
|
const format2 = "YYYY-MM";
|
||||||
|
|
||||||
const dateInputPlaceholder = '选择日期';
|
const dateInputPlaceholder = "选择日期";
|
||||||
const dateInputPlaceholder2 = '选择年月';
|
const dateInputPlaceholder2 = "选择年月";
|
||||||
|
|
||||||
class Demo15 extends React.Component {
|
class Demo15 extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -63,12 +65,12 @@ class Demo15 extends React.Component {
|
||||||
title: "姓名",
|
title: "姓名",
|
||||||
dataIndex: "name",
|
dataIndex: "name",
|
||||||
key: "name",
|
key: "name",
|
||||||
width: "10%",
|
width: "100px",
|
||||||
render: (text, record, index) => (
|
render: (text, record, index) => (
|
||||||
<InputRender
|
<InputRender
|
||||||
value={text}
|
value={text}
|
||||||
isclickTrigger={true}
|
isclickTrigger={true}
|
||||||
onChange={this.onCellChange(index, "name")}
|
onChange={this.onInputChange(index, "name")}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -76,7 +78,7 @@ class Demo15 extends React.Component {
|
||||||
title: "年龄",
|
title: "年龄",
|
||||||
dataIndex: "age",
|
dataIndex: "age",
|
||||||
key: "age",
|
key: "age",
|
||||||
width: "10%",
|
width: "100px",
|
||||||
render: (text, record, index) => (
|
render: (text, record, index) => (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={record.age}
|
checked={record.age}
|
||||||
|
@ -88,13 +90,13 @@ class Demo15 extends React.Component {
|
||||||
title: "你懂的",
|
title: "你懂的",
|
||||||
dataIndex: "address",
|
dataIndex: "address",
|
||||||
key: "address",
|
key: "address",
|
||||||
width: "10%",
|
width: "200px",
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
<Select
|
<SelectRender
|
||||||
defaultValue="lucy"
|
isclickTrigger={true}
|
||||||
style={{ width: 100, marginRight: 6 }}
|
value="lucy"
|
||||||
onChange={this.handleChange}
|
onChange={this.onSelectChange}
|
||||||
>
|
>
|
||||||
<Option value="jack">boyuzhou</Option>
|
<Option value="jack">boyuzhou</Option>
|
||||||
<Option value="lucy">renhualiu</Option>
|
<Option value="lucy">renhualiu</Option>
|
||||||
|
@ -102,69 +104,59 @@ class Demo15 extends React.Component {
|
||||||
Disabled
|
Disabled
|
||||||
</Option>
|
</Option>
|
||||||
<Option value="yiminghe">yuzhao</Option>
|
<Option value="yiminghe">yuzhao</Option>
|
||||||
</Select>
|
</SelectRender>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ title: '日期', dataIndex: 'datepicker', key: 'datepicker', width: "10%",
|
{
|
||||||
render:()=>{
|
title: "日期",
|
||||||
return(
|
dataIndex: "datepicker",
|
||||||
<DatePicker
|
key: "datepicker",
|
||||||
|
width: "200px",
|
||||||
|
render: () => {
|
||||||
|
return (
|
||||||
|
<DatePicker
|
||||||
format={format}
|
format={format}
|
||||||
|
|
||||||
onSelect={this.onSelect}
|
onSelect={this.onSelect}
|
||||||
|
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
|
placeholder={dateInputPlaceholder}
|
||||||
placeholder = {dateInputPlaceholder}>
|
/>
|
||||||
</DatePicker>
|
);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ title: '年月', dataIndex: 'MonthPicker', key: 'MonthPicker', width: "10%",
|
{
|
||||||
render:()=>{
|
title: "年月",
|
||||||
return(
|
dataIndex: "MonthPicker",
|
||||||
<MonthPicker
|
key: "MonthPicker",
|
||||||
|
width: "200px",
|
||||||
|
render: () => {
|
||||||
|
return (
|
||||||
|
<MonthPicker
|
||||||
format={format2}
|
format={format2}
|
||||||
|
|
||||||
onSelect={this.onSelect}
|
onSelect={this.onSelect}
|
||||||
|
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
|
placeholder={dateInputPlaceholder2}
|
||||||
placeholder = {dateInputPlaceholder2}>
|
/>
|
||||||
</MonthPicker>
|
);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ title: '周', dataIndex: 'WeekPicker', key: 'WeekPicker', width: "10%",
|
{
|
||||||
render:()=>{
|
title: "周",
|
||||||
return(
|
dataIndex: "WeekPicker",
|
||||||
<WeekPicker placeholder="选择周"/>
|
key: "WeekPicker",
|
||||||
)
|
render: () => {
|
||||||
}
|
return <WeekPicker placeholder="选择周" />;
|
||||||
},
|
|
||||||
{ title: '日期范围', dataIndex: 'RangePicker', key: 'RangePicker', width: "10%",
|
|
||||||
render:()=>{
|
|
||||||
return(
|
|
||||||
<RangePicker
|
|
||||||
|
|
||||||
format={format}
|
|
||||||
|
|
||||||
onSelect={this.onSelect}
|
|
||||||
|
|
||||||
onChange={this.onChange}
|
|
||||||
|
|
||||||
placeholder={'选择年月'}
|
|
||||||
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
handleChange = value => {
|
|
||||||
console.log(`selected ${value}`);
|
onInputChange = (index, key) => {
|
||||||
|
return value => {
|
||||||
|
const dataSource = [...this.state.dataSource];
|
||||||
|
dataSource[index][key] = value;
|
||||||
|
this.setState({ dataSource });
|
||||||
|
};
|
||||||
};
|
};
|
||||||
onCheckChange = (index, key) => {
|
onCheckChange = (index, key) => {
|
||||||
return value => {
|
return value => {
|
||||||
|
@ -173,12 +165,8 @@ class Demo15 extends React.Component {
|
||||||
this.setState({ dataSource });
|
this.setState({ dataSource });
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
onCellChange = (index, key) => {
|
onSelectChange = value => {
|
||||||
return value => {
|
console.log(`selected ${value}`);
|
||||||
const dataSource = [...this.state.dataSource];
|
|
||||||
dataSource[index][key] = value;
|
|
||||||
this.setState({ dataSource });
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
onDelete = index => {
|
onDelete = index => {
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -212,13 +200,13 @@ class Demo15 extends React.Component {
|
||||||
</Animate>
|
</Animate>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
onSelect = (d) =>{
|
onSelect = d => {
|
||||||
console.log(d)
|
console.log(d);
|
||||||
};
|
};
|
||||||
|
|
||||||
onChange = (d) => {
|
onChange = d => {
|
||||||
console.log(d)
|
console.log(d);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -5,16 +5,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import React, { Component } from "react";
|
||||||
import React, { Component } from 'react';
|
import Table from "../../src";
|
||||||
import Table from '../../src';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const columns7 = [
|
const columns7 = [
|
||||||
{ title: "用户名", dataIndex: "a", key: "a"},
|
{ title: "用户名", dataIndex: "a", key: "a" },
|
||||||
{ id: "123", title: "性别", dataIndex: "b", key: "b"},
|
{ id: "123", title: "性别", dataIndex: "b", key: "b" },
|
||||||
{ title: "年龄", dataIndex: "c", key: "c"},
|
{ title: "年龄", dataIndex: "c", key: "c" },
|
||||||
{
|
{
|
||||||
title: "操作",
|
title: "操作",
|
||||||
dataIndex: "",
|
dataIndex: "",
|
||||||
|
@ -26,47 +23,41 @@ const columns7 = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const data7 = [
|
const data7 = [
|
||||||
{ a: "令狐冲", b: "男", c: 41, key: "1" },
|
{ a: "令狐冲", b: "01班", c: "文学系", key: "1" },
|
||||||
{ a: "杨过", b: "男", c: 67, key: "2" },
|
{ a: "杨过", b: "01班", c: "外语系", key: "2" },
|
||||||
{ a: "郭靖", b: "男", c: 25, key: "3" }
|
{ a: "郭靖", b: "02班", c: "美术系", key: "3" }
|
||||||
];
|
];
|
||||||
|
|
||||||
const columns7_1 = [
|
const columns7_1 = [
|
||||||
{ title: "用户名", dataIndex: "a", key: "a"},
|
{ title: "用户名", dataIndex: "a", key: "a" },
|
||||||
{ id: "123", title: "班级", dataIndex: "b", key: "b"},
|
{ id: "123", title: "班级", dataIndex: "b", key: "b" },
|
||||||
{ title: "系别", dataIndex: "c", key: "c"}
|
{ title: "系别", dataIndex: "c", key: "c" }
|
||||||
];
|
];
|
||||||
|
|
||||||
class Demo7 extends Component {
|
class Demo7 extends Component {
|
||||||
constructor(props){
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
children_data : []
|
children_data: []
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
rowclick = (record, index) => {
|
rowclick = (record, index) => {
|
||||||
console.log(record)
|
console.log(record);
|
||||||
console.log(index)
|
console.log(index);
|
||||||
if(record.a === '令狐冲'){
|
if (record.a === "令狐冲") {
|
||||||
this.setState({
|
this.setState({
|
||||||
children_data: [
|
children_data: [{ a: "令狐冲", b: "男", c: 41, key: "1" }]
|
||||||
{ a: "令狐冲", b: "01班", c: '文学系', key: "1" },
|
});
|
||||||
]
|
} else if (record.a === "杨过") {
|
||||||
})
|
|
||||||
}else if(record.a === '杨过'){
|
|
||||||
this.setState({
|
this.setState({
|
||||||
children_data: [
|
children_data: [{ a: "杨过", b: "男", c: 67, key: "2" }]
|
||||||
{ a: "杨过", b: "01班", c: '外语系', key: "2" },
|
});
|
||||||
]
|
} else if (record.a === "郭靖") {
|
||||||
})
|
|
||||||
}else if(record.a === '郭靖'){
|
|
||||||
this.setState({
|
this.setState({
|
||||||
children_data: [
|
children_data: [{ a: "郭靖", b: "男", c: 25, key: "3" }]
|
||||||
{ a: "郭靖", b: "02班", c: '美术系', key: "3" }
|
});
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -86,4 +77,4 @@ class Demo7 extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Demo7;
|
export default Demo7;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,67 @@
|
||||||
|
import React, { Component } from "react";
|
||||||
|
import Icon from "bee-icon";
|
||||||
|
import DatePicker from "bee-datepicker";
|
||||||
|
|
||||||
|
export default class DateRender extends Component {
|
||||||
|
state = {
|
||||||
|
value: this.props.value,
|
||||||
|
editable: false
|
||||||
|
};
|
||||||
|
handleChange = e => {
|
||||||
|
debugger;
|
||||||
|
const value = e.target.value;
|
||||||
|
this.setState({ value });
|
||||||
|
};
|
||||||
|
check = () => {
|
||||||
|
this.setState({ editable: false });
|
||||||
|
if (this.props.onChange) {
|
||||||
|
this.props.onChange(this.state.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
edit = () => {
|
||||||
|
this.setState({ editable: true });
|
||||||
|
};
|
||||||
|
handleKeydown = event => {
|
||||||
|
console.log(event.keyCode);
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
this.check();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
render() {
|
||||||
|
const { value, editable } = this.state;
|
||||||
|
let { isclickTrigger } = this.props;
|
||||||
|
let cellContent = "";
|
||||||
|
if (editable) {
|
||||||
|
cellContent = isclickTrigger ? (
|
||||||
|
<div className="editable-cell-input-wrapper">
|
||||||
|
<DatePicker onChange={this.handleChange} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="editable-cell-input-wrapper">
|
||||||
|
<DatePicker {...this.props} onChange={this.handleChange}/>
|
||||||
|
<Icon
|
||||||
|
type="uf-correct"
|
||||||
|
className="editable-cell-icon-check"
|
||||||
|
onClick={this.check}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
cellContent = isclickTrigger ? (
|
||||||
|
<div className="editable-cell-text-wrapper" onClick={this.edit}>
|
||||||
|
{value || " "}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="editable-cell-text-wrapper">
|
||||||
|
{value || " "}
|
||||||
|
<Icon
|
||||||
|
type="uf-pencil"
|
||||||
|
className="editable-cell-icon"
|
||||||
|
onClick={this.edit}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <div className="editable-cell">{cellContent}</div>;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ export default class InputRender extends Component {
|
||||||
editable: false
|
editable: false
|
||||||
};
|
};
|
||||||
handleChange = e => {
|
handleChange = e => {
|
||||||
const value = e.target.value;
|
const value = e;
|
||||||
this.setState({ value });
|
this.setState({ value });
|
||||||
};
|
};
|
||||||
check = () => {
|
check = () => {
|
||||||
|
@ -21,7 +21,6 @@ export default class InputRender extends Component {
|
||||||
this.setState({ editable: true });
|
this.setState({ editable: true });
|
||||||
};
|
};
|
||||||
handleKeydown = event => {
|
handleKeydown = event => {
|
||||||
console.log(event.keyCode);
|
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
this.check();
|
this.check();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
import React, { Component } from "react";
|
||||||
|
import Icon from "bee-icon";
|
||||||
|
import Select from "bee-select";
|
||||||
|
|
||||||
|
export default class SelectRender extends Component {
|
||||||
|
state = {
|
||||||
|
value: this.props.value,
|
||||||
|
editable: false
|
||||||
|
};
|
||||||
|
handleChange = e => {
|
||||||
|
const value = e;
|
||||||
|
let self = this;
|
||||||
|
if (self.props.onChange) {
|
||||||
|
self.props.onChange(value);
|
||||||
|
}
|
||||||
|
this.setState({ value: value });
|
||||||
|
setTimeout(function() {
|
||||||
|
self.setState({ editable: false });
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
check = () => {
|
||||||
|
this.setState({ editable: false });
|
||||||
|
if (this.props.onChange) {
|
||||||
|
this.props.onChange(this.state.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
edit = () => {
|
||||||
|
this.setState({ editable: true });
|
||||||
|
};
|
||||||
|
render() {
|
||||||
|
const { value, editable } = this.state;
|
||||||
|
let { isclickTrigger } = this.props;
|
||||||
|
let cellContent = "";
|
||||||
|
if (editable) {
|
||||||
|
cellContent = isclickTrigger ? (
|
||||||
|
<div className="editable-cell-input-wrapper">
|
||||||
|
<Select
|
||||||
|
{...this.props}
|
||||||
|
value={this.state.value}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
>
|
||||||
|
{this.props.children}
|
||||||
|
</Select>
|
||||||
|
<Icon
|
||||||
|
type="uf-correct"
|
||||||
|
className="editable-cell-icon-check"
|
||||||
|
onClick={this.check}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="editable-cell-input-wrapper">
|
||||||
|
<Select
|
||||||
|
{...this.props}
|
||||||
|
value={this.state.value}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
>
|
||||||
|
{this.props.children}
|
||||||
|
</Select>
|
||||||
|
<Icon
|
||||||
|
type="uf-correct"
|
||||||
|
className="editable-cell-icon-check"
|
||||||
|
onClick={this.check}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
cellContent = isclickTrigger ? (
|
||||||
|
<div className="editable-cell-text-wrapper" onClick={this.edit}>
|
||||||
|
{value || " "}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="editable-cell-text-wrapper">
|
||||||
|
{value || " "}
|
||||||
|
<Icon
|
||||||
|
type="uf-pencil"
|
||||||
|
className="editable-cell-icon"
|
||||||
|
onClick={this.edit}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <div className="editable-cell">{cellContent}</div>;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue