perf: 优化 protocol setting

This commit is contained in:
ibuler 2023-07-07 18:51:20 +08:00
parent 09dabb5d3f
commit ddf9780f9c
2 changed files with 16 additions and 40 deletions

View File

@ -5,7 +5,7 @@
:destroy-on-close="true"
:show-cancel="false"
:show-confirm="false"
:title="$tc('assets.PlatformProtocolConfig') + '' + item.name"
:title="$tc('assets.PlatformProtocolConfig') + '' + protocol.name"
class="setting-dialog"
v-bind="$attrs"
width="70%"
@ -38,7 +38,7 @@ export default {
AutoDataForm
},
props: {
item: {
protocol: {
type: Object,
default: () => ({})
},
@ -51,23 +51,13 @@ export default {
const vm = this
const platform = this.$route.query.platform
return {
baseAttrs: ['primary', 'required', 'default', 'public'], // setting
defaultSetting: {
sftp_enabled: true,
sftp_home: '/tmp',
username_selector: '#username',
password_selector: '#password',
submit_selector: '.btn-submit',
security: 'any',
console: false
},
loading: true,
form: {},
form: this.protocol,
platformDetail: platform ? '#/console/assets/platforms/' + platform : '',
config: {
hasSaveContinue: false,
hasButtons: !this.disabled,
url: '/api/v1/assets/protocol-settings/?name=' + this.item.name,
url: '/api/v1/assets/protocol-settings/?name=' + this.protocol.name,
fields: [
[vm.$t('common.Basic'), [
'primary', 'required', 'default', 'public'
@ -82,25 +72,11 @@ export default {
}
}
},
created() {
this.form = this.item.setting
if (!this.form || !this.item) {
return
}
for (const i of this.baseAttrs) {
this.form[i] = !!this.item[i]
}
},
methods: {
onSubmit(form) {
for (const i of this.baseAttrs) {
if (form.hasOwnProperty(i)) {
this.item[i] = form[i]
}
}
this.item.setting = form
this.protocol = Object.assign(this.protocol, form)
this.$emit('update:visible', false)
this.$emit('confirm', this.item)
this.$emit('confirm', this.protocol)
}
}
}

View File

@ -62,7 +62,7 @@
<ProtocolSettingDialog
v-if="showDialog"
:disabled="settingReadonly || readonly"
:item="settingItem"
:protocol="currentProtocol"
:visible.sync="showDialog"
@confirm="handleSettingConfirm"
/>
@ -108,7 +108,7 @@ export default {
return {
name: '',
items: [],
settingItem: {},
currentProtocol: {},
showDialog: false,
loading: false
}
@ -167,20 +167,20 @@ export default {
},
methods: {
handleSettingConfirm() {
if (this.settingItem.primary) {
if (this.currentProtocol.primary) {
const others = this.items
.filter(item => item.name !== this.settingItem.name)
.filter(item => item.name !== this.currentProtocol.name)
.map(item => {
item.primary = false
return item
})
this.items = [this.settingItem, ...others]
this.items = [this.currentProtocol, ...others]
}
if (this.settingItem.name === 'winrm') {
if (this.settingItem.setting?.use_ssl) {
this.settingItem.port = 5986
if (this.currentProtocol.name === 'winrm') {
if (this.currentProtocol.setting?.use_ssl) {
this.currentProtocol.port = 5986
} else {
this.settingItem.port = 5985
this.currentProtocol.port = 5985
}
}
},
@ -271,7 +271,7 @@ export default {
return protocols
},
onSettingClick(item) {
this.settingItem = item
this.currentProtocol = item
this.showDialog = true
}
}