react 组装table列表带分页
2.组装编辑界面
/**
* Created by hldev on 17-6-14.
*/
import React, {Component} from "react";
import {Link} from "react-router-dom";
import {inject, observer} from "mobx-react";
import {Form, Input, Select, Row, Col, Button, Card, InputNumber, Radio, Modal } from 'antd';
import HlBreadcrumb from "../common/HlBreadcrumb";
import Panel, {PanelBody, PanelHeader} from '../common/Panel';
import Utils from "../../utils/util"
const FormItem = Form.Item;
const Option = Select.Option;
const RadioGroup = Radio.Group; @inject("store")
@observer
class HostEdit extends Component { constructor(props) {
super(props);
this.hostState = this.props.store.hostState;
} componentWillMount() {
this.hostState.getCabinetList();
if (!this.isAdd()) {
this.hostState.getHosts(this.props.match.params.id);
}
} isAdd = () => this.props.match.params.id === 'add'; handClick = (event) => {
window.history.back();
}; isUNumb =(obj) =>{
//根据cabinetId 找到对应的机柜的总的U位数
//然后对比两个U位和机柜U位之间的关系
const cabinetList = this.hostState.cabinetList;
if (!cabinetList || cabinetList.length === 0) {
return [];
}
const cabinet = cabinetList.find( item => item.cabinetId === obj.cabinetId); if(obj.startNum > cabinet.unum){
Modal.error({
title:'错误消息',
content:`开始U位数不能大于机柜的U位数${cabinet.unum}`
});
return; }
if(obj.endNum > cabinet.unum){
Modal.error({
title:'错误消息',
content:`结束U位数不能大于机柜的U位数${cabinet.unum}`
});
return;
} if(obj.startNum > obj.endNum){
Modal.error({
title:'错误消息',
content:`开始U位数不能大于结束U位数`
});
return;
}
if(obj.startNum < cabinet.unum && obj.endNum <= cabinet.unum && obj.startNum <= obj.endNum){
//处理添加和修改的区别
if (!this.isAdd()) {
this.hostState.updateHost(obj).then((response)=> {
console.log(response);
const {status} = response;
if(status){
Utils.goBack();
}
})
} else {
this.hostState.createHost(obj); //新增
Utils.goBack();
}
} }; handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
if (this.isAdd()) { //新增/api/cabinet
//验证主机的开始U位数和结束U位数不能大于 机柜的总的U位数
this.isUNumb(values)
//this.hostState.createHost(values);
} else {
console.log('修改主机参数: ', values);
this.isUNumb(values);
//this.hostState.updateHost(values); //修改
} }
});
}; renderOptions = () => {
const cabinetList = this.hostState.cabinetList;
if (!cabinetList || cabinetList.length === 0) {
return <Option value="暂无数据" key='-1'>暂无数据</Option>
}
return cabinetList.map((doc, idx) => <Option key={idx} value={doc.cabinetId}>{doc.name}——{doc.cabinetId}</Option>);
}; render() {
const {getFieldDecorator} = this.props.form;
const formItemLayout = {
labelCol: {
xs: {span: 7},
sm: {span: 6},
},
wrapperCol: {
xs: {span: 12},
sm: {span: 14},
},
}; const breadcrumb = [{
path: '/', name: '首页'
}, {
path: '/hostMain', name: '主机管理'
}, {
name: this.isAdd() ? '添加主机' : '编辑主机'
}]; const optionElement = this.renderOptions(); return (
<div className="content-main">
<HlBreadcrumb breadcrumb={breadcrumb}/>
<Panel>
<PanelBody>
<Form onSubmit={this.handleSubmit}>
<Row>
<Col span={10}>
<FormItem
{...formItemLayout}
label="机柜ID"
hasFeedback>
{getFieldDecorator('cabinetId', {
rules: [{
required: true, message: '请输入机柜ID!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.cabinetId
})(
<Select showSearch style={{width: '16rem'}}
optionFilterProp="children"
onChange={this.handleChange}
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
placeholder="--请选择--">
{optionElement}
</Select>
)}
</FormItem>
<FormItem {...formItemLayout}
label="CPU参数"
hasFeedback>
{getFieldDecorator('cpuParameter', {
rules: [{
required: true, message: '请输入CPU参数!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.cpuParameter
})(
<Input />
)}
</FormItem> <FormItem {...formItemLayout}
label="主机ID"
hasFeedback>
{getFieldDecorator('hostId', {
rules: [{
required: true, message: '请输入主机ID!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.hostId
})(
this.isAdd() ? <Input /> : <Input disabled={true}/>
)}
</FormItem> <FormItem {...formItemLayout}
label="内存参数(GB)"
hasFeedback>
{getFieldDecorator('memoryParameter', {
rules: [{
required: true, message: '请输入内存参数!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.memoryParameter
})(
<Input />
)}
</FormItem> <FormItem {...formItemLayout}
label="硬盘参数(T)"
hasFeedback>
{getFieldDecorator('diskParameter', {
rules: [{
required: true, message: '请输入硬盘参数!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.diskParameter
})(
<Input />
)}
</FormItem> <FormItem {...formItemLayout} label="电源参数(V)"
hasFeedback>
{getFieldDecorator('powerParameter', {
rules: [{
required: true, message: '请输入电源参数!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.powerParameter
})(
<Input />
)}
</FormItem> <FormItem {...formItemLayout}
label="主板参数(GB)"
hasFeedback>
{getFieldDecorator('motherBoardParameter', {
rules: [{
required: true, message: '请输入主板参数!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.motherBoardParameter
})(
<Input />
)}
</FormItem> </Col>
<Col span={2}> </Col> <Col span={10}> <FormItem {...formItemLayout}
label="起始U位"
hasFeedback>
{getFieldDecorator('startNum', {
rules: [{
required: true, message: '请输入起始U位!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.startNum
})(
<InputNumber
min={1}
max={99}
formatter={value => parseInt(value) || "" }
/>
)}
</FormItem>
<FormItem {...formItemLayout}
label="终止U位"
hasFeedback>
{getFieldDecorator('endNum', {
rules: [{
required: true, message: '请输入终止U位!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.endNum
})(
<InputNumber min={1}
max={99}
formatter={value => parseInt(value) || ""}
/>
)}
</FormItem> <FormItem {...formItemLayout}
label="硬盘状态"
hasFeedback>
{getFieldDecorator('diskStatus', {
rules: [{
required: true, message: '请选择硬盘状态!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.diskStatus+''
})(
<RadioGroup>
<Radio value="0">预警</Radio>
<Radio value="1">正常</Radio>
</RadioGroup>
)}
</FormItem> <FormItem {...formItemLayout}
label="内存状态"
hasFeedback>
{getFieldDecorator('memoryStatus', {
rules: [{
required: true, message: '请选择内存状态!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.memoryStatus+''
})(
<RadioGroup>
<Radio value="0">预警</Radio>
<Radio value="1">正常</Radio>
</RadioGroup>
)}
</FormItem> <FormItem {...formItemLayout}
label="CPU状态"
hasFeedback>
{getFieldDecorator('cpuStatus', {
rules: [{
required: true, message: '请选择CPU状态!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.cpuStatus+''
})(
<RadioGroup>
<Radio value="0">预警</Radio>
<Radio value="1">正常</Radio>
</RadioGroup>
)}
</FormItem> <FormItem {...formItemLayout}
label="服务健康状况"
hasFeedback>
{getFieldDecorator('serverStatus', {
rules: [{
required: true, message: '请选择服务健康状况!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.serverStatus+''
})(
<RadioGroup>
<Radio value="0">预警</Radio>
<Radio value="1">正常</Radio>
</RadioGroup>
)}
</FormItem> <FormItem {...formItemLayout}
label="主机状态"
hasFeedback>
{getFieldDecorator('status', {
rules: [{
required: true, message: '请选择主机状态!',
}],
initialValue: this.isAdd() ? "" : this.hostState.hosts.status+''
})(
<RadioGroup>
<Radio value="0">未使用</Radio>
<Radio value="1">正常</Radio>
<Radio value="2">预警</Radio>
</RadioGroup>
)}
</FormItem> </Col>
</Row> <FormItem style={{textAlign: 'center'}}>
<Button onClick={this.handClick}>取消</Button>
<Button type="primary" htmlType="submit">确认</Button>
</FormItem>
</Form>
</PanelBody>
</Panel>
</div>
)
}
} HostEdit = Form.create()(HostEdit);
export default HostEdit;
1.table列表
/**
* Created by hldev on 17-6-14.
* 机柜列表管理
*/
import React, {Component} from "react";
import {Link} from "react-router-dom";
import {inject, observer} from "mobx-react";
import {Button, Col, Form, Icon, Popconfirm, Row, Table, Tag} from "antd";
import HlBreadcrumb from "../common/HlBreadcrumb";
import HlPagination from "../common/HlPagination";
import Panel, {PanelBody, PanelHeader} from "../common/Panel"; @inject("store")
@observer
class CabinetList extends Component { constructor(props) {
super(props);
this.roomState = this.props.store.roomState;
} componentDidMount() {
//this.roomState.getRoomList();
this.roomState.getRoomPage();
} /*
* 渲染table数据列,处理请求返回为空的情况
* */
dataSource = (roomPage) => {
console.log('totalElements', roomPage.totalElements);
if (roomPage.totalElements === undefined || roomPage.totalElements <= 0) {
return [];
} return roomPage.content.map((item, idx) => {
let statusName = '';
if (item.status === 0) {
statusName = '未使用'
} else if (item.status === 1) {
statusName = '使用中'
} else {
statusName = '预警'
}
return {
...item,
status: statusName,
/*address:cabinet.address,*/
key: idx,
};
});
}; render() { const columns = [{
title: '机房编号',
dataIndex: 'roomId',
key: 'roomId',
render: (text, record, index) => <Link to={`/clusterMain/${record.roomId}`}>{text}</Link>
}, {
title: '机房位置',
dataIndex: 'address',
key: 'address',
/*render: (item) => item ? item.join(',') : '' description*/
}, {
title: '备注信息',
dataIndex: 'description',
key: 'description',
}, {
title: '机房状态',
dataIndex: 'status',
key: 'status',
render: (status) => {
if (status === `未使用`) {
return (<div style={{color: 'gary'}}>{status}</div>)
} else if (status === `使用中`) {
return (<Tag color="green">{status}</Tag>)
} else {
return (<Tag color="orange">{status}</Tag>)
}
}
},{
title: '操作',
key: 'operation',
render: (_, record) => (
<div>
<Link to={`/roomMain/${record.roomId}`}><Icon type="edit"/>编辑</Link>
<span className="ant-divider"/>
<Popconfirm title="是否确认删除该记录?"
onConfirm={() => this.topicState.deleteTopic(`${record.id}`)}>
{/*<a className="fgw-text-error"><Icon type="delete"/>删除</a>*/}
</Popconfirm>
</div>)
}]; const {getFieldDecorator} = this.props.form; const dataSource = this.dataSource(this.roomState.roomPage);
const paginationProps = {
totalElements: this.roomState.roomPage.totalElements || 0,
params: this.props.form.getFieldsValue(),
state: "roomState",
method: "getRoomPage"
}; const breadcrumb = [{
path: '/',
name: '首页'
}, {
name: '所有机房管理'
}]; return (
<div className="content-main">
<HlBreadcrumb breadcrumb={breadcrumb}/>
<Panel>
<PanelHeader>
<Row>
<Col span={12}>
{/*<Input.Search placeholder="输入机柜编号进行搜索"
onSearch={value => this.topicState.getTopicPage({name: value})}/>*/}
</Col>
<Col span={12}>
<Link to={`/roomMain/add`} className="fgw-pull-right">
<Button type="primary" htmlType="submit">添加</Button>
</Link>
</Col>
</Row>
</PanelHeader>
<PanelBody>
<Table bordered={true}
size="small"
columns={columns}
pagination={false}
dataSource={dataSource}/>
<HlPagination paginationProps={paginationProps}/>
</PanelBody>
</Panel>
</div>);
}
} CabinetList = Form.create()(CabinetList);
export default CabinetList;
react 组装table列表带分页的更多相关文章
- 从后端到前端之Vue(四)小试牛刀——真实项目的应用(树、tab、数据列表和分页)
学以致用嘛,学了这么多,在真实项目里面怎么应用呢?带着问题去学习才是最快的学习方式.还是以前的那个项目,前后端分离,现在把前端换成vue的,暂时采用脚本化的方式,然后在尝试工程化的方式. 现在先实现功 ...
- GridView使用自带分页功能时分页方式及样式PagerStyle
// 转向地址:http://www.bubuko.com/infodetail-412562.html GridView分页,使用自带分页功能,类似下面样式: 在aspx页面中,GridView上的 ...
- 帝国cms 列表页分页样式修改美化【1】
[1]自己修改帝国cms默认的分页样式(css),这样做的好处是你不用去改动帝国的核心文件,方便以后升级. [2]自己动手去修改帝国的分页(php+css),帝国的分页在e>class>下 ...
- spring boot jpa 多条件组合查询带分页的案例
spring data jpa 是一个封装了hebernate的dao框架,用于单表操作特别的方便,当然也支持多表,只不过要写sql.对于单表操作,jpake可以通过各种api进行搞定,下面是一个对一 ...
- django上课笔记2-视图CBV-ORM补充-Django的自带分页-Django的自定义分页
一.视图CBV 1.urls url(r'^login.html$', views.Login.as_view()), 2.views from django.views import View cl ...
- WijmoJS 中自定义 React 菜单和列表项模板
WijmoJS 中自定义 React 菜单和列表项模板 在V2019.0 Update2 的全新版本中,React 框架下 WijmoJS 的前端UI组件功能再度增强. WijmoJS的菜单和类似列表 ...
- [Laravel] 自带分页实现以及links方法不存在错误
自带分页实现其实挺简单的,但是我在实现的时候报错!找了很久才找出原因! 废话不说上码 控制器LeeController.php层 <?php namespace App\Http\control ...
- 如何快速开发树形列表和分页查询整合的WInform程序界面
我在做Winform界面的时候,一般都是统一化处理,界面顶部放置一些字段条件供查询,下面就是分页查询列表,展示相关的数据.但有时候碰到一些表字段内容分类比较多,有一些特别重要,如果放在一个树形列表来进 ...
- sharepoint 2010 列表数据分页控件介绍 pagination UserControl
转:http://blog.csdn.net/chenxinxian/article/details/8714391 这里主要是介绍下最近开发的一个sharepoint列表或者文档库的分页控件,并且把 ...
随机推荐
- MySQL Navicat Premium 保存sql语句
一.新建查询 二.编写sql语句并保存 1.保存到内部 1.Ctrl+s保存当前查询文件 2.下次打开可点击查询点击上次保存的查询文件名打开上次查询的文件 2.保存到外部 1.默认保存至 C:\Use ...
- 02-Elenment 引入使用
快速上手 本节将介绍如何在项目中使用 Element. ¶使用 vue-cli@3 我们为新版的 vue-cli 准备了相应的 Element 插件,你可以用它们快速地搭建一个基于 Element 的 ...
- [HDU 5608]Function(莫比乌斯反演 + 杜教筛)
题目描述 有N2−3N+2=∑d∣Nf(d)N^2-3N+2=\sum_{d|N} f(d)N2−3N+2=∑d∣Nf(d) 求∑i=1Nf(i)\sum_{i=1}^{N} f(i)∑i=1Nf ...
- 使用webuploader实现大文件上传分片上传
本人在2010年时使用swfupload为核心进行文件的批量上传的解决方案.见文章:WEB版一次选择多个文件进行批量上传(swfupload)的解决方案. 本人在2013年时使用plupload为核心 ...
- learning scala How To Create Implicit Function
println("Step 1: How to create a wrapper String class which will extend the String type") ...
- qt动态库实现无边框窗体的消息处理 nativeEvent的使用
需求: 在动态库中创建一个窗口句柄,可以给外部调用,库的调用者,通过这个句柄发送消息到底层库,库里面可以实现对消息的处理 m_FHandle=AllocateHWnd(WndProcDllMsg); ...
- decodeURI 与 decodeURIComponent 区别
1. 关于URL.encodeURI 及 encodeURIComponent: URI: Uniform Resource Identifiers,通用资源标识符 Global 对象的 encode ...
- java.lang.ClassNotFoundException: org.springframework.kafka.core.KafkaAdmin
<dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring ...
- Spring - 环境安装
安装IDEA的非Community版本和Java的包之后就可以用Java来HelloWorld了. 然后去这个链接:https://github.com/spring-guides/gs-rest-s ...
- BZOJ1856[Scoi2010]字符串——组合数学+容斥
题目描述 lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgww想要知道满足 ...