import React, {Component} from 'react'; import { Button, Card, Col, Descriptions, Divider, Input, Layout, List, Row, Select, Space, Tag, Tooltip, Typography } from "antd"; import { CheckCircleOutlined, CodeOutlined, DesktopOutlined, ExclamationCircleOutlined, SyncOutlined, TagsOutlined, UndoOutlined } from "@ant-design/icons"; import request from "../../common/request"; import {message} from "antd/es"; import qs from "qs"; const {Content} = Layout; const {Title} = Typography; const {Search} = Input; class MyAsset extends Component { inputRefOfName = React.createRef(); inputRefOfIp = React.createRef(); state = { items: [], tags: [], queryParams: { pageIndex: 1, pageSize: 8, protocol: '', tags: '' }, loading: false, } async componentDidMount() { this.loadTableData(); let result = await request.get('/tags'); if (result['code'] === 1) { this.setState({ tags: result['data'] }) } } async loadTableData(queryParams) { this.setState({ loading: true }); queryParams = queryParams || this.state.queryParams; // queryParams let paramsStr = qs.stringify(queryParams); let data = { items: [], total: 0 }; try { let result = await request.get('/account/assets?' + paramsStr); if (result['code'] === 1) { data = result['data']; } else { message.error(result['message']); } } catch (e) { } finally { const items = data.items.map(item => { return {'key': item['id'], ...item} }) this.setState({ items: items, total: data.total, queryParams: queryParams, loading: false }); } } renderTags(tags) { let tagDocuments = [] let tagArr = tags.split(','); for (let i = 0; i < tagArr.length; i++) { if (tags[i] === '-') { continue; } tagDocuments.push({tagArr[i]}) } return tagDocuments; } handleSearchByName = name => { let query = { ...this.state.queryParams, 'pageIndex': 1, 'pageSize': this.state.queryParams.pageSize, 'name': name, } this.loadTableData(query); }; handleSearchByIp = ip => { let query = { ...this.state.queryParams, 'pageIndex': 1, 'pageSize': this.state.queryParams.pageSize, 'ip': ip, } this.loadTableData(query); }; handleTagsChange = tags => { this.setState({ selectedTags: tags }) let query = { ...this.state.queryParams, 'pageIndex': 1, 'pageSize': this.state.queryParams.pageSize, 'tags': tags.join(','), } this.loadTableData(query); } handleSearchByProtocol = protocol => { let query = { ...this.state.queryParams, 'pageIndex': 1, 'pageSize': this.state.queryParams.pageSize, 'protocol': protocol, } this.loadTableData(query); } handleChangPage = async (pageIndex, pageSize) => { let queryParams = this.state.queryParams; queryParams.pageIndex = pageIndex; queryParams.pageSize = pageSize; this.setState({ queryParams: queryParams }); await this.loadTableData(queryParams) }; handleTableChange = (pagination, filters, sorter) => { let query = { ...this.state.queryParams, 'order': sorter.order, 'field': sorter.field } this.loadTableData(query); } render() { return (
我的资产
`总计 ${total} 条`, pageSizeOptions: [8, 16, 32, 64, 128] }} renderItem={item => { const id = item['id']; const protocol = item['protocol']; const name = item['name']; const sshMode = item['sshMode']; let url = ''; if (protocol === 'ssh' && sshMode === 'naive') { url = `#/term?assetId=${id}&assetName=${name}`; } else { url = `#/access?assetId=${id}&assetName=${name}&protocol=${protocol}`; } return ( } color="success"> 运行中 : } color="error"> 不可用 } actions={[]}> 资产协议
}> {item['protocol']} 主机地址
}> {item['ip'] + ':' + item['port']} 标签}> {this.renderTags(item['tags'])} ) }} /> ); } } export default MyAsset;