增加全局VNC与TELNET设置

This commit is contained in:
dushixiang
2021-02-10 21:56:05 +08:00
committed by dushixiang
parent 622fa65241
commit 25c3c6b929
11 changed files with 783 additions and 765 deletions

View File

@ -40,10 +40,6 @@ import {
import {PROTOCOL_COLORS} from "../../common/constants";
import Logout from "../user/Logout";
import {hasPermission, isAdmin} from "../../service/permission";
import AssetSSHAttributeModal from "./AssetSSHAttributeModal";
import AssetRDPAttributeModal from "./AssetRDPAttributeModal";
import AssetVNCAttributeModal from "./AssetVNCAttributeModal";
import AssetTelnetAttributeModal from "./AssetTelnetAttributeModal";
const confirm = Modal.confirm;
const {Search} = Input;
@ -89,8 +85,6 @@ class Asset extends Component {
users: [],
selected: {},
selectedSharers: [],
attrVisible: false,
attributes: {}
};
async componentDidMount() {
@ -230,34 +224,6 @@ class Asset extends Component {
await this.showModal('复制资产', result.data);
}
async attr(record) {
let result = await request.get(`/assets/${record['id']}/attributes`);
if (result.code !== 1) {
message.error(result.message, 10);
return;
}
// eslint-disable-next-line no-extend-native
String.prototype.bool = function () {
return (/^true$/i).test(this);
};
let attributes = result['data'];
for (const key in attributes) {
if (!attributes.hasOwnProperty(key)) {
continue;
}
if (key === 'swap-red-blue') {
attributes[key] = attributes[key].bool();
}
}
this.setState({
selected: record,
attrVisible: true,
attributes: attributes
});
}
async showModal(title, asset = {}) {
// 并行请求
let getCredentials = request.get('/credentials');
@ -447,30 +413,6 @@ class Asset extends Component {
})
}
handleUpdateAttr = async (formData) => {
// 弹窗 form 传来的数据
this.setState({
modalConfirmLoading: true
});
try {
let selected = this.state.selected;
let result = await request.put(`/assets/${selected['id']}/attributes?protocol=${selected['protocol']}`, formData);
if (result['code'] !== 1) {
message.error(result['message'], 10);
} else {
message.success('操作成功');
this.setState({
attrVisible: false
})
}
} finally {
this.setState({
modalConfirmLoading: false
});
}
}
handleCancelUpdateAttr = () => {
this.setState({
attrVisible: false,
@ -550,12 +492,6 @@ class Asset extends Component {
onClick={() => this.copy(record.id)}>复制</Button>
</Menu.Item>
<Menu.Item key="3">
<Button type="text" size='small'
disabled={!hasPermission(record['owner'])}
onClick={() => this.attr(record)}>属性</Button>
</Menu.Item>
{isAdmin() ?
<Menu.Item key="4">
<Button type="text" size='small'
@ -893,50 +829,6 @@ class Asset extends Component {
/>
</Modal> : undefined
}
{
this.state.attrVisible && this.state.selected['protocol'] === 'ssh' ?
<AssetSSHAttributeModal
handleOk={this.handleUpdateAttr}
handleCancel={this.handleCancelUpdateAttr}
confirmLoading={this.state.modalConfirmLoading}
attributes={this.state.attributes}
/>
: null
}
{
this.state.attrVisible && this.state.selected['protocol'] === 'rdp' ?
<AssetRDPAttributeModal
handleOk={this.handleUpdateAttr}
handleCancel={this.handleCancelUpdateAttr}
confirmLoading={this.state.modalConfirmLoading}
attributes={this.state.attributes}
/>
: null
}
{
this.state.attrVisible && this.state.selected['protocol'] === 'vnc' ?
<AssetVNCAttributeModal
handleOk={this.handleUpdateAttr}
handleCancel={this.handleCancelUpdateAttr}
confirmLoading={this.state.modalConfirmLoading}
attributes={this.state.attributes}
/>
: null
}
{
this.state.attrVisible && this.state.selected['protocol'] === 'telnet' ?
<AssetTelnetAttributeModal
handleOk={this.handleUpdateAttr}
handleCancel={this.handleCancelUpdateAttr}
confirmLoading={this.state.modalConfirmLoading}
attributes={this.state.attributes}
/>
: null
}
</Content>
</>
);