qiqiboy / react-antd-formutil Goto Github PK
View Code? Open in Web Editor NEWHappy to use react-formutil in the project based on ant-design ^_^
Home Page: http://github.boy.im/react-antd-formutil/demo/
License: MIT License
Happy to use react-formutil in the project based on ant-design ^_^
Home Page: http://github.boy.im/react-antd-formutil/demo/
License: MIT License
我在使用 mobx 配合使用 withForm 装饰器的时候,
定义了两个 @observable 属性,
在 <Form />
组件中使用的 @observable 属性 改变,会触发 rerender,
但是在 <Table />
组件中使用的 @observable 属性 改变,不会触发 rerender
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {observer} from 'mobx-react';
import {observable, action} from 'mobx';
import { withForm, FormItem } from 'react-antd-formutil';
import { Table, Form, Input, Checkbox, DatePicker, Button, AutoComplete, Select, Row, Col } from 'antd';
import Content from 'components/Layout/Content';
import Card from 'components/Layout/Card';
import { formRowLeftLayout, formRowRightLayout, formItemLayout, selectOption } from 'utils/config/form';
import './style.scss';
const columns = [{
title: '账户ID',
dataIndex: 'accountNumber',
key: 'accountNumber',
}, {
title: '账户名称',
dataIndex: 'accountName',
key: 'accountName',
}, {
title: '账户类别',
dataIndex: 'accountType',
key: 'accountType',
}, {
title: '账户别名',
dataIndex: 'accountAlias',
key: 'accountAlias',
}, {
title: '操作',
dataIndex: 'option',
key: 'option',
render: option => (
<span>
<Button> 查看详情 </Button>
</span>
),
}];
const accountList = [{
"accountNumber": "U124514251",
"accountName": "青劲有限公司1",
"accountAlias": "曼妥思",
"accountType": "STL-Master",
"slaveAccount": "L123123",
"accountStatus": true
},{
"accountNumber": "U124514252",
"accountName": "青劲有限公司2",
"accountAlias": "曼妥思",
"accountType": "STL-Master",
"slaveAccount": "L123123",
"accountStatus": true
},{
"accountNumber": "U124514253",
"accountName": "青劲有限公司3",
"accountAlias": "曼妥思",
"accountType": "STL-Master",
"slaveAccount": "L123123",
"accountStatus": true
}]
@observer
@withForm
export default class AccountSetting extends Component {
static propTypes = {
$formutil: PropTypes.object
};
@observable acDataSource = [];
@observable selectedRowKeys = [];
submit = ev => {
ev.preventDefault();
const { $invalid, $batchDirty, $params } = this.props.$formutil;
console.info($params);
if ($invalid) {
$batchDirty(true);
} else {
// submit data
}
};
@action
onSelectChange = (selectedRowKeys) => {
console.info('onSelectChange==>', this.selectedRowKeys === selectedRowKeys)
this.selectedRowKeys = selectedRowKeys;
}
render() {
console.info('this.selectedRowKeys', this.selectedRowKeys);
const rowSelection = {
selectedRowKeys: this.selectedRowKeys.slice(),
onChange: this.onSelectChange,
};
return (
<Content className="p-accset">
<Card.Title>账户别名</Card.Title>
<Card>
<Form onSubmit={this.submit}>
<Row style={{ height: '65px' }}>
<Col {...formRowLeftLayout}>
<FormItem name="accountID" itemProps={{ ...formItemLayout, label: "账户ID" }} required>
<AutoComplete
dataSource={this.acDataSource}
onSearch={value =>
this.acDataSource = !value ? [] : [value, value + value, value + value + value]
}
placeholder="input here"
/>
</FormItem>
</Col>
<Col {...formRowRightLayout}>
<FormItem name="accountName" itemProps={{ ...formItemLayout, label: "账户名称" }} required>
<AutoComplete
dataSource={this.acDataSource}
onSearch={value =>
this.acDataSource = !value ? [] : [value, value + value, value + value + value]
}
placeholder="input here"
/>
</FormItem>
</Col>
</Row>
<Row style={{ height: '65px' }}>
<Col {...formRowLeftLayout}>
<FormItem name="accountType" itemProps={{ ...formItemLayout, label: "账户类别" }} required>
<Select
showSearch
style={{ width: "100%" }}
optionFilterProp="children"
filterOption={(input, option) =>
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
placeholder="选择类型">
{selectOption}
</Select>
</FormItem>
</Col>
<Col {...formRowRightLayout}>
<FormItem name="accountSubName" itemProps={{ ...formItemLayout, label: "账户别名" }} required>
<AutoComplete
dataSource={this.acDataSource}
onSearch={value =>
this.acDataSource = !value ? [] : [value, value + value, value + value + value]
}
placeholder="input here"
/>
</FormItem>
</Col>
</Row>
<Row>
<Button style={{ marginTop: '10px', display: 'block' }} htmlType="submit" type="primary">
查询
</Button>
</Row>
</Form>
</Card>
<Card>
<Button style={{ marginBottom: '20px', display: 'block' }} type="primary">
批量命名
</Button>
<Table
rowSelection={rowSelection}
columns={columns}
dataSource={accountList}
pagination={false}
/>
</Card>
</Content>
);
}
}
如果项目中使用了babel-plugin-import
插件,请参考在生产环境(NODE_ENV==='production')部分组件调用有异常?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.