From a0658d93d8c5ed3f6ab0a7aaea7d353393129bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chuailei000=E2=80=9D?= <2280131253@qq.com> Date: Thu, 23 Feb 2023 16:13:00 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=B5=84=E4=BA=A7=E6=97=B6=E6=B7=BB=E5=8A=A0=E7=9B=B8=E5=90=8C?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=B4=A6=E5=8F=B7=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/AccountTemplateDialog.vue | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/views/assets/Asset/AssetCreateUpdate/components/AccountTemplateDialog.vue b/src/views/assets/Asset/AssetCreateUpdate/components/AccountTemplateDialog.vue index 34df5fb7e..e451def6d 100644 --- a/src/views/assets/Asset/AssetCreateUpdate/components/AccountTemplateDialog.vue +++ b/src/views/assets/Asset/AssetCreateUpdate/components/AccountTemplateDialog.vue @@ -37,7 +37,7 @@ - + !i?.id) - values.forEach((item, index) => { - const hasSameTypeAccount = _.filter(notIdAccounts, function(o) { - return o.username === item.username && o.secret_type === item.secret_type.value - }) - if (hasSameTypeAccount.length > 0) { - this.$message.error(this.$t('accounts.SameTypeAccountTip')) - this.$refs.dataTable.$refs.dataTable.toggleRowSelection(item, false) - this.accountsSelected.splice(index, 1) - } - }) - }, hasSelectValue(row) { return this.accountsSelected.some(item => item.id === row.id) }, + // 判断是否有相同类型的账号, 有则不允许选择 + hasSameTypeAccount(row) { + const notIdAccounts = this.accounts.filter(i => !i?.id) + const needFilterAccounts = [...notIdAccounts, ...this.accountsSelected] + const status = needFilterAccounts.some(item => { + return row.username === item.username && ( + row.secret_type.value === item.secret_type || + row.secret_type.value === item.secret_type.value + ) + }) + if (status) { + this.$refs.dataTable.$refs.dataTable.toggleRowSelection(row, false) + this.$message.error(this.$t('accounts.SameTypeAccountTip')) + } + return status + }, addRowToSelect(row) { const hasSelectValue = this.hasSelectValue(row) - if (!hasSelectValue) { + const hasSameTypeAccount = this.hasSameTypeAccount(row) + if (!hasSelectValue && !hasSameTypeAccount) { this.accountsSelected.push(row) } },