|
| 1 | +import React, { PureComponent, Fragment } from 'react'; |
| 2 | +import { connect } from 'dva'; |
| 3 | +import { Card, Form, Input, Button, Row, Col } from 'antd'; |
| 4 | +import StandardTable from '@/components/StandardTable'; |
| 5 | +import StandardQueryList from '@/components/StandardQueryList'; |
| 6 | +import PageHeaderWrapper from '@/components/PageHeaderWrapper'; |
| 7 | +import { formatFormValues, serializeSearchParam } from '@/utils/search'; |
| 8 | + |
| 9 | +// import styles from './AppList.less'; |
| 10 | + |
| 11 | +const FormItem = Form.Item; |
| 12 | + |
| 13 | +@connect(({ app, loading }) => ({ |
| 14 | + app, |
| 15 | + loading: loading.models.app, |
| 16 | +})) |
| 17 | +@Form.create() |
| 18 | +class AppList extends PureComponent { |
| 19 | + state = { |
| 20 | + selectedRows: [], |
| 21 | + formValues: {}, |
| 22 | + }; |
| 23 | + |
| 24 | + columns = [ |
| 25 | + { |
| 26 | + title: 'ID', |
| 27 | + dataIndex: 'id', |
| 28 | + sorter: true, |
| 29 | + }, |
| 30 | + { |
| 31 | + title: 'Code', |
| 32 | + dataIndex: 'code', |
| 33 | + }, |
| 34 | + { |
| 35 | + title: '名称', |
| 36 | + dataIndex: 'name', |
| 37 | + }, |
| 38 | + { |
| 39 | + title: '操作', |
| 40 | + render: (text, row) => ( |
| 41 | + <Fragment> |
| 42 | + <a onClick={() => this.handleDeleteApp(true, row)}>删除</a> |
| 43 | + </Fragment> |
| 44 | + ), |
| 45 | + }, |
| 46 | + ]; |
| 47 | + |
| 48 | + componentDidMount() { |
| 49 | + const { dispatch } = this.props; |
| 50 | + |
| 51 | + dispatch({ |
| 52 | + type: 'app/search', |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + handleDeleteApp() { |
| 57 | + const { dispatch } = this.props; |
| 58 | + |
| 59 | + dispatch({ |
| 60 | + type: 'app/delete', |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | + handleSelectRows(rows) { |
| 65 | + this.setState({ |
| 66 | + selectedRows: rows || [], |
| 67 | + }); |
| 68 | + } |
| 69 | + |
| 70 | + handleStandardTableChange(pagination, filters, sorter) { |
| 71 | + const { dispatch } = this.props; |
| 72 | + const { formValues } = this.state; |
| 73 | + |
| 74 | + const params = serializeSearchParam(pagination, formValues, filters, sorter); |
| 75 | + |
| 76 | + dispatch({ |
| 77 | + type: 'app/search', |
| 78 | + payload: params, |
| 79 | + }); |
| 80 | + } |
| 81 | + |
| 82 | + handleFormReset() { |
| 83 | + const { form, dispatch } = this.props; |
| 84 | + form.resetFields(); |
| 85 | + this.setState({ |
| 86 | + formValues: {}, |
| 87 | + }); |
| 88 | + dispatch({ |
| 89 | + type: 'app/search', |
| 90 | + payload: {}, |
| 91 | + }); |
| 92 | + } |
| 93 | + |
| 94 | + handleSearch() { |
| 95 | + const { dispatch, form } = this.props; |
| 96 | + |
| 97 | + form.validateFields((err, fieldsValue) => { |
| 98 | + if (err) return; |
| 99 | + |
| 100 | + const values = formatFormValues(fieldsValue); |
| 101 | + |
| 102 | + this.setState({ |
| 103 | + formValues: values, |
| 104 | + }); |
| 105 | + |
| 106 | + dispatch({ |
| 107 | + type: 'app/search', |
| 108 | + payload: { |
| 109 | + filter: JSON.stringify(values), |
| 110 | + }, |
| 111 | + }); |
| 112 | + }); |
| 113 | + } |
| 114 | + |
| 115 | + renderQueryForm() { |
| 116 | + const { |
| 117 | + form: { getFieldDecorator }, |
| 118 | + } = this.props; |
| 119 | + |
| 120 | + return ( |
| 121 | + <Form layout="inline"> |
| 122 | + <Row gutter={{ md: 8, lg: 24, xl: 48 }}> |
| 123 | + <Col md={8} sm={24}> |
| 124 | + <FormItem label="应用方 ID"> |
| 125 | + {getFieldDecorator('EQ_id')(<Input placeholder="请输入 ID" />)} |
| 126 | + </FormItem> |
| 127 | + </Col> |
| 128 | + <Col md={8} sm={24}> |
| 129 | + <FormItem label="应用方 Code"> |
| 130 | + {getFieldDecorator('EQ_code')(<Input placeholder="请输入 Code,精确查询" />)} |
| 131 | + </FormItem> |
| 132 | + </Col> |
| 133 | + <Col md={8} sm={24}> |
| 134 | + <FormItem label="应用方名称"> |
| 135 | + {getFieldDecorator('LIKE_name')(<Input placeholder="请输入名称,支持模糊查询" />)} |
| 136 | + </FormItem> |
| 137 | + </Col> |
| 138 | + </Row> |
| 139 | + </Form> |
| 140 | + ); |
| 141 | + } |
| 142 | + |
| 143 | + render() { |
| 144 | + const { |
| 145 | + app: { data }, |
| 146 | + loading, |
| 147 | + } = this.props; |
| 148 | + const { selectedRows } = this.state; |
| 149 | + |
| 150 | + return ( |
| 151 | + <PageHeaderWrapper |
| 152 | + title="应用方列表" |
| 153 | + content="使用鉴权系统的相关系统,所有的资源、角色和分组都必须属于某个应用方。" |
| 154 | + > |
| 155 | + <Card bordered={false}> |
| 156 | + <StandardQueryList |
| 157 | + form={this.renderQueryForm()} |
| 158 | + leftOperators={ |
| 159 | + <Fragment> |
| 160 | + <Button icon="plus" type="primary"> |
| 161 | + 新建 |
| 162 | + </Button> |
| 163 | + {selectedRows.length > 0 && ( |
| 164 | + <span> |
| 165 | + <Button>批量删除</Button> |
| 166 | + </span> |
| 167 | + )} |
| 168 | + </Fragment> |
| 169 | + } |
| 170 | + rightOperators={ |
| 171 | + <Fragment> |
| 172 | + <Button icon="close" onClick={() => this.handleFormReset()}> |
| 173 | + 重置 |
| 174 | + </Button> |
| 175 | + <Button icon="search" type="primary" onClick={() => this.handleSearch()}> |
| 176 | + 查询 |
| 177 | + </Button> |
| 178 | + </Fragment> |
| 179 | + } |
| 180 | + table={ |
| 181 | + <StandardTable |
| 182 | + selectedRows={selectedRows} |
| 183 | + loading={loading} |
| 184 | + data={data} |
| 185 | + rowKey="id" |
| 186 | + columns={this.columns} |
| 187 | + onSelectRow={rows => this.handleSelectRows(rows)} |
| 188 | + onChange={(...args) => this.handleStandardTableChange(...args)} |
| 189 | + /> |
| 190 | + } |
| 191 | + /> |
| 192 | + </Card> |
| 193 | + </PageHeaderWrapper> |
| 194 | + ); |
| 195 | + } |
| 196 | +} |
| 197 | + |
| 198 | +export default AppList; |
0 commit comments