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列表或者文档库的分页控件,并且把 ...
随机推荐
- TeX Live安装指南
若要安装 TeXLive ,推荐下载 TeXLive 的 ISO 镜像,因为在线安装下载过程会很慢.如果网速快也可以在线安装.下载地址:http://mirror.ctan.org/systems/t ...
- BZOJ 3636 教义问答手册 (分治)
题意 一个整数数列,多次询问某段区间[li,ri][l_i,r_i][li,ri]内,选出若干个长度为LLL且不相交的连续段使选出来的数和最大. 分析 首先想朴素的区间DPDPDP 设f[i][j ...
- 关于https的五大误区
如今,https协议正在被广泛重视和使用.随着今年2月初,谷歌旗下Chrome浏览器宣布将所有http标示为不安全网站,许多网站都争相从http升级到了https.当你打开很多网站时,会发现浏览器左上 ...
- [AGC028B]Removing Blocks 概率与期望
考虑算每一个位置在所有情况的期望值乘以全排列似乎就是答案. 那么对于 $i$,如果要由 $j$ 来贡献的话就要满足 $j$ 在 $i....j-1$ 之前先拿. 而在拿 $j$ 时,先于 $i...j ...
- simcom7600ce-t LBS function
Welcome to minicom 2.7 OPTIONS: I18n Compiled on Nov 15 2018, 20:20:38.Port /dev/ttyUSB2, 00:55:23 P ...
- Qt在pro中实现条件编译
https://www.cnblogs.com/Braveliu/p/5107550.html https://blog.csdn.net/simonforfuture/article/details ...
- Ubuntu16.04 安装 CUDA9.2(总结一些新手容易遇到的问题)
系统:Ubuntu16.04 64bit 显卡:Nvidia GEFORCE 940MX 驱动:NVIDIA-Linux-x86_64-396.18.run 软件:cuda_9.2.88_396.26 ...
- 一个类中域(field)的首字母不要大写
首先这种写法不规范, 其次,至少在AJAX交互的情况下, 如果首字母大写,会无法与前端相同名称的JSON属性相绑定. 如 data:{'Name':'2017-10-19'} public NameI ...
- java Spring定时器 每个季度执行一次
@Scheduled(cron = " 0 00 00 1 4,7,10,1 ?")//每个季度的第一天零点进行统计此注解是每个季度结束后的下一天执行(因为Spring不识别字母( ...
- Hadoop(3)如何构建HDFS--HA,YARN---HA
什么是HA? HA的意思是High Availability高可用,指当当前工作中的机器宕机后,会自动处理这个异常,并将工作无缝地转移到其他备用机器上去,以来保证服务的高可用. HA方式安装部署才是最 ...