fix: 主机硬件信息 多次请求及warning

This commit is contained in:
feng
2023-03-13 23:16:26 +08:00
parent 3809519331
commit 983663a3fa
3 changed files with 29 additions and 21 deletions

View File

@@ -3,13 +3,13 @@
<template>
<el-popover
placement="top-start"
open-delay="500"
:open-delay="parseInt('500')"
:title="title"
width="400"
trigger="hover"
>
<el-row v-for="(item, key) of items" :key="key" class="detail-item">
<el-col :span="12">{{ info[key] }}</el-col>
<el-col :span="12">{{ formatterArgs.info[key] }}</el-col>
<el-col :span="12">{{ item }}</el-col>
</el-row>
<span slot="reference">{{ viewText }}</span>
@@ -66,23 +66,6 @@ export default {
}
return '-'
}
},
async mounted() {
this.info = await this.optionAndGenFields()
},
methods: {
async optionAndGenFields() {
const data = await this.$store.dispatch('common/getUrlMeta', { url: this.url })
const remoteMeta = data.actions['GET'] || {}
const fieldName = this.formatterArgs?.fieldName || ''
const remoteMetaFields = remoteMeta[fieldName]?.children || {}
const fields = Object.keys(remoteMetaFields)
const info = {}
for (const name of fields) {
info[name] = remoteMetaFields[name].label
}
return info
}
}
}
</script>

View File

@@ -29,6 +29,7 @@ export default {
config: {
url: '/api/v1/assets/hosts/',
category: 'host',
optionInfo: {},
headerActions: {
createRoute: 'HostCreate',
extraActions: [
@@ -85,7 +86,22 @@ export default {
}
}
}
}
},
async mounted() {
this.config.optionInfo = await this.optionAndGenFields()
},
methods: {
async optionAndGenFields() {
const data = await this.$store.dispatch('common/getUrlMeta', { url: this.config.url })
const remoteMeta = data.actions['GET'] || {}
const remoteMetaFields = remoteMeta['info']?.children || {}
const fields = Object.keys(remoteMetaFields)
const info = {}
for (const name of fields) {
info[name] = remoteMetaFields[name].label
}
return info
}
}
}

View File

@@ -60,6 +60,10 @@ export default {
helpMessage: {
type: String,
default: ''
},
optionInfo: {
type: Object,
default: () => ({})
}
},
data() {
@@ -129,7 +133,7 @@ export default {
label: this.$t('assets.HardwareInfo'),
formatter: HostInfoFormatter,
formatterArgs: {
fieldName: 'info',
info: vm?.optionInfo,
can: vm.$hasPerm('assets.refresh_assethardwareinfo'),
getRoute({ row }) {
return {
@@ -269,6 +273,11 @@ export default {
}
return actions
}
},
watch: {
optionInfo(iNew) {
this.$set(this.defaultConfig.columnsMeta.info.formatterArgs, 'info', iNew)
}
}
}
</script>