perf: 优化平台

This commit is contained in:
ibuler
2022-09-21 18:48:52 +08:00
parent 0e3af4df5d
commit c491fb6c40
6 changed files with 84 additions and 111 deletions

View File

@@ -48,7 +48,10 @@ export default {
return { return {
defaultSetting: { defaultSetting: {
sftp_enabled: true, sftp_enabled: true,
sftp_home: '/tmp' sftp_home: '/tmp',
username_selector: '#username',
password_selector: '#password',
submit_selector: '.btn-submit'
}, },
loading: true, loading: true,
form: {}, form: {},
@@ -88,6 +91,24 @@ export default {
type: 'input', type: 'input',
helpText: this.$t('assets.SFTPHelpMessage'), helpText: this.$t('assets.SFTPHelpMessage'),
hidden: (form) => this.item.name !== 'ssh' || !form['sftp_enabled'] hidden: (form) => this.item.name !== 'ssh' || !form['sftp_enabled']
},
{
id: 'username_selector',
label: '用户名输入框选择器',
type: 'input',
hidden: (form) => this.item.name !== 'http'
},
{
id: 'password_selector',
label: '密码输入框选择器',
type: 'input',
hidden: (form) => this.item.name !== 'http'
},
{
id: 'submit_selector',
label: '提交按钮选择器',
type: 'input',
hidden: (form) => this.item.name !== 'http'
} }
] ]
} }

View File

