diff --git a/src/components/Apps/AccountListTable/AccountList.vue b/src/components/Apps/AccountListTable/AccountList.vue index 1220d33f6..4b8863030 100644 --- a/src/components/Apps/AccountListTable/AccountList.vue +++ b/src/components/Apps/AccountListTable/AccountList.vue @@ -148,6 +148,7 @@ export default { type: Boolean, default: true }, + // target for ad connect btn, if not has, ad account should be select one target: { type: Object, default: null @@ -186,7 +187,7 @@ export default { }, columnsMeta: { name: { - minWidth: '120px', + minWidth: '60px', formatterArgs: { can: () => vm.$hasPerm('accounts.view_account'), getRoute: ({ row }) => ({ @@ -212,15 +213,9 @@ export default { width: '80px', formatter: AccountConnectFormatter, formatterArgs: { - buttonIcon: 'fa fa-desktop', - url: '/api/v1/assets/assets/{id}', can: () => this.currentUserIsSuperAdmin, - connectUrlTemplate: (row) => `/luna/direct_connect/${row.id}/${row.username}/${row.asset.id}/${row.asset.name}/`, - setMapItem: (id, protocol) => { - this.$store.commit('table/SET_PROTOCOL_MAP_ITEM', { - key: id, - value: protocol - }) + connectUrlTemplate: (row) => { + } } }, @@ -238,7 +233,7 @@ export default { } }, username: { - minWidth: '120px', + minWidth: '60px', formatter: function(row) { if (row.ad_domain) { return `${row.username}@${row.ad_domain}` diff --git a/src/components/Table/TableFormatters/AccountConnectFormatter.vue b/src/components/Table/TableFormatters/AccountConnectFormatter.vue index 6a2493fe1..2fde206d3 100644 --- a/src/components/Table/TableFormatters/AccountConnectFormatter.vue +++ b/src/components/Table/TableFormatters/AccountConnectFormatter.vue @@ -1,24 +1,32 @@ @@ -50,85 +48,70 @@ export default { name: 'AccountConnectFormatter', extends: BaseFormatter, props: { - buttonIcon: { - type: String, - default: 'fa fa-desktop' - }, - titleText: { - type: String, - default: '' - }, - url: { - type: String, - default: '' + formatterArgsDefault: { + type: Object, + default() { + return { + can: () => true, + getConnectUrl: (row, protocol) => { + return `/luna/admin-connect/? + asset=${row.asset.id} + &account=${row.id} + &protocol=${protocol} + `.replace(/\s+/g, '') + }, + assetUrl: '/api/v1/assets/assets/{id}/', + buttonIcon: 'fa fa-desktop' + } + } } }, data() { return { - hasPerm: false, - protocols: [] + formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs), + protocols: [], + isClick: false, + getProtocolsLoading: false, + dropdownTitle: this.$t('Protocols') } }, computed: { - IButtonIcon() { - return this.buttonIcon + iButtonIcon() { + return this.formatterArgs.buttonIcon }, - ITitleText() { - return this.titleText || this.$t('SelectProtocol') + hasPerm() { + return this.formatterArgs.can(this.row, this.cellValue) } }, - mounted() { - this.hasPerm = this.formatterArgs.can() - }, methods: { - handleCommand(protocol) { - if (protocol === 'Title') return - - this.formatterArgs.setMapItem(this.row.id, protocol) - this.handleWindowOpen(this.row, protocol) + handleProtocolConnect(protocol) { + const url = this.formatterArgs.getConnectUrl(this.row, protocol) + window.open(url, '_blank') }, visibleChange(visible) { if (visible) { this.getProtocols(this.row.asset.id) } }, - handleWindowOpen(row, protocol) { - const url = this.formatterArgs.connectUrlTemplate(row) + `${protocol}` - - this.$nextTick(() => { - window.open(url, '_blank') - }) - }, - async handlePamConnect() { - const protocolMap = this.$store.getters.protocolMap - - if (protocolMap.has(this.row.id)) { - // 直连 - const protocol = protocolMap.get(this.row.id) - this.handleWindowOpen(this.row, protocol) - } else { - try { - const url = this.formatterArgs.url.replace('{id}', this.row.asset.id) - const res = await this.$axios.get(url) - - if (res && res.protocols.length > 0) { - const protocol = res.protocols[0] - - this.formatterArgs.setMapItem(this.row.id, protocol.name) - this.handleWindowOpen(this.row, protocol.name) - } - } catch (e) { - throw new Error(`Error getting protocols: ${e}`) - } + async handleBtnConnect() { + this.isClick = true + if (this.protocols === 0) { + await this.getProtocols(this.row.asset.id) } + + if (this.protocols.length > 0) { + this.handleProtocolConnect(this.protocols[0].name) + } + setTimeout(() => { + this.isClick = false + }, 1000) }, async getProtocols(assetId) { + if (this.protocols.length > 0) return try { - const url = this.formatterArgs.url.replace('{id}', assetId) + const url = this.formatterArgs.assetUrl.replace('{id}', assetId) const res = await this.$axios.get(url) - - // 暂将 SFTP 过滤 - if (res) this.protocols = res.protocols + this.protocols = res.protocols || [] } catch (e) { throw new Error(`Error getting protocols: ${e}`) } @@ -137,7 +120,7 @@ export default { } -