mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-04 00:16:32 +00:00
perf: update platform detail
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import GenericCreateUpdatePage from '@/layout/components/GenericCreateUpdatePage'
|
import GenericCreateUpdatePage from '@/layout/components/GenericCreateUpdatePage'
|
||||||
import { fieldsMeta } from './const'
|
import { platformFieldsMeta, setAutomations } from './const'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PlatformCreateUpdate',
|
name: 'PlatformCreateUpdate',
|
||||||
@@ -48,7 +48,7 @@ export default {
|
|||||||
['自动化', ['automation']],
|
['自动化', ['automation']],
|
||||||
[this.$t('common.Other'), ['comment']]
|
[this.$t('common.Other'), ['comment']]
|
||||||
],
|
],
|
||||||
fieldsMeta,
|
fieldsMeta: platformFieldsMeta(this),
|
||||||
url: `/api/v1/assets/platforms/`,
|
url: `/api/v1/assets/platforms/`,
|
||||||
cleanFormValue: (values) => {
|
cleanFormValue: (values) => {
|
||||||
const category_type = values['category_type']
|
const category_type = values['category_type']
|
||||||
@@ -61,7 +61,8 @@ export default {
|
|||||||
obj['category_type'] = [obj['category'].value, obj['type'].value]
|
obj['category_type'] = [obj['category'].value, obj['type'].value]
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
},
|
||||||
|
object: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
@@ -89,6 +90,7 @@ export default {
|
|||||||
const type = this.$route.query.type
|
const type = this.$route.query.type
|
||||||
const url = `/api/v1/assets/categories/constraints/?category=${category}&type=${type}`
|
const url = `/api/v1/assets/categories/constraints/?category=${category}&type=${type}`
|
||||||
const constraints = await this.$axios.get(url)
|
const constraints = await this.$axios.get(url)
|
||||||
|
this.object = constraints
|
||||||
|
|
||||||
const fieldsCheck = ['protocols_enabled', 'domain_enabled', 'su_enabled']
|
const fieldsCheck = ['protocols_enabled', 'domain_enabled', 'su_enabled']
|
||||||
for (const field of fieldsCheck) {
|
for (const field of fieldsCheck) {
|
||||||
@@ -105,45 +107,7 @@ export default {
|
|||||||
this.fieldsMeta.charset.hidden = () => true
|
this.fieldsMeta.charset.hidden = () => true
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.setAutomations(constraints['automation'])
|
await setAutomations(this)
|
||||||
},
|
|
||||||
async setAutomations(automation) {
|
|
||||||
const autoFieldsMeta = this.fieldsMeta.automation.fieldsMeta
|
|
||||||
const autoFields = this.fieldsMeta.automation.fields
|
|
||||||
.filter(item => item.endsWith('_method'))
|
|
||||||
.map(item => item.replace('_method', ''))
|
|
||||||
|
|
||||||
const initial = this.initial.automation || {}
|
|
||||||
initial['ansible_enabled'] = automation['ansible_enabled']
|
|
||||||
initial['ansible_config'] = JSON.stringify(automation['ansible_config'])
|
|
||||||
|
|
||||||
for (const item of autoFields) {
|
|
||||||
const itemEnabledKey = item + '_enabled'
|
|
||||||
const itemMethodKey = item + '_method'
|
|
||||||
const itemEnabled = automation[itemEnabledKey]
|
|
||||||
// 设置 enableKey disabled 和 默认值
|
|
||||||
if (itemEnabled === false) {
|
|
||||||
initial[itemEnabledKey] = false
|
|
||||||
_.set(autoFieldsMeta, `${itemEnabledKey}.el.disabled`, true)
|
|
||||||
} else {
|
|
||||||
initial[itemEnabledKey] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置 enableKey Hidden
|
|
||||||
_.set(autoFieldsMeta, `${itemEnabledKey}.hidden`, (formValue) => {
|
|
||||||
return !formValue['ansible_enabled']
|
|
||||||
})
|
|
||||||
// 设置 enableMethod Hidden
|
|
||||||
_.set(autoFieldsMeta, `${itemMethodKey}.hidden`, (formValue) => {
|
|
||||||
return !formValue[itemEnabledKey] || !formValue['ansible_enabled']
|
|
||||||
})
|
|
||||||
// 设置 method 类型和 options
|
|
||||||
_.set(autoFieldsMeta, `${itemMethodKey}.type`, 'select')
|
|
||||||
const methods = automation[itemMethodKey + 's'] || []
|
|
||||||
autoFieldsMeta[itemMethodKey].options = methods.map(method => {
|
|
||||||
return { value: method['id'], label: method['name'] }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,12 @@
|
|||||||
<el-col :md="10" :sm="24">
|
<el-col :md="10" :sm="24">
|
||||||
<QuickActions type="primary" :actions="quickActions" />
|
<QuickActions type="primary" :actions="quickActions" />
|
||||||
</el-col>
|
</el-col>
|
||||||
<PlatformDetailUpdateDialog v-if="visible" :visible.sync="visible" :fields="fields" />
|
<PlatformDetailUpdateDialog
|
||||||
|
v-if="visible"
|
||||||
|
:visible.sync="visible"
|
||||||
|
:show-fields="fields"
|
||||||
|
:object="object"
|
||||||
|
/>
|
||||||
</el-row>
|
</el-row>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dialog
|
<Dialog
|
||||||
v-if="iVisible"
|
|
||||||
:title="$tc('common.Update')"
|
:title="$tc('common.Update')"
|
||||||
:visible.sync="iVisible"
|
:visible.sync="iVisible"
|
||||||
width="60%"
|
width="60%"
|
||||||
@@ -8,14 +7,14 @@
|
|||||||
:show-cancel="false"
|
:show-cancel="false"
|
||||||
:show-confirm="false"
|
:show-confirm="false"
|
||||||
>
|
>
|
||||||
<GenericCreateUpdateForm v-bind="config" @submitSuccess="submitSuccess" />
|
<GenericCreateUpdateForm v-bind="$data" @submitSuccess="submitSuccess" />
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Dialog from '@/components/Dialog'
|
import Dialog from '@/components/Dialog'
|
||||||
import { GenericCreateUpdateForm } from '@/layout/components'
|
import { GenericCreateUpdateForm } from '@/layout/components'
|
||||||
import { fieldsMeta } from '../const'
|
import { platformFieldsMeta, setAutomations } from '../const'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -27,24 +26,25 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
fields: {
|
showFields: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => []
|
default: () => []
|
||||||
|
},
|
||||||
|
object: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
config: {
|
initial: {},
|
||||||
successUrl: { name: 'Settings', params: { activeMenu: 'Basic' }},
|
successUrl: { name: 'Settings', params: { activeMenu: 'Basic' }},
|
||||||
url: `/api/v1/assets/platforms/`,
|
url: `/api/v1/assets/platforms/`,
|
||||||
hasReset: false,
|
hasReset: false,
|
||||||
hasDetailInMsg: false,
|
hasDetailInMsg: false,
|
||||||
submitMethod: () => 'patch',
|
submitMethod: () => 'patch',
|
||||||
fields: [
|
fields: [['', this.showFields]],
|
||||||
['', this.fields]
|
fieldsMeta: platformFieldsMeta(this)
|
||||||
],
|
|
||||||
fieldsMeta
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -56,6 +56,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
setAutomations(this)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submitSuccess() {
|
submitSuccess() {
|
||||||
@@ -69,5 +70,4 @@ export default {
|
|||||||
::v-deep .el-dialog .el-dialog__body {
|
::v-deep .el-dialog .el-dialog__body {
|
||||||
padding: 0 20px;
|
padding: 0 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<GenericDetailPage :actions="actions" :object.sync="TaskDetail" :active-menu.sync="config.activeMenu" v-bind="config" v-on="$listeners">
|
<GenericDetailPage :object.sync="TaskDetail" :active-menu.sync="config.activeMenu" v-bind="config" v-on="$listeners">
|
||||||
<keep-alive>
|
<keep-alive>
|
||||||
<component :is="config.activeMenu" :object="TaskDetail" />
|
<component :is="config.activeMenu" :object="TaskDetail" />
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
@@ -18,8 +18,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
TaskDetail: {},
|
TaskDetail: {},
|
||||||
actions: {
|
actions: {},
|
||||||
},
|
|
||||||
config: {
|
config: {
|
||||||
title: this.$t('assets.PlatformDetail'),
|
title: this.$t('assets.PlatformDetail'),
|
||||||
activeMenu: 'Detail',
|
activeMenu: 'Detail',
|
||||||
@@ -29,6 +28,21 @@ export default {
|
|||||||
name: 'Detail'
|
name: 'Detail'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
actions: {
|
||||||
|
updateCallback: () => {
|
||||||
|
const { type, category } = this.TaskDetail
|
||||||
|
this.$router.push({
|
||||||
|
name: 'PlatformCreate',
|
||||||
|
params: {
|
||||||
|
id: this.$route.params.id
|
||||||
|
},
|
||||||
|
query: {
|
||||||
|
type: type.value,
|
||||||
|
category: category.value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
hasRightSide: this.$route.params.id > 7
|
hasRightSide: this.$route.params.id > 7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,8 @@ import { JsonEditor } from '@/components/FormFields'
|
|||||||
import { assetFieldsMeta } from '@/views/assets/const'
|
import { assetFieldsMeta } from '@/views/assets/const'
|
||||||
const assetMeta = assetFieldsMeta()
|
const assetMeta = assetFieldsMeta()
|
||||||
|
|
||||||
export const fieldsMeta = {
|
export const platformFieldsMeta = (vm) => {
|
||||||
|
return {
|
||||||
automation: {
|
automation: {
|
||||||
initial: {
|
initial: {
|
||||||
ansible_config: ''
|
ansible_config: ''
|
||||||
@@ -20,9 +21,6 @@ export const fieldsMeta = {
|
|||||||
fieldsMeta: {
|
fieldsMeta: {
|
||||||
ansible_config: {
|
ansible_config: {
|
||||||
component: JsonEditor,
|
component: JsonEditor,
|
||||||
el: {
|
|
||||||
value: '{}'
|
|
||||||
},
|
|
||||||
hidden: (formValue) => !formValue['ansible_enabled']
|
hidden: (formValue) => !formValue['ansible_enabled']
|
||||||
},
|
},
|
||||||
ping_method: {},
|
ping_method: {},
|
||||||
@@ -44,8 +42,8 @@ export const fieldsMeta = {
|
|||||||
disabled: true
|
disabled: true
|
||||||
},
|
},
|
||||||
hidden: (formValue) => {
|
hidden: (formValue) => {
|
||||||
if (formValue.category_type[0] === undefined) {
|
if (formValue?.category_type?.[0] === undefined) {
|
||||||
formValue.category_type = this.initial.category_type
|
formValue.category_type = vm.initial.category_type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -72,4 +70,45 @@ export const fieldsMeta = {
|
|||||||
type: 'select',
|
type: 'select',
|
||||||
hidden: (form) => !form['su_enabled']
|
hidden: (form) => !form['su_enabled']
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setAutomations = (vm) => {
|
||||||
|
const automation = vm.object.automation || {}
|
||||||
|
const autoFieldsMeta = vm.fieldsMeta.automation.fieldsMeta
|
||||||
|
const autoFields = vm.fieldsMeta.automation.fields
|
||||||
|
.filter(item => item.endsWith('_method'))
|
||||||
|
.map(item => item.replace('_method', ''))
|
||||||
|
|
||||||
|
const initial = vm.initial.automation || {}
|
||||||
|
initial['ansible_enabled'] = automation['ansible_enabled']
|
||||||
|
initial['ansible_config'] = JSON.stringify(automation['ansible_config'])
|
||||||
|
|
||||||
|
for (const item of autoFields) {
|
||||||
|
const itemEnabledKey = item + '_enabled'
|
||||||
|
const itemMethodKey = item + '_method'
|
||||||
|
const itemEnabled = automation[itemEnabledKey]
|
||||||
|
// 设置 enableKey disabled 和 默认值
|
||||||
|
if (itemEnabled === false) {
|
||||||
|
initial[itemEnabledKey] = false
|
||||||
|
_.set(autoFieldsMeta, `${itemEnabledKey}.el.disabled`, true)
|
||||||
|
} else {
|
||||||
|
initial[itemEnabledKey] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置 enableKey Hidden
|
||||||
|
_.set(autoFieldsMeta, `${itemEnabledKey}.hidden`, (formValue) => {
|
||||||
|
return !formValue['ansible_enabled']
|
||||||
|
})
|
||||||
|
// 设置 enableMethod Hidden
|
||||||
|
_.set(autoFieldsMeta, `${itemMethodKey}.hidden`, (formValue) => {
|
||||||
|
return !formValue[itemEnabledKey] || !formValue['ansible_enabled']
|
||||||
|
})
|
||||||
|
// 设置 method 类型和 options
|
||||||
|
_.set(autoFieldsMeta, `${itemMethodKey}.type`, 'select')
|
||||||
|
const methods = automation[itemMethodKey + 's'] || []
|
||||||
|
autoFieldsMeta[itemMethodKey].options = methods.map(method => {
|
||||||
|
return { value: method['id'], label: method['name'] }
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user