feat: 优化创建是选择默认的资产和节点 feat: 优化protocols选择

This commit is contained in:
ibuler
2020-06-08 13:41:01 +08:00
parent 1ec46d11ce
commit b0f0c55063
10 changed files with 114 additions and 21 deletions

View File

@@ -73,7 +73,6 @@ export default {
} }
}, },
mounted() { mounted() {
}, },
methods: { methods: {
editTreeNode: function() { editTreeNode: function() {
@@ -96,9 +95,11 @@ export default {
if (treeNode.meta.type === 'node') { if (treeNode.meta.type === 'node') {
this.currentNode = treeNode this.currentNode = treeNode
this.currentNodeId = treeNode.meta.node.id this.currentNodeId = treeNode.meta.node.id
this.$route.query['node'] = this.currentNodeId
this.$emit('urlChange', `${this.setting.url}?node_id=${treeNode.meta.node.id}&show_current_asset=null`) this.$emit('urlChange', `${this.setting.url}?node_id=${treeNode.meta.node.id}&show_current_asset=null`)
} else if (treeNode.meta.type === 'asset') { } else if (treeNode.meta.type === 'asset') {
this.$emit('urlChange', `${this.setting.url}?asset_id=${treeNode.meta.asset.id}&show_current_asset=null`) this.$emit('urlChange', `${this.setting.url}?asset_id=${treeNode.meta.asset.id}&show_current_asset=null`)
this.$route.query['asset'] = treeNode.meta.asset.id
} }
}, },
removeTreeNode: function() { removeTreeNode: function() {

View File

@@ -24,7 +24,7 @@ export default {
default: '' default: ''
}, },
createRoute: { createRoute: {
type: String, type: [String, Object],
default: function() { default: function() {
return this.$route.name.replace('List', 'Create') return this.$route.name.replace('List', 'Create')
} }
@@ -112,8 +112,13 @@ export default {
}, },
methods: { methods: {
handleCreate() { handleCreate() {
const routeName = this.createRoute let route = {}
this.$router.push({ name: routeName }) if (typeof this.createRoute === 'string') {
route.name = this.createRoute
} else {
route = this.createRoute
}
this.$router.push(route)
this.$log.debug('handle create') this.$log.debug('handle create')
}, },
defaultBulkDeleteCallback({ selectedRows, reloadTable }) { defaultBulkDeleteCallback({ selectedRows, reloadTable }) {

View File

@@ -152,6 +152,7 @@
"DateLastMonth": "最近一月", "DateLastMonth": "最近一月",
"DateLast3Months": "最近三月", "DateLast3Months": "最近三月",
"MFAConfirm": "MFA 认证", "MFAConfirm": "MFA 认证",
"SelectPlaceholder": "请选择",
"Yes": "是", "Yes": "是",
"No": "否", "No": "否",
"Remove":"删除", "Remove":"删除",

View File

@@ -151,6 +151,7 @@
"DateLastMonth": "Last month", "DateLastMonth": "Last month",
"DateLast3Months": "Last 3 months", "DateLast3Months": "Last 3 months",
"MFAConfirm": "MFA Confirm", "MFAConfirm": "MFA Confirm",
"SelectPlaceholder": "Select",
"Yes": "Yes", "Yes": "Yes",
"Remove":"Remove", "Remove":"Remove",
"No": "No", "No": "No",

View File

@@ -11,6 +11,10 @@ $--color-info: #23c6c8;
$--color-warning: #f8ac59; $--color-warning: #f8ac59;
$--color-danger: #ed5565; $--color-danger: #ed5565;
$--color-text-primary: #303133;
/// color|1|Font Color|2
$--color-text-regular: #606266;
.el-upload { .el-upload {
input[type="file"] { input[type="file"] {
display: none !important; display: none !important;
@@ -434,3 +438,11 @@ a {
.el-alert .el-alert__description { .el-alert .el-alert__description {
margin: 1px 0 0; margin: 1px 0 0;
} }
.el-input-group__prepend div.el-select .el-input__inner {
color: $--color-text-primary;
}
.el-input-group__prepend div.el-select .el-input__inner:hover {
color: $--color-text-primary;
}

View File

@@ -4,17 +4,23 @@
<script> <script>
import GenericCreateUpdatePage from '@/layout/components/GenericCreateUpdatePage' import GenericCreateUpdatePage from '@/layout/components/GenericCreateUpdatePage'
import CustomInput from '@/components/CustomInput' import Protocols from './components/Protocols'
export default { export default {
name: 'AssetCreateUpdate', name: 'AssetCreateUpdate',
components: { components: {
GenericCreateUpdatePage GenericCreateUpdatePage
}, },
data() { data() {
const nodesInitial = []
if (this.$route.query['node']) {
nodesInitial.push(this.$route.query.node)
}
return { return {
initial: { initial: {
is_active: true, is_active: true,
platform: 'Linux' platform: 'Linux',
protocols: ['ssh/22'],
nodes: nodesInitial
}, },
fields: [ fields: [
[this.$t('assets.Basic'), ['hostname', 'ip', 'platform', 'public_ip', 'domain']], [this.$t('assets.Basic'), ['hostname', 'ip', 'platform', 'public_ip', 'domain']],
@@ -26,7 +32,7 @@ export default {
], ],
fieldsMeta: { fieldsMeta: {
protocols: { protocols: {
component: CustomInput component: Protocols
}, },
platform: { platform: {
el: { el: {

View File

@@ -77,7 +77,10 @@ export default {
} }
}, },
headerActions: { headerActions: {
createRoute: 'AssetCreate', createRoute: {
name: 'AssetCreate',
query: this.$route.query
},
extraMoreActions: [ extraMoreActions: [
{ {
name: 'DeactiveSelected', name: 'DeactiveSelected',

View File

@@ -1,17 +1,14 @@
<template> <template>
<div> <div>
<div v-for="(item,index) in items" :key="index" style="display: flex;justify-content: space-around;margin-top: 8px;"> <div v-for="(item,index) in items" :key="index" style="display: flex;justify-content: space-around;margin-top: 8px;">
<el-input v-model="item.value" :placeholder="placeholder" class="input-with-select" v-bind="$attrs"> <el-input v-model="item.value" class="input-with-select" v-bind="$attrs">
<el-select slot="prepend" v-model="item.select" placeholder="请选择"> <el-select slot="prepend" v-model="item.select" @change="handleProtocolChange">
<el-option label="ssh" value="ssh" /> <el-option v-for="p of remainProtocols" :key="p.name" :label="p.name" :value="p.name" />
<el-option label="vnc" value="vnc" />
<el-option label="rdp" value="rdp" />
<el-option label="telnet" value="telnet" />
</el-select> </el-select>
</el-input> </el-input>
<div style="display: flex"> <div style="display: flex" class="input-button">
<el-button type="danger" icon="el-icon-minus" style="flex-shrink: 0;" size="mini" :disabled="items.length===1" @click="handleDelete(index)" /> <el-button type="danger" icon="el-icon-minus" style="flex-shrink: 0;" size="mini" :disabled="items.length===1" @click="handleDelete(index)" />
<el-button type="success" icon="el-icon-plus" style="flex-shrink: 0;" size="mini" @click="handleAdd(index)" /> <el-button type="primary" icon="el-icon-plus" style="flex-shrink: 0;" size="mini" @click="handleAdd(index)" />
</div> </div>
</div> </div>
</div> </div>
@@ -27,10 +24,6 @@ export default {
title: { title: {
type: String, type: String,
default: '' default: ''
},
placeholder: {
type: String,
default: () => ''
} }
}, },
data() { data() {
@@ -41,6 +34,24 @@ export default {
value: '', value: '',
select: '' select: ''
} }
],
protocols: [
{
name: 'ssh',
port: 22
},
{
name: 'rdp',
port: 3389
},
{
name: 'telnet',
port: 23
},
{
name: 'vnc',
port: 5901
}
] ]
} }
}, },
@@ -51,6 +62,22 @@ export default {
data.push(`${i.select}/${i.value}`) data.push(`${i.select}/${i.value}`)
}) })
return data return data
},
itemsMap() {
const mapper = {}
for (const item of this.items) {
mapper[item.select] = item
}
return mapper
},
remainProtocols() {
const remain = []
for (const item of this.protocols) {
if (!this.itemsMap[item.name]) {
remain.push(item)
}
}
return remain
} }
}, },
watch: { watch: {
@@ -90,6 +117,21 @@ export default {
select: '' select: ''
} }
) )
},
handleProtocolChange(val) {
let port = 22
switch (val) {
case 'rdp':
port = 3389
break
case 'telnet':
port = 23
break
case 'vnc':
port = 5901
break
}
this.itemsMap[val].value = port
} }
} }
} }
@@ -111,4 +153,12 @@ export default {
.el-select /deep/ .el-input__inner { .el-select /deep/ .el-input__inner {
width: 100px; width: 100px;
} }
.input-button {
margin-top: 4px;
}
.input-button /deep/ .el-button.el-button--mini {
height: 25px;
padding: 5px;
}
</style> </style>

View File

@@ -11,11 +11,21 @@ export default {
GenericCreateUpdatePage GenericCreateUpdatePage
}, },
data() { data() {
const nodesInitial = []
if (this.$route.query['node']) {
nodesInitial.push(this.$route.query.node)
}
const assetsInitial = []
if (this.$route.query['asset']) {
assetsInitial.push(this.$route.query.asset)
}
return { return {
initial: { initial: {
is_active: true, is_active: true,
actions: ['all', 'connect', 'updownload', 'upload_file', 'download_file'], actions: ['all', 'connect', 'updownload', 'upload_file', 'download_file'],
date_expired: '2099-12-31 00:00:00 +0800' date_expired: '2099-12-31 00:00:00 +0800',
nodes: nodesInitial,
assets: assetsInitial
}, },
fields: [ fields: [
[this.$t('perms.Basic'), ['name']], [this.$t('perms.Basic'), ['name']],

View File

@@ -97,6 +97,10 @@ export default {
} }
}, },
headerActions: { headerActions: {
createRoute: {
name: 'AssetPermissionCreate',
query: this.$route.query
},
hasRightActions: false, hasRightActions: false,
hasBulkDelete: false, hasBulkDelete: false,
hasBulkUpdate: false, hasBulkUpdate: false,