react 获取ajax列表,react中使用ajax获取数据并渲染

如下代码

import React from 'react';

import {Button, Card, Row, Badge, Modal, Table} from 'antd';

import Services from 'Services/monitor';

import classnames from 'classnames';

import {isSuccess} from 'Utils/request';

import {SERVICE_STATUS, SERVICE_STATUS_COLOR} from 'Constants/constants';

import {encodeFormatTime} from 'Utils/time';

import RateLine from './RateLine';

import NumberLine from './NumberLine';

import styles from './index.less';

export default class MainPage extends React.PureComponent {

state = {

agentStatus: SERVICE_STATUS.OFFLINE,

visible: false,

logList: [],

pagination: {},

loading: false,

loadSet: false

}

componentDidMount() {

Services.getAgentStatus().then(res => {

if (isSuccess(res)) {

this.setState({agentStatus: res.model.status});

}

});

}

// 日志

getLogTableColumn = () => {

const columns = [{

dataIndex: 'timestamp',

title: '时间',

render: encodeFormatTime,

width: '200px'

}, {

dataIndex: 'type',

title: '操作类型',

width: '150px'

}, {

dataIndex: 'message',

title: '操作内容',

width: '300px'

}];

return columns;

}

condition = {

pageNo: 1,

pageSize: 5

};

handlePiganation = ({current}) => {

this.condition.pageNo = current;

this.loadLog();

}

loadLog = () => {

this.setState({loading: true});

Services.getLog(this.condition).then(res => {

if (isSuccess(res)) {

const {model, pageInfo: {count: total, pageNo, pageSize}} = res;

if (pageNo === this.condition.pageNo) {

const pagination = {

total,

pageSize,

current: pageNo

};

this.setState({logList: model, pagination});

}

}

}).finally(() => {

this.setState({loading: false});

});

}

showModal = () => {

this.loadLog();

this.setState({visible: true});

}

showSetp = () => {

this.setState({loadSet: true});

}

closeModal = () => {

this.setState({visible: false, loadSet: false});

this.condition.pageNo = 1;

}

renderLogTable = () => {

const {pagination, logList, loading, visible} = this.state;

if (!visible) {

return null;

}

return (

columns={this.getLogTableColumn()}

dataSource={logList}

loading={loading}

pagination={pagination}

onChange={this.handlePiganation}

/>

);

}

render() {

const lines = [{

title: 'CPU使用率',

getData: Services.getCpuMonitorData

},

{

title: '内存使用率',

getData: Services.getMemoryMonitorData

},

{

title: '磁盘占用率',

getData: Services.getDiskMonitorData

},

{

title: '当前运行任务数',

getData: Services.getTaskMonitorData,

type: 'number'

}];

const agentStatus = this.state.agentStatus;

let color = '';

if (agentStatus === SERVICE_STATUS.OFFLINE) {

color = SERVICE_STATUS_COLOR.OFFLINE;

} else {

color = SERVICE_STATUS_COLOR.ONLINE;

}

return (

监控配置

运行日志

节点状态:

{

lines.map(item => {

const {title, getData, type} = item;

const Line = type ? NumberLine : RateLine;

return (

);

})

}

visible={this.state.visible}

onCancel={this.closeModal}

footer={null}

width="750px"

>

{this.renderLogTable()}

visible={this.state.loadSet}

onCancel={this.closeModal}

footer={null}

width="750px"

>

{this.renderLogTable()}

);

}

}

我需要在监控配置这个弹框通过后台的接口获取内容并且渲染出来,

就是这个样式:

bVbteMh?w=720&h=312

怎么实现这个渲染哇

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值