Merge branch 'lcj-demo-50x'
This commit is contained in:
commit
48f821a3bf
|
@ -5,82 +5,96 @@
|
||||||
* @description 可以对行进行编辑的表格
|
* @description 可以对行进行编辑的表格
|
||||||
* demo0501
|
* demo0501
|
||||||
*/
|
*/
|
||||||
import React, { Component, PureComponent } from "react";
|
import React, { Component } from "react";
|
||||||
import Table from "../../src";
|
import Table from "../../src";
|
||||||
import { Select, Form, FormControl, Button, Icon, Tooltip } from "tinper-bee";
|
import { Select, Form, FormControl, Button, Icon, Tooltip } from "tinper-bee";
|
||||||
const Option = Select.Option;
|
const Option = Select.Option;
|
||||||
import { RefTreeWithInput } from "ref-tree";
|
import { RefTreeWithInput } from "ref-tree";
|
||||||
|
|
||||||
function handleFormValueChange(WarpCompProps, field, allFields) {
|
class StringEditCell extends Component {
|
||||||
const { onChange, throwError } = WarpCompProps;
|
constructor(props, context) {
|
||||||
if (field.value === "") return throwError && throwError(true);
|
super(props);
|
||||||
throwError && throwError(false);
|
this.state = {
|
||||||
onChange && onChange(field.value);
|
value: props.value
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const StringEditCell = Form.createForm({
|
componentWillReceiveProps(nextProps) {
|
||||||
onValuesChange: handleFormValueChange
|
if (!nextProps.editable) {
|
||||||
})(PureStringEditCell);
|
this.setState({ value: nextProps.value });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function PureStringEditCell(props) {
|
handleChange = value => {
|
||||||
const { getFieldProps, getFieldError } = props.form;
|
const { onChange, throwError } = this.props;
|
||||||
const { value, editable, required } = props;
|
if (value === "") {
|
||||||
let cls = "editable-cell-input-wrapper";
|
throwError && throwError(true);
|
||||||
if (required) cls += " required";
|
} else {
|
||||||
if (getFieldError("value")) cls += " verify-cell";
|
throwError && throwError(false);
|
||||||
return editable ? (
|
}
|
||||||
<div className="editable-cell">
|
this.setState({ value });
|
||||||
<div className={cls}>
|
onChange && onChange(value);
|
||||||
<FormControl
|
};
|
||||||
{...getFieldProps("value", {
|
|
||||||
initialValue: value,
|
render() {
|
||||||
validateTrigger: "onBlur",
|
const { editable, required, colName } = this.props;
|
||||||
rules: [
|
const { value } = this.state;
|
||||||
{
|
let cls = "editable-cell-input-wrapper";
|
||||||
required: true,
|
if (required) cls += " required";
|
||||||
message: (
|
if (value === "") cls += " verify-cell";
|
||||||
<Tooltip
|
return editable ? (
|
||||||
inverse
|
<div className="editable-cell">
|
||||||
className="u-editable-table-tp"
|
<div className={cls}>
|
||||||
placement="bottom"
|
<FormControl value={value} onChange={this.handleChange} />
|
||||||
overlay={
|
<span className="error">
|
||||||
<div className="tp-content">
|
{value === "" ? (
|
||||||
{"请输入" + props.colName}
|
<Tooltip
|
||||||
</div>
|
inverse
|
||||||
}
|
className="u-editable-table-tp"
|
||||||
>
|
placement="bottom"
|
||||||
<Icon className="uf-exc-t required-icon" />
|
overlay={<div className="tp-content">{"请输入" + colName}</div>}
|
||||||
</Tooltip>
|
>
|
||||||
)
|
<Icon className="uf-exc-t required-icon" />
|
||||||
}
|
</Tooltip>
|
||||||
]
|
) : null}
|
||||||
})}
|
</span>
|
||||||
/>
|
</div>
|
||||||
<span className="error">{getFieldError("value")}</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
) : (
|
||||||
) : (
|
value || " "
|
||||||
value || " "
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SELECT_SOURCE = ["男", "女"];
|
const SELECT_SOURCE = ["男", "女"];
|
||||||
|
|
||||||
class SelectEditCell extends PureComponent {
|
class SelectEditCell extends Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
value: props.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (!nextProps.editable) {
|
||||||
|
this.setState({ value: nextProps.value });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSelect = value => {
|
handleSelect = value => {
|
||||||
|
this.setState({ value });
|
||||||
this.props.onChange && this.props.onChange(value);
|
this.props.onChange && this.props.onChange(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { value, editable } = this.props;
|
const { editable } = this.props;
|
||||||
|
const { value } = this.state;
|
||||||
|
let cls = "editable-cell-input-wrapper";
|
||||||
return editable ? (
|
return editable ? (
|
||||||
<div className="editable-cell">
|
<div className="editable-cell">
|
||||||
<div className="editable-cell-input-wrapper">
|
<div className={cls}>
|
||||||
<Select value={this.props.value} onSelect={this.handleSelect}>
|
<Select value={value} onSelect={this.handleSelect}>
|
||||||
{SELECT_SOURCE.map((item, index) => (
|
{SELECT_SOURCE.map((item, index) => (
|
||||||
<Option key={index} value={item}>
|
<Option key={index} value={item}>
|
||||||
{item}
|
{item}
|
||||||
|
@ -252,18 +266,29 @@ const option = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const RefEditCell = Form.createForm()(
|
const RefEditCell = Form.createForm()(
|
||||||
class RefComponentWarpper extends PureComponent {
|
class RefComponentWarpper extends Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
value: props.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (!nextProps.editable) {
|
||||||
|
this.setState({ value: nextProps.value });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSelect = values => {
|
handleSelect = values => {
|
||||||
|
this.setState({ value: values[0] });
|
||||||
this.props.onChange && this.props.onChange(values[0]);
|
this.props.onChange && this.props.onChange(values[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { getFieldProps, getFieldError } = this.props.form;
|
const { getFieldProps, getFieldError } = this.props.form;
|
||||||
const { value, editable, required } = this.props;
|
const { editable, required } = this.props;
|
||||||
|
const { value } = this.state;
|
||||||
let cls = "editable-cell-input-wrapper";
|
let cls = "editable-cell-input-wrapper";
|
||||||
if (required) cls += " required";
|
if (required) cls += " required";
|
||||||
if (getFieldError("refValue")) cls += " verify-cell";
|
if (getFieldError("refValue")) cls += " verify-cell";
|
||||||
|
@ -428,7 +453,14 @@ class Demo0501 extends Component {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
this.originData = {};
|
this.state = {
|
||||||
|
dataSource: dataSource,
|
||||||
|
editingRowsMap: {},
|
||||||
|
currentIndex: null,
|
||||||
|
errorEditFlag: false
|
||||||
|
};
|
||||||
|
|
||||||
|
this.dataBuffer = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
edit = index => () => {
|
edit = index => () => {
|
||||||
|
@ -436,17 +468,15 @@ class Demo0501 extends Component {
|
||||||
let editingRowsMap = { ...this.state.editingRowsMap };
|
let editingRowsMap = { ...this.state.editingRowsMap };
|
||||||
editingRowsMap[index] = index.toString();
|
editingRowsMap[index] = index.toString();
|
||||||
// 最好使用深复制
|
// 最好使用深复制
|
||||||
this.originData[index] = { ...this.state.dataSource[index] };
|
this.dataBuffer[index] = { ...this.state.dataSource[index] };
|
||||||
this.setState({ editingRowsMap });
|
this.setState({ editingRowsMap });
|
||||||
};
|
};
|
||||||
|
|
||||||
abortEdit = index => () => {
|
abortEdit = index => () => {
|
||||||
let editingRowsMap = { ...this.state.editingRowsMap };
|
let editingRowsMap = { ...this.state.editingRowsMap };
|
||||||
let dataSource = [...this.state.dataSource];
|
|
||||||
dataSource[index] = this.originData[index];
|
|
||||||
delete editingRowsMap[index];
|
delete editingRowsMap[index];
|
||||||
delete this.originData[index];
|
delete this.dataBuffer[index];
|
||||||
this.setState({ editingRowsMap, dataSource });
|
this.setState({ editingRowsMap });
|
||||||
};
|
};
|
||||||
|
|
||||||
delete = index => () => {
|
delete = index => () => {
|
||||||
|
@ -462,13 +492,13 @@ class Demo0501 extends Component {
|
||||||
if (this.state.errorEditFlag) return;
|
if (this.state.errorEditFlag) return;
|
||||||
let editingRowsMap = { ...this.state.editingRowsMap };
|
let editingRowsMap = { ...this.state.editingRowsMap };
|
||||||
delete editingRowsMap[index];
|
delete editingRowsMap[index];
|
||||||
this.setState({ editingRowsMap });
|
let dataSource = [...this.state.dataSource];
|
||||||
|
dataSource[index] = { ...this.dataBuffer[index] };
|
||||||
|
this.setState({ editingRowsMap, dataSource });
|
||||||
};
|
};
|
||||||
|
|
||||||
onCellChange = (index, key) => value => {
|
onCellChange = (index, key) => value => {
|
||||||
let dataSource = [...this.state.dataSource];
|
this.dataBuffer[index][key] = value;
|
||||||
dataSource[index][key] = value;
|
|
||||||
this.setState({ dataSource });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
throwError = isError => {
|
throwError = isError => {
|
||||||
|
|
|
@ -5,15 +5,24 @@
|
||||||
* @description 以行内编辑形式对全表数据进行编辑
|
* @description 以行内编辑形式对全表数据进行编辑
|
||||||
* demo0505
|
* demo0505
|
||||||
*/
|
*/
|
||||||
import React, { Component, PureComponent } from "react";
|
import React, { Component } from "react";
|
||||||
import Table from "../../src";
|
import Table from "../../src";
|
||||||
import { Select, Form, FormControl, Button, Icon, Tooltip } from "tinper-bee";
|
import { Select, Form, FormControl, Button, Icon, Tooltip } from "tinper-bee";
|
||||||
const Option = Select.Option;
|
const Option = Select.Option;
|
||||||
import { RefTreeWithInput } from "ref-tree";
|
import { RefTreeWithInput } from "ref-tree";
|
||||||
|
|
||||||
class StringEditCell extends PureComponent {
|
class StringEditCell extends Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
value: props.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (!nextProps.editable) {
|
||||||
|
this.setState({ value: nextProps.value });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange = value => {
|
handleChange = value => {
|
||||||
|
@ -23,11 +32,13 @@ class StringEditCell extends PureComponent {
|
||||||
} else {
|
} else {
|
||||||
throwError && throwError(false);
|
throwError && throwError(false);
|
||||||
}
|
}
|
||||||
|
this.setState({ value });
|
||||||
onChange && onChange(value);
|
onChange && onChange(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { value, editable, required, colName, isEdited } = this.props;
|
const { editable, required, colName, isEdited } = this.props;
|
||||||
|
const { value } = this.state;
|
||||||
let cls = "editable-cell-input-wrapper";
|
let cls = "editable-cell-input-wrapper";
|
||||||
if (required) cls += " required";
|
if (required) cls += " required";
|
||||||
if (value === "") cls += " verify-cell";
|
if (value === "") cls += " verify-cell";
|
||||||
|
@ -58,23 +69,34 @@ class StringEditCell extends PureComponent {
|
||||||
|
|
||||||
const SELECT_SOURCE = ["男", "女"];
|
const SELECT_SOURCE = ["男", "女"];
|
||||||
|
|
||||||
class SelectEditCell extends PureComponent {
|
class SelectEditCell extends Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
value: props.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (!nextProps.editable) {
|
||||||
|
this.setState({ value: nextProps.value });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSelect = value => {
|
handleSelect = value => {
|
||||||
|
this.setState({ value });
|
||||||
this.props.onChange && this.props.onChange(value);
|
this.props.onChange && this.props.onChange(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { value, editable, isEdited } = this.props;
|
const { editable, isEdited } = this.props;
|
||||||
|
const { value } = this.state;
|
||||||
let cls = "editable-cell-input-wrapper";
|
let cls = "editable-cell-input-wrapper";
|
||||||
if (isEdited) cls += " edited";
|
if (isEdited) cls += " edited";
|
||||||
return editable ? (
|
return editable ? (
|
||||||
<div className="editable-cell">
|
<div className="editable-cell">
|
||||||
<div className={cls}>
|
<div className={cls}>
|
||||||
<Select value={this.props.value} onSelect={this.handleSelect}>
|
<Select value={value} onSelect={this.handleSelect}>
|
||||||
{SELECT_SOURCE.map((item, index) => (
|
{SELECT_SOURCE.map((item, index) => (
|
||||||
<Option key={index} value={item}>
|
<Option key={index} value={item}>
|
||||||
{item}
|
{item}
|
||||||
|
@ -246,18 +268,29 @@ const option = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const RefEditCell = Form.createForm()(
|
const RefEditCell = Form.createForm()(
|
||||||
class RefComponentWarpper extends PureComponent {
|
class RefComponentWarpper extends Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
value: props.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (!nextProps.editable) {
|
||||||
|
this.setState({ value: nextProps.value });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSelect = values => {
|
handleSelect = values => {
|
||||||
|
this.setState({ value: values[0] });
|
||||||
this.props.onChange && this.props.onChange(values[0]);
|
this.props.onChange && this.props.onChange(values[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { getFieldProps, getFieldError } = this.props.form;
|
const { getFieldProps, getFieldError } = this.props.form;
|
||||||
const { value, editable, required, isEdited } = this.props;
|
const { editable, required, isEdited } = this.props;
|
||||||
|
const { value } = this.state;
|
||||||
let cls = "editable-cell-input-wrapper";
|
let cls = "editable-cell-input-wrapper";
|
||||||
if (required) cls += " required";
|
if (required) cls += " required";
|
||||||
if (getFieldError("refValue")) cls += " verify-cell";
|
if (getFieldError("refValue")) cls += " verify-cell";
|
||||||
|
@ -420,7 +453,7 @@ class Demo0505 extends Component {
|
||||||
];
|
];
|
||||||
|
|
||||||
// 用于记录数据是否被修改
|
// 用于记录数据是否被修改
|
||||||
dataSource.forEach(item => item.isEdited = {});
|
dataSource.forEach(item => (item.isEdited = {}));
|
||||||
this.state = {
|
this.state = {
|
||||||
dataSource: dataSource,
|
dataSource: dataSource,
|
||||||
isEditingAll: false,
|
isEditingAll: false,
|
||||||
|
@ -429,36 +462,38 @@ class Demo0505 extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
// 用于记录编辑前数据
|
// 用于记录编辑前数据
|
||||||
this.originData = [];
|
this.dataBuffer = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
edit = () => {
|
edit = () => {
|
||||||
this.originData = [];
|
this.dataBuffer = [];
|
||||||
// 最好使用深复制
|
// 最好使用深复制
|
||||||
this.state.dataSource.forEach(item => this.originData.push({ ...item }));
|
this.state.dataSource.forEach((item, index) => {
|
||||||
|
this.dataBuffer.push({ ...item });
|
||||||
|
});
|
||||||
this.setState({ isEditingAll: true });
|
this.setState({ isEditingAll: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
abortEdit = () => {
|
abortEdit = () => {
|
||||||
this.originData.forEach(item => item.isEdited = {});
|
let originData = [...this.state.dataSource];
|
||||||
|
originData.forEach(item => (item.isEdited = {}));
|
||||||
this.setState({
|
this.setState({
|
||||||
isEditingAll: false,
|
isEditingAll: false,
|
||||||
dataSource: [...this.originData]
|
dataSource: originData
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
commitChange = () => {
|
commitChange = () => {
|
||||||
if (this.state.errorEditFlag) return;
|
if (this.state.errorEditFlag) return;
|
||||||
let dataSource = [...this.state.dataSource];
|
const newData = this.dataBuffer.map(item => {
|
||||||
dataSource.forEach(item => item.isEdited = {});
|
return Object.assign({}, item, { isEdited: {} });
|
||||||
this.setState({ isEditingAll: false });
|
});
|
||||||
|
this.setState({ isEditingAll: false, dataSource: newData });
|
||||||
};
|
};
|
||||||
|
|
||||||
onCellChange = (index, key) => value => {
|
onCellChange = (index, key) => value => {
|
||||||
let dataSource = [...this.state.dataSource];
|
this.dataBuffer[index][key] = value;
|
||||||
dataSource[index][key] = value;
|
this.dataBuffer[index].isEdited[key] = true;
|
||||||
dataSource[index].isEdited[key] = true;
|
|
||||||
this.setState({ dataSource }, () => console.table(this.originData));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
throwError = isError => {
|
throwError = isError => {
|
||||||
|
@ -466,11 +501,6 @@ class Demo0505 extends Component {
|
||||||
this.setState({ errorEditFlag: isError });
|
this.setState({ errorEditFlag: isError });
|
||||||
};
|
};
|
||||||
|
|
||||||
setEditedRowClass = (record, index, indent) => {
|
|
||||||
if (Object.keys(record.isEdited).length > 0) return "u-row-select";
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { dataSource, isEditingAll } = this.state;
|
const { dataSource, isEditingAll } = this.state;
|
||||||
const columns = this.columns;
|
const columns = this.columns;
|
||||||
|
@ -496,7 +526,7 @@ class Demo0505 extends Component {
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Table data={dataSource} columns={columns} height={40} rowClassName={this.setEditedRowClass} />
|
<Table data={dataSource} columns={columns} height={40} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue