import React, {Component} from 'react'; import { Badge, Button, Col, Divider, Input, Layout, Modal, Row, Select, Space, Table, Tag, Tooltip, Typography } from "antd"; import qs from "qs"; import request from "../../common/request"; import {message} from "antd/es"; import {PlusOutlined, SyncOutlined, UndoOutlined} from '@ant-design/icons'; import {PROTOCOL_COLORS} from "../../common/constants"; const confirm = Modal.confirm; const {Search} = Input; const {Content} = Layout; const {Title, Text} = Typography; class UserShareAsset extends Component { inputRefOfName = React.createRef(); changeOwnerFormRef = React.createRef(); state = { items: [], total: 0, queryParams: { pageIndex: 1, pageSize: 10, protocol: '' }, loading: false, tags: [], model: {}, selectedRowKeys: [], selectedRows: [], delBtnLoading: false, changeOwnerModalVisible: false, changeSharerModalVisible: false, changeOwnerConfirmLoading: false, changeSharerConfirmLoading: false, users: [], selected: {}, totalSelectedRows: [], sharer: '' }; async componentDidMount() { this.setState({ sharer: this.props.sharer }) let r2 = await request.get('/assets/paging?pageIndex=1&pageSize=1000&sharer=' + this.props.sharer); if (r2['code'] === 1) { let items = r2['data']['items']; this.setState({ totalSelectedRows: items }) } 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('/assets/paging?' + 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} }) let totalSelectedRows = this.state.totalSelectedRows; let selectedRowKeys = totalSelectedRows.map(item => item['id']); this.setState({ items: items, total: data.total, queryParams: queryParams, loading: false, selectedRowKeys: selectedRowKeys }); } } handleChangPage = async (pageIndex, pageSize) => { let queryParams = this.state.queryParams; queryParams.pageIndex = pageIndex; queryParams.pageSize = pageSize; this.setState({ queryParams: queryParams }); await this.loadTableData(queryParams) }; handleSearchByName = name => { let query = { ...this.state.queryParams, 'pageIndex': 1, 'pageSize': this.state.queryParams.pageSize, 'name': name, } this.loadTableData(query); }; handleTagsChange = tags => { console.log(tags) // this.setState({ // tags: 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); } unSelectRow = async (assetId) => { let userId = this.state.sharer; let result = await request.post(`/resources/remove`, { userId: userId, resourceType: 'asset', resourceIds: [assetId] }); if (result['code'] === 1) { message.success('操作成功', 3); } else { message.error(result['message'], 10); } const selectedRowKeys = this.state.selectedRowKeys.filter(key => key !== assetId); const totalSelectedRows = this.state.totalSelectedRows.filter(item => item['id'] !== assetId); this.setState({ selectedRowKeys: selectedRowKeys, totalSelectedRows: totalSelectedRows }) } render() { const columns = [{ title: '序号', dataIndex: 'id', key: 'id', render: (id, record, index) => { return index + 1; } }, { title: '资产名称', dataIndex: 'name', key: 'name', render: (name, record) => { let short = name; if (short && short.length > 20) { short = short.substring(0, 20) + " ..."; } return ( {short} ); } }, { title: '网络', dataIndex: 'ip', key: 'ip', render: (text, record) => { return record['ip'] + ':' + record['port']; } }, { title: '连接协议', dataIndex: 'protocol', key: 'protocol', render: (text, record) => { return ({text}); } }, { title: '状态', dataIndex: 'active', key: 'active', render: text => { if (text) { return (); } else { return (); } } }, { title: '所有者', dataIndex: 'ownerName', key: 'ownerName' }, { title: '创建日期', dataIndex: 'created', key: 'created' } ]; const selectedRowKeys = this.state.selectedRowKeys; const rowSelection = { selectedRowKeys: this.state.selectedRowKeys, onChange: (selectedRowKeys, selectedRows) => { this.setState({selectedRowKeys, selectedRows}); }, }; let hasSelected = false; if (selectedRowKeys.length > 0) { let totalSelectedRows = this.state.totalSelectedRows; let allSelectedRowKeys = totalSelectedRows.map(item => item['id']); for (let i = 0; i < selectedRowKeys.length; i++) { let selectedRowKey = selectedRowKeys[i]; if (!allSelectedRowKeys.includes(selectedRowKey)) { hasSelected = true; break; } } } return ( <> 共享资产列表
{ this.state.totalSelectedRows.map(item => { return this.unSelectRow(item['id'])} key={item['id']}>{item['name']} }) }
全部资产列表
`总计 ${total} 条` }} loading={this.state.loading} /> ); } } export default UserShareAsset;