Merge pull request #2771 from jumpserver/pr@dev@perf_ticket2

perf: 优化账号历史数量
This commit is contained in:
老广 2023-02-23 14:12:53 +08:00 committed by GitHub
commit 71c86a637c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 132 additions and 40 deletions

View File

@ -108,7 +108,7 @@ export default {
}, },
columnsExclude: ['spec_info'], columnsExclude: ['spec_info'],
columns: [ columns: [
'name', 'username', 'asset', 'privileged', 'version', 'name', 'username', 'asset', 'privileged',
'secret_type', 'source', 'actions' 'secret_type', 'source', 'actions'
], ],
columnsMeta: { columnsMeta: {

View File

@ -40,13 +40,16 @@
<span>{{ account['date_updated'] | date }}</span> <span>{{ account['date_updated'] | date }}</span>
</el-form-item> </el-form-item>
<el-form-item v-if="showPasswordRecord" :label="$tc('accounts.PasswordRecord')"> <el-form-item v-if="showPasswordRecord" :label="$tc('accounts.PasswordRecord')">
<el-button <el-link
v-perms="'accounts.view_historyaccountsecret'" v-perms="'accounts.view_historyaccountsecret'"
type="text" :underline="false"
@click="onShowPasswordHistory" type="success"
@click="showHistoryDialog"
> >
{{ account['version'] }} <span style="padding-right: 30px">
</el-button> {{ versions }}
</span>
</el-link>
</el-form-item> </el-form-item>
</el-form> </el-form>
</Dialog> </Dialog>
@ -99,6 +102,7 @@ export default {
data() { data() {
return { return {
secretInfo: {}, secretInfo: {},
versions: '-',
showSecret: false, showSecret: false,
sshKeyFingerprint: '', sshKeyFingerprint: '',
historyCount: 0, historyCount: 0,
@ -113,6 +117,12 @@ export default {
return this.account['secret_type'].value return this.account['secret_type'].value
} }
}, },
mounted() {
const url = `/api/v1/accounts/account-secrets/${this.account.id}/histories/?limit=1`
this.$axios.get(url).then(resp => {
this.versions = resp.count
})
},
methods: { methods: {
getAuthInfo() { getAuthInfo() {
this.$axios.get(this.url, { disableFlashErrorMsg: true }).then(resp => { this.$axios.get(this.url, { disableFlashErrorMsg: true }).then(resp => {
@ -124,7 +134,7 @@ export default {
exit() { exit() {
this.$emit('update:visible', false) this.$emit('update:visible', false)
}, },
onShowPasswordHistory() { showHistoryDialog() {
this.showPasswordHistoryDialog = true this.showPasswordHistoryDialog = true
} }
} }

View File

@ -0,0 +1,74 @@
<template>
<el-tag
:size="tag.size"
:type="tag.type"
class="tag-formatter"
disable-transitions
>
<i v-if="tag.icon" :class="tag.icon" class="fa" /> {{ tag.label }}
</el-tag>
</template>
<script>
import BaseFormatter from './base'
export default {
name: 'TagChoicesFormatter',
extends: BaseFormatter,
props: {
formatterArgsDefault: {
type: Object,
default() {
return {
getTag({ row, cellValue }) {
return null
},
getTagSize({ row, cellValue }) {
return 'mini'
},
getTagLabel({ row, cellValue }) {
return cellValue
},
getTagType({ row, cellValue }) {
return 'primary'
},
getTagIcon({ row, cellValue }) {
return ''
}
}
}
}
},
data() {
return {
formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs)
}
},
computed: {
tag() {
return this.iGetTag()
}
},
methods: {
iGetTag() {
let tag = this.formatterArgs.getTag({ row: this.row, cellValue: this.cellValue })
if (tag) return tag
console.log('Tag: ', tag)
tag = {
size: this.formatterArgs.getTagSize({ row: this.row, cellValue: this.cellValue }),
type: this.formatterArgs.getTagType({ row: this.row, cellValue: this.cellValue }),
label: this.formatterArgs.getTagLabel({ row: this.row, cellValue: this.cellValue }),
icon: this.formatterArgs.getTagIcon({ row: this.row, cellValue: this.cellValue })
}
return tag
}
}
}
</script>
<style scoped>
.tag-formatter {
margin: 2px 0;
}
</style>

View File

@ -14,6 +14,7 @@ import TagsFormatter from './TagsFormatter'
import ObjectRelatedFormatter from './ObjectRelatedFormatter' import ObjectRelatedFormatter from './ObjectRelatedFormatter'
import TwoTabFormatter from './TwoTabFormatter' import TwoTabFormatter from './TwoTabFormatter'
import ProtocolsFormatter from './ProtocolsFormatter.vue' import ProtocolsFormatter from './ProtocolsFormatter.vue'
import TagChoicesFormatter from './TagChoicesFormatter.vue'
export default { export default {
DetailFormatter, DetailFormatter,
@ -31,7 +32,8 @@ export default {
TagsFormatter, TagsFormatter,
ObjectRelatedFormatter, ObjectRelatedFormatter,
TwoTabFormatter, TwoTabFormatter,
ProtocolsFormatter ProtocolsFormatter,
TagChoicesFormatter
} }
export { export {
@ -50,5 +52,6 @@ export {
TagsFormatter, TagsFormatter,
ObjectRelatedFormatter, ObjectRelatedFormatter,
TwoTabFormatter, TwoTabFormatter,
ProtocolsFormatter ProtocolsFormatter,
TagChoicesFormatter
} }

View File

@ -48,7 +48,7 @@ export default {
return { return {
templateDialogVisible: false, templateDialogVisible: false,
columns: [ columns: [
'name', 'username', 'privileged', 'version', 'connectivity', 'name', 'username', 'privileged', 'connectivity',
'is_active', 'secret_type', 'source', 'date_created', 'is_active', 'secret_type', 'source', 'date_created',
'date_updated', 'actions' 'date_updated', 'actions'
], ],

View File

@ -1,14 +1,14 @@
<template> <template>
<GenericListPage <GenericListPage
v-loading="loading" v-loading="loading"
:table-config="ticketTableConfig"
:header-actions="ticketActions" :header-actions="ticketActions"
:table-config="ticketTableConfig"
/> />
</template> </template>
<script type="text/jsx"> <script type="text/jsx">
import { GenericListPage } from '@/layout/components' import { GenericListPage } from '@/layout/components'
import { DetailFormatter } from '@/components/TableFormatters' import { DetailFormatter, TagChoicesFormatter } from '@/components/TableFormatters'
import { toSafeLocalDateStr } from '@/utils/common' import { toSafeLocalDateStr } from '@/utils/common'
import { APPROVE, REJECT } from './const' import { APPROVE, REJECT } from './const'
@ -25,13 +25,19 @@ export default {
hasMoreActions: { hasMoreActions: {
type: Boolean, type: Boolean,
default: false default: false
},
extraQuery: {
type: Object,
default: () => ({})
} }
}, },
data() { data() {
const vm = this
return { return {
loading: true, loading: true,
ticketTableConfig: { ticketTableConfig: {
url: this.url, url: this.url,
extraQuery: this.extraQuery,
columnsExclude: ['process_map', 'rel_snapshot'], columnsExclude: ['process_map', 'rel_snapshot'],
columnsShow: { columnsShow: {
min: ['title', 'serial_num', 'type', 'state', 'date_created'], min: ['title', 'serial_num', 'type', 'state', 'date_created'],
@ -67,7 +73,7 @@ export default {
label: this.$t('tickets.user'), label: this.$t('tickets.user'),
sortable: 'custom', sortable: 'custom',
formatter: row => { formatter: row => {
return row.rel_snapshot.applicant return row['rel_snapshot'].applicant
} }
}, },
type: { type: {
@ -81,11 +87,21 @@ export default {
align: 'center', align: 'center',
width: '90px', width: '90px',
sortable: 'custom', sortable: 'custom',
formatter: row => { formatter: TagChoicesFormatter,
formatterArgs: {
getTagLabel({ row }) {
if (row.status.value === 'open') { if (row.status.value === 'open') {
return <el-tag type='primary' size='mini'> {this.$t('tickets.OpenStatus')}</el-tag> return vm.$t('tickets.OpenStatus')
} else { } else {
return <el-tag type='danger' size='mini'> {this.$t('tickets.CloseStatus')}</el-tag> return vm.$t('tickets.CloseStatus')
}
},
getTagType({ row }) {
if (row.status.value === 'open') {
return 'primary'
} else {
return 'danger'
}
} }
} }
}, },
@ -94,28 +110,17 @@ export default {
align: 'center', align: 'center',
width: '90px', width: '90px',
sortable: 'custom', sortable: 'custom',
formatter: row => { formatter: TagChoicesFormatter,
if (row.status.value === 'open') { formatterArgs: {
return <el-tag getTagType({ row }) {
type='success' const mapper = {
size='mini' [APPROVE]: 'success',
> [REJECT]: 'danger'
{this.$t('tickets.Pending')}
</el-tag>
} }
switch (row.state.value) { return mapper[row.state.value] || 'warning'
case 'approved': },
return <el-tag type='primary' size='mini'> getTagLabel({ row }) {
{this.$t('tickets.Approved')} return row.state.label || vm.$t('common.Pending')
</el-tag>
case 'rejected':
return <el-tag type='danger' size='mini'>
{this.$t('tickets.Rejected')}
</el-tag>
default :
return <el-tag type='info' size='mini'>
{this.$t('tickets.Closed')}
</el-tag>
} }
} }
}, },