perf: gateway

This commit is contained in:
feng
2022-12-02 11:19:21 +08:00
parent bbc43b7ec6
commit e51d13a47b
2 changed files with 95 additions and 99 deletions

View File

@@ -1,111 +1,109 @@
<template> <template>
<GenericCreateUpdatePage v-bind="$data" /> <GenericCreateUpdatePage v-if="!loading" v-bind="iConfig" />
</template> </template>
<script> <script>
import GenericCreateUpdatePage from '@/layout/components/GenericCreateUpdatePage' import GenericCreateUpdatePage from '@/layout/components/GenericCreateUpdatePage'
import { Select2, UploadKey } from '@/components' import { assetFieldsMeta } from '@/views/assets/const'
import { UpdateToken } from '@/components/FormFields'
import ProtocolSelector from '../components/ProtocolSelector'
export default { export default {
name: 'GatewayCreateUpdate', name: 'GatewayCreateUpdate',
components: { GenericCreateUpdatePage }, components: { GenericCreateUpdatePage },
data() { data() {
return { return {
initial: { loading: true,
is_active: true, platform: {},
protocols: '', defaultConfig: {
domain: this.$route.query.domain initial: {},
}, platform: {},
fields: [ url: '/api/v1/assets/gateways/',
[this.$t('common.Basic'), ['name', 'address']], hasDetailInMsg: false,
[this.$t('assets.Network'), ['domain', 'protocols']], fields: [
[this.$t('assets.Auth'), ['username', 'password', 'private_key', 'passphrase']], [this.$t('common.Basic'), ['name', 'address', 'platform']],
[this.$t('common.Other'), ['is_active', 'comment']] [this.$t('assets.Network'), ['domain', 'protocols']],
], [this.$t('assets.Account'), ['accounts']],
fieldsMeta: { [this.$t('assets.Node'), ['nodes']],
domain: { [this.$t('assets.Label'), ['labels']],
component: Select2, [this.$t('common.Other'), ['is_active', 'comment']]
el: { ],
ajax: { fieldsMeta: assetFieldsMeta(this),
url: '/api/v1/assets/domains/' cleanFormValue(values) {
}, const { id = '' } = this.$route.params
disabled: true, if (id) delete values['accounts']
multiple: false return values
}
}, },
protocols: { getNextRoute(res, method) {
component: ProtocolSelector, const domain = res.domain.id
el: { const route = {
}, name: 'DomainDetail',
hidden: (form) => { params: {
const fieldsMeta = this.fieldsMeta id: domain
if (form['protocols']) { },
fieldsMeta['protocols'].el.choices = form['protocols'] query: {
activeTab: 'GatewayList'
} }
} }
}, return route
username: {
el: {
type: 'text'
}
},
password: {
component: UpdateToken
},
private_key: {
component: UploadKey
},
is_active: {
type: 'switch'
} }
},
updateSuccessNextRoute: {
name: 'DomainDetail',
params: {
id: ''
}
},
createSuccessNextRoute: {
name: 'DomainDetail',
params: {
}
},
url: `/api/v1/assets/gateways/`,
hasDetailInMsg: false,
afterGetFormValue(formValue) {
formValue.username = formValue.username_display
return formValue
},
getNextRoute(res, method) {
const domain = res.domain
const route = {
name: 'DomainDetail',
params: {
id: domain
},
query: {
activeTab: 'GatewayList'
}
}
return route
},
cleanFormValue(values) {
if (this.$route.params.id && !values.password) {
delete values['password']
}
return values
} }
} }
}, },
mounted() { computed: {
iConfig() {
const { url, defaultConfig } = this
// 过滤类型为null, undefined 的元素
defaultConfig.fields = defaultConfig.fields.filter(Boolean)
const config = _.merge(defaultConfig, { url })
return config
}
},
async created() {
try {
await this.setInitial()
await this.setPlatformConstrains()
} finally {
this.loading = false
}
}, },
methods: { methods: {
async setInitial() {
const { defaultConfig } = this
const { node } = this.$route?.query || {}
const nodesInitial = node ? [node] : []
const url = `/api/v1/assets/platforms/?name=Gateway`
this.platform = await this.$axios.get(url)
this.platform = this.platform[0]
const initial = {
labels: [],
is_active: true,
nodes: nodesInitial,
platform: parseInt(this.platform.id),
protocols: [],
domain: this.$route.query.domain
}
if (this.updateInitial) {
this.updateInitial(initial)
}
this.defaultConfig.initial = Object.assign({}, initial, defaultConfig.initial)
},
async setPlatformConstrains() {
const { platform } = this
const protocols = platform.protocols.filter(item => item.name === 'ssh')
this.defaultConfig.fieldsMeta.protocols.el.choices.splice(0, 0, ...protocols)
this.defaultConfig.fieldsMeta.accounts.el.platform = platform
this.defaultConfig.fieldsMeta.domain.disabled = true
const hiddenCheckFields = ['protocols', 'domain']
for (const field of hiddenCheckFields) {
if (platform[field + '_enabled'] === false) {
this.defaultConfig.fieldsMeta[field].hidden = () => true
}
}
}
} }
} }
</script> </script>
<style lang='less' scoped> <style>
</style> </style>

View File

@@ -36,7 +36,6 @@
<script> <script>
import GenericListTable from '@/layout/components/GenericListTable/index' import GenericListTable from '@/layout/components/GenericListTable/index'
import DisplayFormatter from '@/components/TableFormatters/DisplayFormatter'
import Dialog from '@/components/Dialog' import Dialog from '@/components/Dialog'
export default { export default {
@@ -55,23 +54,21 @@ export default {
return { return {
tableConfig: { tableConfig: {
url: `/api/v1/assets/gateways/?domain=${this.$route.params.id}`, url: `/api/v1/assets/gateways/?domain=${this.$route.params.id}`,
columns: ['name', 'address', 'port', 'username_display', 'comment', 'actions'], columns: ['name', 'address', 'platform', 'connectivity', 'is_active', 'actions'],
columnsMeta: { columnsMeta: {
name: { name: {
sortable: 'custom', sortable: 'custom',
formatter: DisplayFormatter formatter: function(row) {
const to = {
name: 'AssetDetail',
params: { id: row.id }
}
return <router-link to={ to } >{ row.name }</router-link>
}
}, },
address: { address: {
width: '140px' width: '140px'
}, },
port: {
width: '120px',
label: this.$t('assets.SshPort'),
formatter: (row) => {
console.log('row', row)
return row.protocols ? row.protocols[0].port : '-'
}
},
actions: { actions: {
formatterArgs: { formatterArgs: {
updateRoute: 'GatewayUpdate', updateRoute: 'GatewayUpdate',
@@ -87,10 +84,11 @@ export default {
title: this.$t('assets.TestConnection'), title: this.$t('assets.TestConnection'),
callback: function(val) { callback: function(val) {
this.dialogVisible = true this.dialogVisible = true
if (!val.row.port) { const port = val.row.protocols.find(item => item.name === 'ssh').port
if (!port) {
return this.$message.error(this.$tc('common.BadRequestErrorMsg')) return this.$message.error(this.$tc('common.BadRequestErrorMsg'))
} else { } else {
this.portInput = val.row.port this.portInput = port
this.cellValue = val.row.id this.cellValue = val.row.id
} }
}.bind(this) }.bind(this)