Skip to content

Commit

Permalink
Perf: Change Connect To Formatter Component
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoJiSen committed Jan 6, 2025
1 parent 28e7321 commit c7fd044
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 126 deletions.
136 changes: 136 additions & 0 deletions src/components/Table/TableFormatters/AccountConnectFormatter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<template>
<el-dropdown
size="small"
trigger="hover"
:show-timeout="500"
@command="handleCommand"
@visible-change="visibleChange"
>
<el-button
plain
size="mini"
type="primary"
@click="handlePamConnect"
>
<i class="fa fa-desktop" />
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="Title" disabled>
可选协议
</el-dropdown-item>
<el-dropdown-item divided />
<el-dropdown-item
v-for="protocol in perm_protocols"
:key="protocol.id"
:command="protocol.name"
>
{{ protocol.name }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>

<script>
import { mapGetters } from 'vuex'
import BaseFormatter from './base.vue'
export default {
name: 'AccountConnectFormatter',
extends: BaseFormatter,
data() {
return {
perm_protocols: []
}
},
computed: {
...mapGetters(['protocolMap'])
},
methods: {
handleCommand(protocol) {
this.$store.commit('table/SET_PROTOCOL_MAP_ITEM', {
key: this.row.id,
value: protocol
})
this.handleWindowOpen(this.row, protocol)
},
visibleChange(visible) {
if (visible) {
this.getPermdProtocols(this.row.asset.id)
}
},
getAssetDetail(id) {
const detailUrl = `/api/v1/assets/assets/${id}`
return new Promise((resolve, reject) => {
this.$axios
.get(detailUrl)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
})
},
handleWindowOpen(row, protocol) {
window.open(
`/luna/pam_connect/${row.id}/${row.username}/${row.asset.id}/${row.asset.name}/${protocol}`,
'_blank'
)
},
async handlePamConnect() {
const protocolMap = this.protocolMap
if (protocolMap.has(this.row.id)) {
const protocol = protocolMap.get(this.row.id)
this.handleWindowOpen(this.row, protocol)
} else {
try {
const res = await this.getAssetDetail(this.row.asset.id)
if (res) {
const protocol = res.protocols[0]
this.$store.commit('table/SET_PROTOCOL_MAP_ITEM', {
key: this.row.id,
value: protocol.name
})
this.handleWindowOpen(this.row, protocol.name)
}
} catch (e) {
throw new Error(`Error for reaseon: ${e}`)
}
}
},
async getPermdProtocols(assetId) {
try {
const res = await this.getAssetDetail(assetId)
if (res) {
this.perm_protocols = res.protocols
}
} catch (e) {
throw new Error(`Error for reaseon: ${e}`)
}
}
}
}
</script>

<style scoped lang="scss">
.el-dropdown-menu__item.is-disabled {
font-weight: 500;
color: var(--el-text-color-secondary);
}
::v-deep .el-dropdown-menu__item {
transition: height 0.3s ease-in-out, padding 0.3s ease-in-out;
overflow: hidden;
}
::v-deep .el-dropdown-menu {
transition: min-height 0.3s ease-in-out;
}
</style>
7 changes: 5 additions & 2 deletions src/components/Table/TableFormatters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import SwitchFormatter from './SwitchFormatter.vue'
import AccountInfoFormatter from './AccountInfoFormatter.vue'
import PlatformFormatter from './PlatformFormatter.vue'
import DiscoverConfirmFormatter from './DiscoverConfirmFormatter.vue'
import AccountConnectFormatter from './AccountConnectFormatter.vue'

export default {
DetailFormatter,
Expand All @@ -43,7 +44,8 @@ export default {
SwitchFormatter,
PlatformFormatter,
AccountInfoFormatter,
DiscoverConfirmFormatter
DiscoverConfirmFormatter,
AccountConnectFormatter
}

export {
Expand All @@ -68,5 +70,6 @@ export {
SwitchFormatter,
PlatformFormatter,
DiscoverConfirmFormatter,
AccountInfoFormatter
AccountInfoFormatter,
AccountConnectFormatter
}
127 changes: 3 additions & 124 deletions src/views/pam/Account/AccountList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
</template>

<script>
import { mapGetters } from 'vuex'
import { DetailFormatter } from '@/components/Table/TableFormatters'
import AccountListTable from '@/components/Apps/AccountListTable/AccountList.vue'
import { DetailFormatter, AccountConnectFormatter } from '@/components/Table/TableFormatters'
export default {
name: 'AssetAccountList',
Expand All @@ -14,9 +13,6 @@ export default {
},
data() {
return {
drawerTitle: '',
currentProtocol: '',
perm_protocols: [],
tableConfig: {
url: '/api/v1/accounts/accounts/',
hasLeftActions: true,
Expand All @@ -38,127 +34,15 @@ export default {
connect: {
label: this.$t('Connect'),
width: '80px',
formatter: row => {
return (
<span class='connect'>
<el-dropdown
{...{
props: {
trigger: 'hover',
size: 'small',
showTimeout: 500
},
on: {
'visible-change': visible => {
if (visible) {
this.getPermdProtocols(row.asset.id)
}
},
'command': protocol => {
this.$store.commit('table/SET_PROTOCOL_MAP_ITEM', {
key: row.id,
value: protocol
})
this.handleWindowOpen(row, protocol)
}
}
}}
>
<el-button
plain
size='mini'
type='primary'
onClick={() => this.handlePamConnect(row)}
>
<i class='fa fa-desktop'/>
</el-button>
<el-dropdown-menu slot='dropdown'>
<el-dropdown-item command='Title' disabled>
可选协议
</el-dropdown-item>
<el-dropdown-item divided/>
{this.perm_protocols.map(protocol => {
return (
<el-dropdown-item command={protocol.name}>
{protocol.name}
</el-dropdown-item>
)
})}
</el-dropdown-menu>
</el-dropdown>
</span>
)
}
formatter: AccountConnectFormatter
}
}
}
}
},
computed: {
...mapGetters(['protocolMap'])
},
async mounted() {
mounted() {
},
methods: {
getAssetDetail(id) {
const detailUrl = `/api/v1/assets/assets/${id}`
return new Promise((resolve, reject) => {
this.$axios
.get(detailUrl)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
})
},
handleWindowOpen(row, protocol) {
window.open(
`/luna/pam_connect/${row.id}/${row.username}/${row.asset.id}/${
row.asset.name
}/${protocol}`,
'_blank'
)
},
async handlePamConnect(row) {
const protocolMap = this.protocolMap
if (protocolMap.has(row.id)) {
const protocol = protocolMap.get(row.id)
this.handleWindowOpen(row, protocol)
} else {
try {
const res = await this.getAssetDetail(row.asset.id)
if (res) {
const protocol = res.protocols[0]
this.$store.commit('table/SET_PROTOCOL_MAP_ITEM', {
key: row.id,
value: protocol.name
})
this.handleWindowOpen(row, protocol.name)
}
} catch (e) {
console.log(e)
}
}
},
async getPermdProtocols(assetId) {
try {
const res = await this.getAssetDetail(assetId)
if (res) {
this.perm_protocols = res.protocols
}
} catch (e) {
console.log(e)
}
}
}
}
</script>
Expand Down Expand Up @@ -208,9 +92,4 @@ export default {
.asset-user-table {
padding-left: 20px;
}
.el-dropdown-menu__item.is-disabled {
font-weight: 500;
color: var(--el-text-color-secondary);
}
</style>

0 comments on commit c7fd044

Please sign in to comment.