mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-19 01:11:07 +00:00
perf: 修改 protocol
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
<div v-for="(item, index) in items" :key="index" style="display: flex;margin-top: 8px;">
|
||||
<div v-for="(item, index) in items" :key="item.name" style="display: flex;margin-top: 8px;">
|
||||
<el-input v-model="item.port" class="input-with-select" v-bind="$attrs">
|
||||
<el-select slot="prepend" v-model="item.name" @change="handleProtocolChange($event, item)">
|
||||
<el-option v-for="p of remainProtocols" :key="p.name" :label="p.name" :value="p.name" />
|
||||
@@ -42,7 +42,7 @@ export default {
|
||||
},
|
||||
choices: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
default: () => ([])
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@@ -52,51 +52,33 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
protocols() {
|
||||
return this.choices.map(item => {
|
||||
const proto = item.split('/')
|
||||
return { name: proto[0], port: proto[1] }
|
||||
})
|
||||
},
|
||||
values() {
|
||||
return this.items.map(item => {
|
||||
return `${item.name}/${item.port}`
|
||||
})
|
||||
},
|
||||
itemsMap() {
|
||||
const mapper = {}
|
||||
for (const item of this.items) {
|
||||
mapper[item.name] = item
|
||||
}
|
||||
return mapper
|
||||
selectedProtocolNames() {
|
||||
return this.items.map(item => item.name)
|
||||
},
|
||||
remainProtocols() {
|
||||
return this.protocols.filter(proto => {
|
||||
return !this.itemsMap[proto.name]
|
||||
return this.choices.filter(proto => {
|
||||
return this.selectedProtocolNames.indexOf(proto.name) === -1
|
||||
})
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
values: {
|
||||
choices: {
|
||||
handler(value) {
|
||||
this.setDefaultItems(value)
|
||||
}
|
||||
},
|
||||
items: {
|
||||
handler(value) {
|
||||
this.$emit('input', value)
|
||||
},
|
||||
immediate: true,
|
||||
deep: true
|
||||
},
|
||||
choices: {
|
||||
handler(value) {
|
||||
this.setDefaultItems()
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.setDefaultItems()
|
||||
this.setDefaultItems(this.choices)
|
||||
},
|
||||
methods: {
|
||||
onInput(val) {
|
||||
this.$emit('input', 'my-input: ' + val)
|
||||
},
|
||||
handleDelete(index) {
|
||||
this.items = this.items.filter((value, i) => {
|
||||
return i !== index
|
||||
@@ -110,20 +92,14 @@ export default {
|
||||
item.name = selected.name
|
||||
item.port = selected.port
|
||||
},
|
||||
setDefaultItems() {
|
||||
let items = []
|
||||
if (this.value.length !== 0) {
|
||||
items = this.value.map(item => {
|
||||
const proto = item.split('/')
|
||||
return { name: proto[0], port: proto[1] }
|
||||
})
|
||||
const protocolsNames = this.protocols.map(item => item.name)
|
||||
items = items.filter(item => protocolsNames.indexOf(item.name) > -1)
|
||||
setDefaultItems(choices) {
|
||||
if (!this.value) {
|
||||
if (choices.length !== 0) {
|
||||
this.items = [choices[0]]
|
||||
}
|
||||
} else {
|
||||
this.items = [...this.value]
|
||||
}
|
||||
if (items.length === 0) {
|
||||
items.push({ ...this.protocols[0] })
|
||||
}
|
||||
this.items = items
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -46,11 +46,14 @@ const mutations = {
|
||||
const actions = {
|
||||
getAssetCategories({ commit, dispatch, state }) {
|
||||
return new Promise(resolve => {
|
||||
if (state.assetCategories.length > 0) {
|
||||
resolve(state)
|
||||
}
|
||||
apiGetCategoryTypes().then(data => {
|
||||
commit('SET_CATEGORIES', data)
|
||||
commit('SET_CATEGORIES_DROPDOWN', data)
|
||||
console.log('Set done')
|
||||
resolve(true)
|
||||
console.log('Get category done: ', state.assetCategories)
|
||||
resolve(state)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@@ -25,7 +25,9 @@ export default {
|
||||
initial: {
|
||||
comment: 'Hello world',
|
||||
charset: 'utf8',
|
||||
category_type: ['host', 'linux']
|
||||
category_type: ['host', 'linux'],
|
||||
domain_enabled: false,
|
||||
protocols_enabled: false
|
||||
},
|
||||
fields: [
|
||||
[this.$t('common.Basic'), [
|
||||
@@ -37,8 +39,11 @@ export default {
|
||||
[this.$t('assets.Domain'), [
|
||||
'domain_enabled', 'domain_default'
|
||||
]],
|
||||
[this.$t('assets.Auth'), [
|
||||
'admin_user_enabled', 'admin_user_default'
|
||||
[this.$t('assets.Account'), [
|
||||
'su_enabled', 'su_method',
|
||||
'verify_account_enabled', 'verify_account_method',
|
||||
'create_account_enabled', 'create_account_method',
|
||||
'change_password_enabled', 'change_password_method'
|
||||
]],
|
||||
[this.$t('common.Other'), ['comment']]
|
||||
],
|
||||
@@ -89,30 +94,27 @@ export default {
|
||||
],
|
||||
el: {
|
||||
multiple: false,
|
||||
options: this.$store.state.assets.assetCategoriesCascader
|
||||
options: []
|
||||
},
|
||||
on: {
|
||||
change: ([event], formValue) => {
|
||||
change: ([event], updateForm) => {
|
||||
const category = event[0]
|
||||
const type = event[1]
|
||||
this.setLimits(category, type)
|
||||
this.setLimits(category, type, updateForm)
|
||||
}
|
||||
}
|
||||
},
|
||||
admin_user_default: {
|
||||
...assetMeta.admin_user,
|
||||
hidden: (formValue) => {
|
||||
return !formValue['admin_user_enabled']
|
||||
}
|
||||
},
|
||||
protocols_enabled: {
|
||||
el: {
|
||||
disabled: false
|
||||
}
|
||||
disabled: false,
|
||||
value: false
|
||||
},
|
||||
value: false
|
||||
},
|
||||
protocols_default: {
|
||||
...assetMeta.protocols,
|
||||
hidden: (formValue) => {
|
||||
console.log('formValue', formValue)
|
||||
return !formValue['protocols_enabled']
|
||||
}
|
||||
},
|
||||
@@ -144,7 +146,10 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.setCategoryOnCreate()
|
||||
this.$store.dispatch('assets/getAssetCategories').then((state) => {
|
||||
this.fieldsMeta.category_type.el.options = state.assetCategoriesCascader
|
||||
this.setCategoryOnCreate()
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
setCategoryOnCreate() {
|
||||
@@ -154,22 +159,22 @@ export default {
|
||||
return
|
||||
}
|
||||
},
|
||||
toOption(choice) {
|
||||
return {
|
||||
label: choice['display_name'],
|
||||
value: choice['value']
|
||||
}
|
||||
},
|
||||
async setLimits(category, type) {
|
||||
const url = `/api/v1/assets/platforms/type-limits/?category=${category}&type=${type}`
|
||||
const limits = await this.$axios.get(url)
|
||||
const hasDomain = limits['has_domain']
|
||||
const protocolLimits = limits['protocols_limit']
|
||||
async setLimits(category, type, updateForm) {
|
||||
const url = `/api/v1/assets/platforms/type-constraints/?category=${category}&type=${type}`
|
||||
const constraints = await this.$axios.get(url)
|
||||
const hasDomain = constraints['has_domain']
|
||||
this.fieldsMeta.domain_enabled.el.disabled = !hasDomain
|
||||
this.fieldsMeta.domain_enabled.value = !!hasDomain
|
||||
|
||||
this.fieldsMeta.protocols_enabled.el.disabled = protocolLimits.length === 0
|
||||
this.fieldsMeta.protocols_default.el.choices = protocolLimits
|
||||
const protocols = constraints['protocols'] || []
|
||||
this.fieldsMeta.protocols_enabled.el.disabled = protocols.length === 0
|
||||
this.fieldsMeta.protocols_default.el.choices = protocols
|
||||
|
||||
if (updateForm) {
|
||||
updateForm({
|
||||
protocols_enabled: !!protocols.length,
|
||||
domain_enabled: hasDomain
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,14 +10,10 @@ export const assetFieldsMeta = (vm) => {
|
||||
},
|
||||
protocols: {
|
||||
component: ProtocolSelector,
|
||||
on: {
|
||||
input: ([value], updateForm) => {
|
||||
vm.fieldsMeta.accounts.el.protocols = value.map(item => {
|
||||
return item.split('/')[0]
|
||||
})
|
||||
}
|
||||
},
|
||||
el: {}
|
||||
on: {},
|
||||
el: {
|
||||
choices: []
|
||||
}
|
||||
},
|
||||
platform: {
|
||||
el: {
|
||||
|
Reference in New Issue
Block a user