@@ -82,15 +82,15 @@ export default {
defaultConfig: { defaultConfig: {
url: '/api/v1/assets/hosts/', url: '/api/v1/assets/hosts/',
columns: [ columns: [
'name', 'ip', 'category', 'type', 'platform', 'name', 'address', 'category', 'type', 'platform',
'protocols', 'is_active', 'connectivity', 'protocols', 'is_active', 'connectivity',
'created_by', 'date_created', 'comment', 'created_by', 'date_created', 'comment',
'org_name', 'actions' 'org_name', 'actions'
], ],
columnsShow: { columnsShow: {
min: ['name', 'ip', 'actions'], min: ['name', 'address', 'actions'],
default: [ default: [
'name', 'ip', 'platform', 'category', 'type', 'name', 'address', 'platform', 'category', 'type',
'connectivity', 'actions' 'connectivity', 'actions'
] ]
}, },

View File

@@ -5,33 +5,16 @@
:visible.sync="iVisible" :visible.sync="iVisible"
width="60%" width="60%"
top="1vh" top="1vh"
@confirm="onConfirm" :show-cancel="false"
@cancel="onConfirm" :show-confirm="false"
> >
<div style="margin: 0 10px"> <div style="margin: 0 10px">
<el-row v-if="showRecentPlatforms.length > 0" :gutter="20">
<p class="recent">{{ this.$t('assets.RecentlyUsed') }}</p>
<el-col
v-for="(item, index) of showRecentPlatforms"
:key="item.id"
:span="6"
>
<el-card
:style="{ borderLeftColor: randomBorderColor(index) }"
class="platform-item"
shadow="hover"
@click.native="createAsset(item)"
>
{{ item.name }}
</el-card>
</el-col>
</el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-collapse v-model="activePlatform" accordion> <el-collapse v-model="activeType" accordion>
<el-collapse-item <el-collapse-item
v-for="(ps, categoryName) in sortedPlatforms" v-for="(ps, categoryName) in sortedPlatforms"
:key="categoryName" :key="categoryName"
:title="categoryMapper[categoryName]" :title="categoryName"
:name="categoryName" :name="categoryName"
> >
<el-col <el-col
@@ -69,17 +52,14 @@ export default {
}, },
category: { category: {
type: String, type: String,
Validator: (value) => {
return ['all', 'host', 'networking', 'database', 'cloud', 'web'].includes(value)
},
default: 'all' default: 'all'
} }
}, },
data() { data() {
return { return {
platforms: [], platforms: [],
recentPlatforms: {}, recentPlatformIds: [],
activePlatform: 'host', activeType: 'host',
typeIconMapper: { typeIconMapper: {
linux: 'fa-linux', linux: 'fa-linux',
windows: 'fa-windows', windows: 'fa-windows',
@@ -97,65 +77,52 @@ export default {
set(val) { set(val) {
this.$emit('update:visible', val) this.$emit('update:visible', val)
}, },
get() { get() { return this.visible }
return this.visible
}
}, },
sortedPlatforms() { sortedPlatforms() {
const { category, platforms } = this const recentPlatforms = {}
const filterPlatforms = _.groupBy(platforms, (item) => item.category.value) if (this.category === 'all') {
return category === 'all' ? filterPlatforms : this.arrangePlatforms(filterPlatforms[category]) recentPlatforms[this.$t('assets.RecentlyUsed')] = this.allRecentPlatforms
}, return { ...recentPlatforms, ...this.allSortedPlatforms }
categoryMapper() { } else {
const mapper = {} recentPlatforms[this.$t('assets.RecentlyUsed')] = this.recentPlatforms
for (const p of this.platforms) { return { ...recentPlatforms, ...this.typeSortedPlatforms }
if (this.category === 'all') {
mapper[p.category.value] = p.category.label
} else {
mapper[p.type.value] = p.type.label
}
} }
return mapper
}, },
showRecentPlatforms() { allSortedPlatforms() {
return this.category === 'all' ? this.recentPlatforms : this.typeRecentPlatforms() return _.groupBy(this.platforms, (item) => item.category.label)
},
typeSortedPlatforms() {
const typedPlatforms = this.platforms.filter(item => item.category.value === this.category)
return _.groupBy(typedPlatforms, (item) => item.type.label)
},
recentPlatforms() {
return this.category === 'all' ? this.allRecentPlatforms : this.typeRecentPlatforms
},
allRecentPlatforms() {
return this.recentPlatformIds
.map(i => this.platforms.find(p => p.id === i))
.filter(p => p)
},
typeRecentPlatforms() {
return this.allRecentPlatforms.filter(item => item.category.value === this.category)
} }
}, },
created() { created() {
this.$axios.get('/api/v1/assets/platforms/').then(data => { this.$axios.get('/api/v1/assets/platforms/').then(data => {
this.platforms = data this.platforms = data
this.loadRecentPlatformIds()
this.activeType = Object.keys(this.sortedPlatforms)[0]
}) })
this.getRecentPlatforms()
}, },
methods: { methods: {
getRecentPlatforms() { loadRecentPlatformIds() {
this.recentPlatforms = JSON.parse(localStorage.getItem('RecentPlatforms')) || [] const recentPlatformIds = JSON.parse(localStorage.getItem('RecentPlatforms')) || []
}, this.recentPlatformIds = recentPlatformIds
setRecentPlatforms(platform) { .map(i => this.platforms.find(p => p.id === i))
const recentPlatforms = this.recentPlatforms || [] .filter(p => p)
const item = { .map(p => p.id)
id: platform.id, console.log('This. platform id: ', this.recentPlatformIds)
name: platform.name,
category: platform.category
}
if (!_.some(recentPlatforms, item)) {
if (recentPlatforms.length >= 8) {
recentPlatforms.pop()
}
recentPlatforms.unshift(item)
localStorage.setItem('RecentPlatforms', JSON.stringify(recentPlatforms))
}
},
typeRecentPlatforms() {
const typePlatforms = []
const { category, recentPlatforms } = this
for (const item of recentPlatforms) {
if (item.category.value === category) {
typePlatforms.push(item)
}
}
return typePlatforms
}, },
onConfirm() { onConfirm() {
this.iVisible = false this.iVisible = false
@@ -166,34 +133,20 @@ export default {
const color = this.bottomColors[colorIndex] const color = this.bottomColors[colorIndex]
return color return color
}, },
createAsset(platform) { addToRecentPlatforms(platform) {
// debugger const recentPlatformIds = this.recentPlatformIds.filter(i => i !== platform.id)
const mapper = { recentPlatformIds.unshift(platform.id)
host: 'HostCreate', if (recentPlatformIds.length > 8) {
database: 'DatabaseCreate', recentPlatformIds.pop()
cloud: 'CloudCreate',
web: 'WebCreate',
remote_app: 'RemoteAppCreate'
} }
const route = mapper[platform.category.value] || 'HostCreate' this.recentPlatformIds = recentPlatformIds
this.$router.push({ name: route, query: { platform: platform.id }}) localStorage.setItem('RecentPlatforms', JSON.stringify(recentPlatformIds))
this.iVisible = false
this.setRecentPlatforms(platform)
}, },
arrangePlatforms(data = []) { createAsset(platform) {
const filterField = {} const route = _.capitalize(platform.category.value) + 'Create' || 'HostCreate'
data.length > 0 && data.forEach(el => { this.addToRecentPlatforms(platform)
if (el.internal) { this.iVisible = false
filterField[el.type.value] = [el] this.$router.push({ name: route, query: { platform: platform.id }})
} else {
filterField[el.type.value]?.push(el)
}
})
const filterFieldKey = Object.keys(filterField)
this.activePlatform = filterFieldKey.length > 0 ? filterFieldKey[0] : ''
return filterField
} }
} }
} }

View File

@@ -27,31 +27,26 @@ export default {
{ {
title: this.$t('applications.host'), title: this.$t('applications.host'),
name: 'hosts', name: 'hosts',
hidden: () => false,
component: () => import('@/views/assets/Asset/AssetList/HostList.vue') component: () => import('@/views/assets/Asset/AssetList/HostList.vue')
}, },
{ {
title: this.$t('route.Device'), title: this.$t('route.Device'),
name: 'devices', name: 'devices',
hidden: () => false,
component: () => import('@/views/assets/Asset/AssetList/DeviceList.vue') component: () => import('@/views/assets/Asset/AssetList/DeviceList.vue')
}, },
{ {
title: this.$t('route.Database'), title: this.$t('route.Database'),
name: 'databases', name: 'databases',
hidden: () => false,
component: () => import('@/views/assets/Asset/AssetList/DatabaseList.vue') component: () => import('@/views/assets/Asset/AssetList/DatabaseList.vue')
}, },
{ {
title: this.$t('assets.Cloud'), title: this.$t('assets.Cloud'),
name: 'clouds', name: 'clouds',
hidden: () => false,
component: () => import('@/views/assets/Asset/AssetList/CloudList.vue') component: () => import('@/views/assets/Asset/AssetList/CloudList.vue')
}, },
{ {
title: 'Web', title: 'Web',
name: 'web', name: 'web',
hidden: () => false,
component: () => import('@/views/assets/Asset/AssetList/WebList.vue') component: () => import('@/views/assets/Asset/AssetList/WebList.vue')
} }
] ]

View File

@@ -83,7 +83,7 @@ export default {
} }
} }
}, },
brand: {}, charset: {},
protocols_enabled: { protocols_enabled: {
el: { el: {
disabled: false disabled: false
@@ -158,6 +158,11 @@ export default {
_.set(this.fieldsMeta, `${field}.el.disabled`, disabled) _.set(this.fieldsMeta, `${field}.el.disabled`, disabled)
} }
this.fieldsMeta.protocols.el.choices = constraints['protocols'] || [] this.fieldsMeta.protocols.el.choices = constraints['protocols'] || []
if (constraints['charset_enabled'] === false) {
this.fieldsMeta.charset.hidden = () => true
}
await this.setAutomations(constraints['automation']) await this.setAutomations(constraints['automation'])
}, },
async setAutomations(automation) { async setAutomations(automation) {
@@ -186,7 +191,6 @@ export default {
return { value: method['id'], label: method['name'] } return { value: method['id'], label: method['name'] }
}) })
} }
console.log('Initial: ', initial)
} }
} }
} }

View File

@@ -6,7 +6,7 @@ import { Select2 } from '@/components/FormFields'
export const assetFieldsMeta = () => { export const assetFieldsMeta = () => {
return { return {
ip: {}, address: {},
protocols: { protocols: {
component: ProtocolSelector, component: ProtocolSelector,
on: {}, on: {},