fix(EmployeeSelector): 修复员工选择器中重复员工的问题
因为员工可能出现重名情况,添加去重逻辑确保selectedEmployees中每个员工的keyField是唯一的
This commit is contained in:
@@ -279,10 +279,13 @@ export default {
|
|||||||
findSelectedEmployees(values) {
|
findSelectedEmployees(values) {
|
||||||
if (this.employeeList.length > 0) {
|
if (this.employeeList.length > 0) {
|
||||||
this.selectedEmployees = this.employeeList.filter(item => values.includes(item[this.keyField]))
|
this.selectedEmployees = this.employeeList.filter(item => values.includes(item[this.keyField]))
|
||||||
|
// 因为员工可能出现重名,所以需要去重,保证selectedEmployees[i][this.keyField]是唯一的
|
||||||
|
this.selectedEmployees = this.selectedEmployees.filter((item, index, arr) => arr.findIndex(t => t[this.keyField] === item[this.keyField]) === index)
|
||||||
} else {
|
} else {
|
||||||
// 如果员工列表为空,先获取列表再查找
|
// 如果员工列表为空,先获取列表再查找
|
||||||
this.getEmployeeList().then(() => {
|
this.getEmployeeList().then(() => {
|
||||||
this.selectedEmployees = this.employeeList.filter(item => values.includes(item[this.keyField]))
|
this.selectedEmployees = this.employeeList.filter(item => values.includes(item[this.keyField]))
|
||||||
|
this.selectedEmployees = this.selectedEmployees.filter((item, index, arr) => arr.findIndex(t => t[this.keyField] === item[this.keyField]) === index)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user