perf: 修改平台和资产

This commit is contained in:
ibuler
2022-09-08 20:29:56 +08:00
parent 7fa7096d91
commit ccfb7356eb
4 changed files with 52 additions and 67 deletions

View File

@@ -47,9 +47,8 @@ export default {
data() {
return {
defaultSetting: {
required: false,
default: true,
is_active: true
sftp_enabled: true,
sftp_home: '/tmp'
},
loading: true,
form: {},
@@ -60,51 +59,37 @@ export default {
hasButtons: !this.disabled,
url: '',
fields: [
[
this.$t('common.Basic'), [
{
id: 'required',
label: '必须配置',
helpText: '新建资产时,必须开启该协议',
type: 'switch'
},
{
id: 'default',
label: '默认配置',
helpText: '新建资产时,默认显示',
type: 'switch'
}
{
id: 'console',
label: 'Console',
type: 'switch',
hidden: () => this.item.name !== 'rdp'
},
{
id: 'security',
label: 'Security',
hidden: () => this.item.name !== 'rdp',
type: 'radio-group',
options: [
{ label: 'Any', value: 'any' },
{ label: 'RDP', value: 'rdp' },
{ label: 'NLA', value: 'nla' },
{ label: 'TLS', value: 'tls' }
]
],
[
this.$t('assets.Protocol'), [
{
id: 'console',
label: 'Console',
type: 'switch',
hidden: () => this.item.name !== 'rdp'
},
{
id: 'security',
label: 'Security',
hidden: () => this.item.name !== 'rdp',
type: 'radio-group',
options: [
{ label: 'Any', value: 'any' },
{ label: 'RDP', value: 'rdp' },
{ label: 'NLA', value: 'nla' },
{ label: 'TLS', value: 'tls' }
]
},
{
id: 'sftp_home',
label: 'SFTP home',
type: 'input',
helpText: this.$t('assets.SFTPHelpMessage'),
hidden: () => this.item.name !== 'sftp'
}
]
]
},
{
id: 'sftp_enabled',
label: '启用 SFTP',
type: 'switch',
hidden: () => this.item.name !== 'ssh'
},
{
id: 'sftp_home',
label: 'SFTP home',
type: 'input',
helpText: this.$t('assets.SFTPHelpMessage'),
hidden: (form) => this.item.name !== 'ssh' || !form['sftp_enabled']
}
]
}
}
@@ -116,7 +101,6 @@ export default {
},
onOpen() {
this.form = this.item.setting || this.defaultSetting
console.log('Item: ', this.item, this.form)
}
}
}

View File

@@ -130,13 +130,11 @@ export default {
item.port = selected.port
},
setDefaultItems(choices) {
if (this.value && this.value.length > 0) {
this.items = [...this.value]
return
}
if (choices.length !== 0) {
this.items = [choices[0]]
let defaults = this.value
if (defaults.length === 0 && choices.length !== 0) {
defaults = choices
}
this.items = defaults
},
onSettingClick(item) {
this.settingItem = item

View File

@@ -50,20 +50,16 @@ export default {
const platformId = this.$route.query['platform'] || 1
const url = `/api/v1/assets/platforms/${platformId}/`
this.platform = await this.$axios.get(url)
let protocols = this.platform.protocols.filter(p => {
return p.setting.default || p.setting.required
})
if (protocols.length === 0) {
protocols = this.platform.protocols[0]
}
const initial = {
platform: parseInt(platformId),
protocols: protocols,
nodes: nodesInitial,
domain: this.platform['domain_default']
protocols: [],
nodes: nodesInitial
}
Object.assign(this.initial, initial)
this.fieldsMeta.protocols.el.choices = this.platform['protocols']
if (this.platform.domain_enabled === false) {
this.fieldsMeta.domain.hidden = () => true
}
}
}
}

View File

@@ -22,8 +22,6 @@ export default {
GenericCreateUpdatePage
},
data() {
const category = this.$route.query.category
const type = this.$route.query.type
const assetMeta = assetFieldsMeta()
return {
loading: true,
@@ -48,7 +46,7 @@ export default {
'name', 'category_type'
]],
[this.$t('assets.Asset'), [
'charset',
'charset', 'domain_enabled',
'protocols_enabled', 'protocols',
'gather_facts_enabled', 'gather_facts_method'
]],
@@ -84,6 +82,11 @@ export default {
disabled: false
}
},
domain_enabled: {
el: {
disabled: false
}
},
protocols: {
label: '支持的协议',
...assetMeta.protocols,
@@ -104,7 +107,7 @@ export default {
type: 'select'
}
},
url: `/api/v1/assets/platforms/?category=${category}&type=${type}`,
url: `/api/v1/assets/platforms/`,
cleanFormValue: (values) => {
const category_type = values['category_type']
values['category'] = category_type[0]
@@ -150,6 +153,10 @@ export default {
this.fieldsMeta.protocols.el.choices = protocols
this.initial.protocols_enabled = !!protocols.length
const domainDisabled = constraints['domain_enabled'] === false
this.fieldsMeta.domain_enabled.el.disabled = domainDisabled
this.initial.domain_enabled = !domainDisabled
for (const itemOk of this.opsItems) {
const itemConstraint = constraints[itemOk]
const itemMethod = itemOk.replace('_enabled', '_method')