UNPKG

app-base-web

Version:
312 lines (305 loc) 11.2 kB
import React, { Suspense, lazy } from 'react'; import { Table, Row, Col, Button, Input, message } from 'antd'; import UtilModal from '../../../library/util-modal'; import UtilDic from '../../../library/util-dic'; import api from '../../../library/util-axios'; // 任务调度管理-任务管理 const title = "任务管理"; const url = "TsTask/"; const FormView = lazy(() => import('./TsTaskView')); const FormEdit = lazy(() => import('./TsTaskEdit')); const FormTsSchedulerEdit = lazy(() => import('../TsScheduler/TsSchedulerEdit')); export default class TsTaskList extends React.Component { constructor(props) { super(props); this.state = { params: {}, data: [], pagination: {}, loading: false, selected: [],//Table checked selectedRows: [], //显藏控制 showView: false, showEdit: false, showSchedulerEdit: false, //values values: {}, }; this.columns = [{ title: "序号", width: 50, fixed: "left", render: (text, record, index) => { return index + 1 } }, { title: "任务名称", dataIndex: "name", width: 200, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, // { // title: "任务类型", // dataIndex: "type", // width: 100, // render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) // }, { title: "日志类型", dataIndex: "logType", width: 100, render: (text, record) => { return UtilDic.json("ts", "日志类型")[text] } }, { title: "监控角色", dataIndex: "monitoringRole", width: 100 }, { title: "报警类型", dataIndex: "alarmType", width: 100, render: (text, record) => { return UtilDic.json("ts", "报警类型")[text] } }, { title: "报警间隔时间", dataIndex: "alarmInterval", width: 100 }, { title: "超时阀值", dataIndex: "timeout", width: 100 }, { title: "任务包路径", dataIndex: "path", width: 200 }, { title: "任务方法", dataIndex: "method", width: 100 }, { title: "任务参数", dataIndex: "params", width: 100 }, { title: "任务说明", dataIndex: "memo", width: 300 }]; } componentDidMount() { this.onLoad(this.state.params); } /*** Table ***/ async onLoad(params) { this.setState({ loading: true }); let rs = await api.get(url + "getList", params); let pagination = { pageSizeOptions: ["20", "100", "200", "500", "1000"], pageSize: params.pageSize || 20, defaultPageSize: params.pageSize || 20, showSizeChanger: true, showQuickJumper: true, total: rs.total, showTotal: (total) => { return `总记录 ${total} ` } }; this.setState({ loading: false, showEdit: false, showSchedulerEdit: false, params, data: rs.data, pagination }); } onChange = (pagination, filters, sorter) => { let params = this.state.params; params.pageSize = pagination.pageSize; params.pageIndex = pagination.current; this.onLoad(params); } onSearch = (values) => { let params = { ...this.state.params, ...values } this.onLoad(params); } onAdd = () => { let values = {}; Object.keys(this.state.values).forEach(key => values[key] = undefined); this.setState({ showView: false, showEdit: true, values }); } onView = (values) => { this.setState({ showView: true, loading: false, values }); } onEdit = (values) => { let me = this; api.get(url + "getModel?id=" + values.id, {}, function (rs) { me.setState({ showEdit: true, showView: false, values: rs.data }); }); } onSave = (values) => { this.onLoad(this.state.params); } onDel = () => { let me = this; if (me.state.selected.length == 0) { message.error('请选择记录!'); return; } UtilModal.confirm({ content: '确定删除?', onOk: function () { api.delete(url + "delete?id=" + me.state.selected).then(function (rs) { if (rs.success) { message.info(rs.msg); me.onLoad(me.state.params || {}); } else { message.error(rs.msg); } }); } }) } onExec = () => { let me = this; if (me.state.selected.length == 0) { message.error('请选择记录!'); return; } UtilModal.confirm({ content: '确定执行该任务?', onOk: function () { api.post(url + "exec?id=" + me.state.selected).then(function (rs) { if (rs.success) { message.info(rs.msg); // me.onLoad(me.state.params || {}); } else { message.error(rs.msg); } }); } }) } onAddScheduler = () => { if (this.state.selected.length == 0) { message.error('请选择记录!'); return; } if (this.state.selected.length > 1) { message.error('只允许对一个任务添加调度!'); return; } this.setState({ showEdit: false, showView: false, showSchedulerEdit: true, values: { name: this.state.selectedRows[0].name + " - 调度", taskId: this.state.selectedRows[0].id, taskName: this.state.selectedRows[0].name } }); } render() { var tableCfg = { scroll: { y: this.props.height - 210 }, size: "middle", rowKey: "id", columns: this.columns, rowSelection: { selectedRowKeys: this.state.selected, onChange: (selectedRowKeys, selectedRows) => { console.log(selectedRowKeys); console.log(selectedRows); this.setState({ selected: selectedRowKeys, selectedRows }); } }, rowClassName: (record) => { return record.id === this.state.selectedRowId ? 'row-selected' : ''; }, onRow: (record) => { return { onClick: event => { this.setState({ selectedRowId: record.id }); } } }, dataSource: this.state.data, pagination: this.state.pagination, loading: this.state.loading, onChange: this.onChange } return <div className="app-admin"> <div className={this.state.showView || this.state.showEdit ? "hide" : ""}> <Row> <Col className="main-title" ><i className="iconfont icon-title"></i>{title}</Col> </Row> {/* <FormQuery onSearch={this.onSearch} values={this.state.params} /> */} <Row className="main-toolbar"> <Col xs={14}> <Button className="btn-add" onClick={this.onAdd}><i className="iconfont icon-add"></i>录入</Button> <Button className="btn-del" onClick={this.onDel}><i className="iconfont icon-del"></i>删除</Button> <Button className="btn-addSchedule" onClick={this.onAddScheduler}><i className="iconfont icon-exec"></i>添加调度</Button> <Button className="btn-exec" onClick={this.onExec}><i className="iconfont icon-exec"></i>手工执行</Button> {/* <Button className="btn-copy" onClick={this.onCopy}><i className="iconfont icon-copy"></i>拷贝</Button> <Button className="btn-export" onClick={this.onExport}><i className="iconfont icon-export"></i>导出</Button> */} </Col> <Col className="query-filed" xs={5}> {/* <Input placeholder="请输入应用名称" onChange={event => { let params = this.state.params; params.app = event.target.value; this.setState({ params }); }} /> */} </Col> <Col className="query-filed" xs={5}> <Input.Search placeholder="请输入名称" onSearch={(value) => { this.onSearch({ name: value }); }} enterButton /> </Col> {/* <Col className="order-filed" xs={2}> <Form.Item name="ord" label=""> <Select onChange={this.onSort} placeholder="默认排序" data={["默认排序", "按时间", "按金额"]} /> </Form.Item> </Col> */} </Row> <Table {...tableCfg} /> </div> <Suspense fallback={<div></div>}> {this.state.showView ? <FormView height={this.props.height - 140} values={this.state.values} onEdit={this.onEdit} onReturn={() => { this.setState({ showView: false }) }} /> : ""} {this.state.showEdit ? <FormEdit height={this.props.height - 140} values={this.state.values} onSave={this.onSave} onCancel={() => { this.setState({ showEdit: false }) }} onEditReturn={() => { this.setState({ showEdit: false, showView: true }) }} /> : ""} {this.state.showSchedulerEdit ? <FormTsSchedulerEdit height={this.props.height - 140} values={this.state.values} onSave={this.onSave} onCancel={() => { this.setState({ showSchedulerEdit: false }) }} /> : ""} </Suspense> </div>; } }