mirror of
https://github.com/jumpserver/lina.git
synced 2026-01-13 19:35:24 +00:00
pref: 修改资产创建
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<AutoDataForm v-bind="$data" @submit="confirm" />
|
||||
<AutoDataForm v-loading="loading" v-bind="$data" @submit="confirm" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -11,13 +11,9 @@ export default {
|
||||
AutoDataForm
|
||||
},
|
||||
props: {
|
||||
protocols: {
|
||||
type: Array,
|
||||
default: () => ([])
|
||||
},
|
||||
accounts: {
|
||||
type: Array,
|
||||
default: () => ([])
|
||||
platform: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
account: {
|
||||
type: Object,
|
||||
@@ -26,6 +22,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: true,
|
||||
url: '/api/v1/assets/accounts/',
|
||||
form: this.account || { },
|
||||
fields: [
|
||||
@@ -45,12 +42,12 @@ export default {
|
||||
}
|
||||
},
|
||||
password: {
|
||||
label: 'Password',
|
||||
label: this.$t('assets.Password'),
|
||||
component: UpdateToken,
|
||||
hidden: (formValue) => formValue['secret_type'] !== 'password'
|
||||
},
|
||||
ssh_key: {
|
||||
label: 'SSH private key',
|
||||
label: this.$t('assets.SSHPrivateKey'),
|
||||
el: {
|
||||
type: 'textarea',
|
||||
rows: 4
|
||||
@@ -72,7 +69,7 @@ export default {
|
||||
},
|
||||
api_key: {
|
||||
id: 'api_key',
|
||||
label: 'Secret key',
|
||||
label: this.$t('assets.SecretKey'),
|
||||
el: {
|
||||
type: 'textarea',
|
||||
rows: 4
|
||||
@@ -80,26 +77,48 @@ export default {
|
||||
hidden: (formValue) => formValue['secret_type'] !== 'api_key'
|
||||
},
|
||||
secret_type: {
|
||||
label: 'Secret Type',
|
||||
type: 'radio-group',
|
||||
options: [
|
||||
{ label: 'Password', value: 'password' },
|
||||
{ label: 'SSH key', value: 'ssh_key' },
|
||||
{ label: 'Token', value: 'token' },
|
||||
{ label: 'Api key', value: 'api_key' }
|
||||
{ label: 'Password', value: 'password' }
|
||||
]
|
||||
},
|
||||
push_now: {
|
||||
hidden: () => {
|
||||
return !this.platform.automation['push_account_enabled']
|
||||
}
|
||||
}
|
||||
},
|
||||
hasSaveContinue: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
console.log('protocols: ', this.protocols)
|
||||
console.log('this.account: ', this.account)
|
||||
this.setSecretTypes().then(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
async setSecretTypes() {
|
||||
const options = [
|
||||
{ label: 'Password', value: 'password' },
|
||||
{ label: 'SSH key', value: 'ssh_key' },
|
||||
{ label: 'Token', value: 'token' },
|
||||
{ label: 'Api key', value: 'api_key' }
|
||||
]
|
||||
const secretTypes = []
|
||||
this.platform.protocols.forEach(p => {
|
||||
secretTypes.push(...p['secret_types'])
|
||||
})
|
||||
if (!this.form.secret_type) {
|
||||
this.form.secret_type = secretTypes[0]
|
||||
}
|
||||
const supportOptions = options.filter(item => {
|
||||
return secretTypes.indexOf(item.value) > -1
|
||||
})
|
||||
if (supportOptions.length > 0) {
|
||||
this.fieldsMeta.secret_type.options = supportOptions
|
||||
}
|
||||
},
|
||||
confirm(form) {
|
||||
console.log('Account form: accout is: ', this.account)
|
||||
if (this.account?.name) {
|
||||
this.$emit('edit', form)
|
||||
} else {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
width="70%"
|
||||
>
|
||||
<AccountCreateForm
|
||||
:protocols="protocols"
|
||||
:platform="platform"
|
||||
:account="account"
|
||||
@add="addAccount"
|
||||
@edit="editAccount"
|
||||
@@ -62,9 +62,9 @@ export default {
|
||||
AccountCreateForm
|
||||
},
|
||||
props: {
|
||||
protocols: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
platform: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
value: {
|
||||
type: [Array],
|
||||
@@ -146,7 +146,6 @@ export default {
|
||||
this.templateTable.visible = true
|
||||
},
|
||||
onSelectTemplate() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ export default {
|
||||
}
|
||||
|
||||
.el-select {
|
||||
width: 100px;
|
||||
max-width: 120px;
|
||||
}
|
||||
|
||||
.input-with-select {
|
||||
@@ -171,7 +171,7 @@ export default {
|
||||
}
|
||||
|
||||
.el-select ::v-deep .el-input__inner {
|
||||
width: 100px;
|
||||
width: 110px;
|
||||
}
|
||||
|
||||
.input-button {
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
"NoSQLProtocol": "非关系数据库"
|
||||
},
|
||||
"assets": {
|
||||
"Network": "网络",
|
||||
"All": "所有",
|
||||
"Cloud": "云服务",
|
||||
"CloudPlatform": "云平台",
|
||||
@@ -278,6 +279,7 @@
|
||||
"ReLoginErr": "登录时长已超过 5 分钟,请重新登录"
|
||||
},
|
||||
"common": {
|
||||
"Selector": "选择器",
|
||||
"NeedAddAppsOrSystemUserErrMsg": "需要添加应用或系统用户",
|
||||
"VerificationCodeSent": "验证码已发送",
|
||||
"SendVerificationCode": "发送验证码",
|
||||
|
||||
@@ -31,14 +31,14 @@ export default {
|
||||
updateSuccessNextRoute: { name: 'AssetList' },
|
||||
hasDetailInMsg: false,
|
||||
fields: [
|
||||
[this.$t('common.Basic'), ['name', 'address', 'platform', 'domain']],
|
||||
[this.$t('assets.Protocols'), ['protocols']],
|
||||
[this.$t('assets.Node'), ['nodes']],
|
||||
[this.$t('common.Basic'), ['name', 'address', 'platform']],
|
||||
[this.$t('assets.Network'), ['domain', 'protocols']],
|
||||
[this.$t('assets.Account'), ['accounts']],
|
||||
[this.$t('assets.Node'), ['nodes']],
|
||||
[this.$t('assets.Label'), ['labels']],
|
||||
[this.$t('common.Other'), ['is_active', 'comment']]
|
||||
],
|
||||
fieldsMeta: assetFieldsMeta()
|
||||
fieldsMeta: assetFieldsMeta(this)
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -48,14 +48,13 @@ export default {
|
||||
// 过滤类型为:null, undefined 的元素
|
||||
defaultConfig.fields = defaultConfig.fields.filter(Boolean)
|
||||
const config = _.merge(defaultConfig, { url })
|
||||
if (addFields.length > 0) {
|
||||
const defaultFields = Object.fromEntries(config.fields)
|
||||
for (const [key, value] of addFields) {
|
||||
if (defaultFields.hasOwnProperty(key)) {
|
||||
defaultFields[key] = new Set([...defaultFields[key], ...(value || [])])
|
||||
}
|
||||
for (const [groupName, adds] of addFields) {
|
||||
const group = config.fields.find(([name]) => name === groupName)
|
||||
if (group) {
|
||||
group[1] = group[1].concat(adds)
|
||||
} else {
|
||||
config.fields.splice(1, 0, [groupName, adds])
|
||||
}
|
||||
config.fields = Object.entries(defaultFields)
|
||||
}
|
||||
return config
|
||||
}
|
||||
@@ -87,8 +86,8 @@ export default {
|
||||
},
|
||||
async setPlatformConstrains() {
|
||||
const { platform } = this
|
||||
this.$set(this.defaultConfig.fieldsMeta.protocols.el, 'choices', (platform['protocols'] || []))
|
||||
this.$set(this.defaultConfig.fieldsMeta.accounts.el, 'protocols', (platform['protocols'] || []))
|
||||
this.defaultConfig.fieldsMeta.protocols.el.choices.splice(0, 0, ...platform.protocols)
|
||||
this.defaultConfig.fieldsMeta.accounts.el.platform = platform
|
||||
const hiddenCheckFields = ['protocols', 'domain']
|
||||
|
||||
for (const field of hiddenCheckFields) {
|
||||
|
||||
@@ -10,7 +10,10 @@ export default {
|
||||
components: { BaseAssetCreateUpdate },
|
||||
data() {
|
||||
return {
|
||||
url: '/api/v1/assets/webs/'
|
||||
url: '/api/v1/assets/webs/',
|
||||
addFields: [
|
||||
[this.$t('common.Selector'), ['username_selector', 'password_selector', 'submit_selector']]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,31 @@ import AssetAccounts from '@/components/FormFields/AssetAccounts'
|
||||
import rules from '@/components/DataForm/rules'
|
||||
import { Select2 } from '@/components/FormFields'
|
||||
|
||||
export const assetFieldsMeta = () => {
|
||||
export const assetFieldsMeta = (vm) => {
|
||||
const platformProtocols = []
|
||||
const secretTypes = []
|
||||
return {
|
||||
address: {},
|
||||
protocols: {
|
||||
component: ProtocolSelector,
|
||||
on: {},
|
||||
el: {
|
||||
settingReadonly: true,
|
||||
choices: []
|
||||
choices: platformProtocols
|
||||
},
|
||||
on: {
|
||||
input: ([value]) => {
|
||||
const protocolSecretTypes = platformProtocols.reduce((pre, cur) => {
|
||||
pre[cur.name] = cur['secret_types']
|
||||
return pre
|
||||
}, {})
|
||||
const _secretTypes = value.map(v => v.name).reduce((pre, name) => {
|
||||
if (protocolSecretTypes[name]) {
|
||||
return pre.concat(protocolSecretTypes[name])
|
||||
}
|
||||
return pre
|
||||
}, [])
|
||||
secretTypes.splice(0, secretTypes.length, ..._secretTypes)
|
||||
}
|
||||
}
|
||||
},
|
||||
platform: {
|
||||
@@ -42,7 +58,7 @@ export const assetFieldsMeta = () => {
|
||||
component: AssetAccounts,
|
||||
label: '',
|
||||
el: {
|
||||
protocols: [],
|
||||
platform: {},
|
||||
default: []
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user