A web update

pull/22/head
雷二猛 2019-12-06 00:45:58 +08:00
parent e76ed02787
commit 511ecd10b5
2 changed files with 36 additions and 40 deletions

View File

@ -1,68 +1,64 @@
import React from 'react'; import React from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { Table, Divider, Modal, message } from 'antd'; import { Table, Tag } from 'antd';
import http from 'libs/http';
import store from './store'; import store from './store';
import { LinkButton } from "components"; import groupStore from '../group/store';
@observer @observer
class ComTable extends React.Component { class ComTable extends React.Component {
constructor(props) {
super(props);
this.state = {
groupMap: {}
}
}
componentDidMount() { componentDidMount() {
store.fetchRecords() store.fetchRecords();
if (groupStore.records.length === 0) {
groupStore.fetchRecords().then(this._handleGroups)
} else {
this._handleGroups()
}
} }
_handleGroups = () => {
const tmp = {};
for (let item of groupStore.records) {
tmp[item.id] = item.name
}
this.setState({groupMap: tmp})
};
columns = [{ columns = [{
title: '序号',
key: 'series',
render: (_, __, index) => index + 1,
width: 80,
}, {
title: '任务名称', title: '任务名称',
dataIndex: 'name', dataIndex: 'name',
}, { }, {
title: '监控类型', title: '监控类型',
dataIndex: 'type', dataIndex: 'type',
}, {
title: '状态',
dataIndex: 'status',
render: value => value === '1' ? <Tag color="orange">报警发生</Tag> : <Tag color="green"></Tag>
}, { }, {
title: '持续时间', title: '持续时间',
render: text => text.body, dataIndex: 'duration',
ellipsis: true
}, { }, {
title: '描述信息', title: '通知方式',
dataIndex: 'desc', dataIndex: 'notify_mode',
ellipsis: true
}, { }, {
title: '操作', title: '通知对象',
render: info => ( dataIndex: 'notify_grp',
<span> render: value => value.map(id => this.state.groupMap[id]).join(',')
<LinkButton onClick={() => store.showForm(info)}>编辑</LinkButton> }, {
<Divider type="vertical"/> title: '发生时间',
<LinkButton onClick={() => this.handleDelete(info)}>删除</LinkButton> dataIndex: 'created_at'
</span>
)
}]; }];
handleDelete = (text) => {
Modal.confirm({
title: '删除确认',
content: `确定要删除【${text['name']}】?`,
onOk: () => {
return http.delete('/api/exec/template/', {params: {id: text.id}})
.then(() => {
message.success('删除成功');
store.fetchRecords()
})
}
})
};
render() { render() {
let data = store.records; let data = store.records;
if (store.f_name) { if (store.f_name) {
data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase())) data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase()))
} }
if (store.f_type) {
data = data.filter(item => item['type'].toLowerCase().includes(store.f_type.toLowerCase()))
}
return ( return (
<Table rowKey="id" loading={store.isFetching} dataSource={data} columns={this.columns}/> <Table rowKey="id" loading={store.isFetching} dataSource={data} columns={this.columns}/>
) )

View File

@ -11,7 +11,7 @@ class Store {
fetchRecords = () => { fetchRecords = () => {
this.isFetching = true; this.isFetching = true;
http.get('/api/alarm/group/') return http.get('/api/alarm/group/')
.then(res => this.records = res) .then(res => this.records = res)
.finally(() => this.isFetching = false) .finally(() => this.isFetching = false)
}; };