fix: 修复资产账号创建账号失败问题

This commit is contained in:
“huailei000”
2022-10-20 11:11:25 +08:00
committed by huailei
parent 91df9c8f1e
commit 84a04ecfca
5 changed files with 49 additions and 15 deletions

View File

@@ -67,14 +67,13 @@ export default {
methods: {
addAccount(form) {
const data = { asset: this.asset.id, ...form }
this.$axios.post(`/api/v1/assets/accounts/`, data)
.then(() => {
this.iVisible = false
this.$emit('add', true)
})
.catch(() => {
this.$message.error(this.$tc('common.createErrorMsg'))
})
this.$axios.post(`/api/v1/assets/accounts/`, data).then(() => {
this.iVisible = false
this.$emit('add', true)
this.$message.success(this.$t('common.createSuccessMsg'))
}).catch(() => {
this.$message.error(this.$tc('common.createErrorMsg'))
})
},
editAccount(form) {
const data = { ...form }

View File

@@ -11,7 +11,7 @@
<AddAccount
v-if="showAddDialog"
:visible.sync="showAddDialog"
:asset="asset"
:asset="iAsset"
:account="account"
@add="addAccountSuccess"
/>
@@ -26,6 +26,7 @@ import UpdateSecretInfo from './UpdateSecretInfo'
import AddAccount from './AddAccount'
import { connectivityMeta } from './const'
import { openTaskPage } from '@/utils/jms'
import { hasUUID } from '@/utils/common'
export default {
name: 'AccountListTable',
@@ -73,6 +74,7 @@ export default {
showViewSecretDialog: false,
showUpdateSecretDialog: false,
showAddDialog: false,
iAsset: this.asset,
account: {},
tableConfig: {
url: this.url,
@@ -213,6 +215,12 @@ export default {
url(iNew) {
this.$set(this.tableConfig, 'url', iNew)
this.$set(this.headerActions.exportOptions, 'url', iNew.replace('/accounts/', '/account-secrets/'))
},
'$route.query.assets': {
immediate: true,
handler() {
this.hasAccountPermission()
}
}
},
mounted() {
@@ -232,6 +240,14 @@ export default {
},
addAccountSuccess() {
this.$refs.ListTable.reloadTable()
},
hasAccountPermission() {
const { path, query } = this.$route
if (!hasUUID(path)) {
const hasPerm = this.$hasPerm('assets.add_account') && !!query.assets
this.iAsset = { id: query.assets }
this.$set(this.headerActions.extraActions[0], 'can', hasPerm)
}
}
}
}

View File

@@ -209,6 +209,19 @@ export function setUrlParam(url, name, value) {
return url
}
export function setRouterQuery(vm, url = '') {
url = url || vm.tableConfig.url
const params = url.split('?')[1]
const query = Object.fromEntries(new URLSearchParams(params))
const newQuery = {
...vm.$route.query,
...query
}
vm.$nextTick(() => {
vm.$router.replace({ query: newQuery })
})
}
export function getDayFuture(days, now) {
if (!now) {
now = new Date()

View File

@@ -1,7 +1,7 @@
<template>
<GenericTreeListPage ref="TreeTablePage" :tree-setting="treeSetting">
<GenericTreeListPage ref="TreeTablePage" :tree-setting="treeSetting" :table-config="tableConfig">
<template #table>
<AccountListTable ref="table" :url="accountsUrl" :has-left-actions="true" />
<AccountListTable ref="table" v-bind="tableConfig" />
</template>
</GenericTreeListPage>
</template>
@@ -9,7 +9,7 @@
<script>
import GenericTreeListPage from '@/layout/components/GenericTreeListPage'
import AccountListTable from '@/components/AccountListTable'
import { setUrlParam } from '@/utils/common'
import { setUrlParam, setRouterQuery } from '@/utils/common'
export default {
name: 'AssetAccountList',
@@ -21,7 +21,10 @@ export default {
isInit: true,
clickedRow: null,
iShowTree: true,
accountsUrl: '/api/v1/assets/accounts/',
tableConfig: {
url: '/api/v1/assets/accounts/',
hasLeftActions: true
},
treeSetting: {
showMenu: false,
showRefresh: true,
@@ -46,7 +49,9 @@ export default {
url = setUrlParam(url, 'nodes', '')
url = setUrlParam(url, 'assets', assetId)
}
this.accountsUrl = url
this.$set(this.tableConfig, 'url', url)
setRouterQuery(this)
}
}
}

View File

@@ -25,7 +25,7 @@ import $ from '@/utils/jquery-vendor'
import { mapGetters } from 'vuex'
import TreeMenu from './components/TreeMenu'
import BaseList from './components/BaseList'
import { setUrlParam } from '@/utils/common'
import { setUrlParam, setRouterQuery } from '@/utils/common'
export default {
components: {
@@ -103,6 +103,7 @@ export default {
url = setUrlParam(url, 'asset', assetId)
}
this.$set(this.tableConfig, 'url', url)
setRouterQuery(this)
}
}
}