From 2dae51f1ec26f5f4ca07c5481bd0631a7c430fb1 Mon Sep 17 00:00:00 2001 From: lideqin <694785430@qq.com> Date: Thu, 9 May 2024 16:44:44 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E9=80=89=E6=8B=A9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=85=A8=E9=80=89=E5=9C=A8=E5=8E=9F=E6=9D=A5?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E7=9A=84=E6=95=B0=E6=8D=AE=E4=B8=8A=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../selection/UserSelectByContactModal.vue | 14 ++++++++++++-- .../selection/UserSelectByContactNoMergeModal.vue | 14 ++++++++++++-- .../selection/UserSelectByWorkGroupModal.vue | 14 ++++++++++++-- src/components/selection/UserSelectModal.vue | 14 ++++++++++++-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/components/selection/UserSelectByContactModal.vue b/src/components/selection/UserSelectByContactModal.vue index 93b764af..5426ae8c 100644 --- a/src/components/selection/UserSelectByContactModal.vue +++ b/src/components/selection/UserSelectByContactModal.vue @@ -241,13 +241,23 @@ export default { params.order = 'desc' getAction(this.url.userList, params).then(res => { if (res.success) { - this.dataSourceRight = res.result.records || [] - this.selectedRowKeys = (res.result.records || []).map(item => item.contactId) + const arr = this.uniqueByKey([...res.result.records || [], ...this.dataSourceRight || []], 'contactId') + this.dataSourceRight = Array.from(arr) + this.selectedRowKeys = Array.from(arr).map(item => item.contactId) } }).finally(() => { this.loadingLeft = false }) }, + // 根据某个字段对对象数组去重 + uniqueByKey (arr, key) { + const map = arr.reduce((acc, obj) => { + const keyValue = obj[key] + acc[keyValue] = obj + return acc + }, {}) + return Object.values(map) + }, // 获取当前查询条件的所有数据 async getCurrentAllData () { const params = Object.assign({}, this.queryParam) diff --git a/src/components/selection/UserSelectByContactNoMergeModal.vue b/src/components/selection/UserSelectByContactNoMergeModal.vue index 25bdb99d..41a58787 100644 --- a/src/components/selection/UserSelectByContactNoMergeModal.vue +++ b/src/components/selection/UserSelectByContactNoMergeModal.vue @@ -271,13 +271,23 @@ export default { params.order = 'desc' getAction(this.url.userList, params).then(res => { if (res.success) { - this.dataSourceRight = res.result.records || [] - this.selectedRowKeys = (res.result.records || []).map(item => item.id) + const arr = this.uniqueByKey([...res.result.records || [], ...this.dataSourceRight || []], 'id') + this.dataSourceRight = Array.from(arr) + this.selectedRowKeys = Array.from(arr).map(item => item.id) } }).finally(() => { this.loadingLeft = false }) }, + // 根据某个字段对对象数组去重 + uniqueByKey (arr, key) { + const map = arr.reduce((acc, obj) => { + const keyValue = obj[key] + acc[keyValue] = obj + return acc + }, {}) + return Object.values(map) + }, // 获取当前查询条件的所有数据 async getCurrentAllData () { const params = Object.assign({}, this.queryParam) diff --git a/src/components/selection/UserSelectByWorkGroupModal.vue b/src/components/selection/UserSelectByWorkGroupModal.vue index 48c24acb..5227e88d 100644 --- a/src/components/selection/UserSelectByWorkGroupModal.vue +++ b/src/components/selection/UserSelectByWorkGroupModal.vue @@ -340,13 +340,23 @@ export default { params.pageSize = this.ipagination.total + 10 getAction(this.url.userList, params).then(res => { if (res.success) { - this.dataSourceRight = res.result.records || [] - this.selectedRowKeys = (res.result.records || []).map(item => item.userId) + const arr = this.uniqueByKey([...res.result.records || [], ...this.dataSourceRight || []], 'userId') + this.dataSourceRight = Array.from(arr) + this.selectedRowKeys = Array.from(arr).map(item => item.userId) } }).finally(() => { this.loadingLeft = false }) }, + // 根据某个字段对对象数组去重 + uniqueByKey (arr, key) { + const map = arr.reduce((acc, obj) => { + const keyValue = obj[key] + acc[keyValue] = obj + return acc + }, {}) + return Object.values(map) + }, // 获取当前查询条件的所有数据 async getCurrentAllData () { const params = Object.assign({}, this.queryParam) diff --git a/src/components/selection/UserSelectModal.vue b/src/components/selection/UserSelectModal.vue index 1c1472d4..e51b67ff 100644 --- a/src/components/selection/UserSelectModal.vue +++ b/src/components/selection/UserSelectModal.vue @@ -290,14 +290,24 @@ export default { params.order = 'desc' getAction(this.url.userList, params).then(res => { if (res.success) { - this.dataSourceRight = res.result.records || [] - this.selectedRowKeys = (res.result.records || []).map(item => item.id) + const arr = this.uniqueByKey([...res.result.records || [], ...this.dataSourceRight || []], 'id') + this.dataSourceRight = Array.from(arr) + this.selectedRowKeys = Array.from(arr).map(item => item.id) this.oldTotal = res.result.total } }).finally(() => { this.loadingLeft = false }) }, + // 根据某个字段对对象数组去重 + uniqueByKey (arr, key) { + const map = arr.reduce((acc, obj) => { + const keyValue = obj[key] + acc[keyValue] = obj + return acc + }, {}) + return Object.values(map) + }, // 获取当前查询条件的所有数据 async getCurrentAllData () { const params = Object.assign({}, this.queryParam)