Giter Club home page Giter Club logo

react-antd-formutil's People

Contributors

qiqiboy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-antd-formutil's Issues

使用 mobx 配合使用 withForm 装饰器的时候,@observable 属性 改变,不会触发 rerender

我在使用 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>
        );
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.