From d85cb94583023fb4b950de7411e1de60ae6716d3 Mon Sep 17 00:00:00 2001 From: vapao Date: Fri, 27 Nov 2020 16:34:48 +0800 Subject: [PATCH] style migrate v3 --- spug_web/src/pages/system/account/Form.js | 115 +++++++++------------ spug_web/src/pages/system/account/Table.js | 62 ++++++----- spug_web/src/pages/system/account/index.js | 27 ++--- spug_web/src/pages/system/account/store.js | 11 +- 4 files changed, 97 insertions(+), 118 deletions(-) diff --git a/spug_web/src/pages/system/account/Form.js b/spug_web/src/pages/system/account/Form.js index 07aa747..c342bf9 100644 --- a/spug_web/src/pages/system/account/Form.js +++ b/spug_web/src/pages/system/account/Form.js @@ -3,32 +3,27 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { observer } from 'mobx-react'; -import { Modal, Form, Select, Input, message, Col } from 'antd'; +import { Modal, Form, Select, Input, message } from 'antd'; import http from 'libs/http'; import store from './store'; import roleStore from '../role/store'; import { Link } from "react-router-dom"; -@observer -class ComForm extends React.Component { - constructor(props) { - super(props); - this.state = { - loading: false - } - } +export default observer(function () { + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); - componentDidMount() { + useEffect(() => { if (roleStore.records.length === 0) { roleStore.fetchRecords() } - } + }, []) - handleSubmit = () => { - this.setState({loading: true}); - const formData = this.props.form.getFieldsValue(); + function handleSubmit() { + setLoading(true); + const formData = form.getFieldsValue(); let request; if (store.record.id) { formData['id'] = store.record.id; @@ -40,57 +35,43 @@ class ComForm extends React.Component { message.success('操作成功'); store.formVisible = false; store.fetchRecords() - }, () => this.setState({loading: false})) - }; - - render() { - const info = store.record; - const {getFieldDecorator} = this.props.form; - return ( - store.formVisible = false} - confirmLoading={this.state.loading} - onOk={this.handleSubmit}> -
- - {getFieldDecorator('username', {initialValue: info['username']})( - - )} - - - {getFieldDecorator('nickname', {initialValue: info['nickname']})( - - )} - - {info.id === undefined && ( - - {getFieldDecorator('password')( - - )} - - )} - - - {getFieldDecorator('role_id', {initialValue: info['role_id']})( - - )} - - - 新建角色 - - -
-
- ) + }, () => setLoading(false)) } -} -export default Form.create()(ComForm) + return ( + store.formVisible = false} + confirmLoading={loading} + onOk={handleSubmit}> +
+ + + + + + + {store.record.id === undefined && ( + + + + )} + + + + + + 新建角色 + + +
+
+ ) +}) diff --git a/spug_web/src/pages/system/account/Table.js b/spug_web/src/pages/system/account/Table.js index 59896bb..18a935b 100644 --- a/spug_web/src/pages/system/account/Table.js +++ b/spug_web/src/pages/system/account/Table.js @@ -4,10 +4,10 @@ * Released under the AGPL-3.0 License. */ import React from 'react'; -import {observer} from 'mobx-react'; -import {Table, Divider, Modal, Badge, message, Form, Input} from 'antd'; -import {LinkButton} from 'components'; -import ComForm from './Form'; +import { observer } from 'mobx-react'; +import { ExclamationCircleOutlined, PlusOutlined } from '@ant-design/icons'; +import { Divider, Form, Radio, Modal, Button, Badge, message, Input } from 'antd'; +import { LinkButton, TableCard } from 'components'; import http from 'libs/http'; import store from './store'; @@ -19,16 +19,12 @@ class ComTable extends React.Component { password: '' } } + componentDidMount() { store.fetchRecords() } columns = [{ - title: '序号', - key: 'series', - render: (_, __, index) => index + 1, - width: 80 - }, { title: '登录名', dataIndex: 'username', }, { @@ -77,9 +73,9 @@ class ComTable extends React.Component { handleReset = (info) => { Modal.confirm({ - icon: 'exclamation-circle', + icon: , title: '重置登录密码', - content:
+ content: this.setState({password: val.target.value})}/> @@ -106,29 +102,29 @@ class ComTable extends React.Component { }; render() { - let data = store.records; - if (store.f_name) { - data = data.filter(item => item['username'].toLowerCase().includes(store.f_name.toLowerCase())) - } - if (store.f_status) { - data = data.filter(item => String(item['is_active']) === store.f_status) - } return ( - - `共 ${total} 条`, - pageSizeOptions: ['10', '20', '50', '100'] - }} - columns={this.columns}/> - {store.formVisible && } - + } onClick={() => store.showForm()}>新建, + store.f_status = e.target.value}> + 全部 + 正常 + 禁用 + + ]} + pagination={{ + showSizeChanger: true, + showLessItems: true, + hideOnSinglePage: true, + showTotal: total => `共 ${total} 条`, + pageSizeOptions: ['10', '20', '50', '100'] + }} + columns={this.columns}/> ) } } diff --git a/spug_web/src/pages/system/account/index.js b/spug_web/src/pages/system/account/index.js index 40ae70a..d0a1ab5 100644 --- a/spug_web/src/pages/system/account/index.js +++ b/spug_web/src/pages/system/account/index.js @@ -5,32 +5,27 @@ */ import React from 'react'; import { observer } from 'mobx-react'; -import { Input, Select, Button } from 'antd'; -import { SearchForm, AuthCard } from 'components'; +import { Input } from 'antd'; +import { SearchForm, AuthDiv, Breadcrumb } from 'components'; import ComTable from './Table'; +import ComForm from './Form'; import store from './store'; export default observer(function () { return ( - + + + 首页 + 系统管理 + 账户管理 + store.f_name = e.target.value} placeholder="请输入"/> - - - - - - -
- -
-
+ {store.formVisible && } + ) }) diff --git a/spug_web/src/pages/system/account/store.js b/spug_web/src/pages/system/account/store.js index c27016c..6a74e29 100644 --- a/spug_web/src/pages/system/account/store.js +++ b/spug_web/src/pages/system/account/store.js @@ -3,7 +3,7 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import { observable } from "mobx"; +import { observable, computed } from 'mobx'; import http from 'libs/http'; class Store { @@ -13,7 +13,14 @@ class Store { @observable formVisible = false; @observable f_name; - @observable f_status; + @observable f_status = ''; + + @computed get dataSource() { + let records = this.records; + if (this.f_name) records = records.filter(x => x.username.toLowerCase().includes(this.f_name.toLowerCase())); + if (this.f_status) records = records.filter(x => String(x.is_active) === this.f_status); + return records + } fetchRecords = () => { this.isFetching = true;