fix: 修复人员管理删除成员问题
- 删除成员时传入需要保留的用户,而不是删除的用户 - 添加成员时合并现有用户和新用户 - 使用正确的接口格式:roleId + userOrDept数组
This commit is contained in:
parent
46b01b4504
commit
8ded5e9fa4
@ -172,6 +172,7 @@ export default {
|
|||||||
department: ''
|
department: ''
|
||||||
},
|
},
|
||||||
tableData: [],
|
tableData: [],
|
||||||
|
allMembers: [],
|
||||||
selectedMembers: [],
|
selectedMembers: [],
|
||||||
pagination: {
|
pagination: {
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
@ -261,24 +262,18 @@ export default {
|
|||||||
const respData = resp.data
|
const respData = resp.data
|
||||||
const personArray = respData['人员'] || respData.person || []
|
const personArray = respData['人员'] || respData.person || []
|
||||||
|
|
||||||
// 解析人员数组
|
|
||||||
// 格式:["周杰-ID:100771324098969075712-userNumber:yc90117846-department:"]
|
|
||||||
const members = []
|
const members = []
|
||||||
personArray.forEach((personStr) => {
|
personArray.forEach((personStr) => {
|
||||||
if (typeof personStr === 'string') {
|
if (typeof personStr === 'string') {
|
||||||
// 提取用户名(第一个 - 之前)
|
|
||||||
const nameMatch = personStr.match(/^([^-]+)/)
|
const nameMatch = personStr.match(/^([^-]+)/)
|
||||||
const username = nameMatch ? nameMatch[1] : ''
|
const username = nameMatch ? nameMatch[1] : ''
|
||||||
|
|
||||||
// 提取ID
|
|
||||||
const idMatch = personStr.match(/ID:([^-]+)/)
|
const idMatch = personStr.match(/ID:([^-]+)/)
|
||||||
const userId = idMatch ? idMatch[1] : ''
|
const userId = idMatch ? idMatch[1] : ''
|
||||||
|
|
||||||
// 提取userNumber(成员编码)
|
|
||||||
const userNumberMatch = personStr.match(/userNumber:([^-]+)/)
|
const userNumberMatch = personStr.match(/userNumber:([^-]+)/)
|
||||||
const userNumber = userNumberMatch ? userNumberMatch[1] : ''
|
const userNumber = userNumberMatch ? userNumberMatch[1] : ''
|
||||||
|
|
||||||
// 提取department(部门)
|
|
||||||
const deptMatch = personStr.match(/department:(.+)$/)
|
const deptMatch = personStr.match(/department:(.+)$/)
|
||||||
const department = deptMatch ? deptMatch[1] : ''
|
const department = deptMatch ? deptMatch[1] : ''
|
||||||
|
|
||||||
@ -286,14 +281,15 @@ export default {
|
|||||||
members.push({
|
members.push({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
username: username,
|
username: username,
|
||||||
userNumber: userNumber, // 成员编码(用户工号)
|
userNumber: userNumber,
|
||||||
department: department // 部门
|
department: department
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 应用搜索过滤
|
this.allMembers = members
|
||||||
|
|
||||||
let filteredMembers = members
|
let filteredMembers = members
|
||||||
if (this.searchForm.memberName) {
|
if (this.searchForm.memberName) {
|
||||||
filteredMembers = filteredMembers.filter(m =>
|
filteredMembers = filteredMembers.filter(m =>
|
||||||
@ -311,12 +307,12 @@ export default {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分页处理
|
|
||||||
this.pagination.total = filteredMembers.length
|
this.pagination.total = filteredMembers.length
|
||||||
const startIndex = (this.pagination.currentPage - 1) * this.pagination.pageSize
|
const startIndex = (this.pagination.currentPage - 1) * this.pagination.pageSize
|
||||||
const endIndex = startIndex + this.pagination.pageSize
|
const endIndex = startIndex + this.pagination.pageSize
|
||||||
this.tableData = filteredMembers.slice(startIndex, endIndex)
|
this.tableData = filteredMembers.slice(startIndex, endIndex)
|
||||||
} else {
|
} else {
|
||||||
|
this.allMembers = []
|
||||||
this.tableData = []
|
this.tableData = []
|
||||||
this.pagination.total = 0
|
this.pagination.total = 0
|
||||||
}
|
}
|
||||||
@ -324,6 +320,7 @@ export default {
|
|||||||
.asyncErrorCatch((err) => {
|
.asyncErrorCatch((err) => {
|
||||||
console.error('加载成员列表失败:', err)
|
console.error('加载成员列表失败:', err)
|
||||||
this.$message.error('加载成员列表失败,请稍后重试')
|
this.$message.error('加载成员列表失败,请稍后重试')
|
||||||
|
this.allMembers = []
|
||||||
this.tableData = []
|
this.tableData = []
|
||||||
this.pagination.total = 0
|
this.pagination.total = 0
|
||||||
})
|
})
|
||||||
@ -378,12 +375,22 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.addMemberSubmitting = true
|
this.addMemberSubmitting = true
|
||||||
// 使用现有接口绑定角色和用户
|
|
||||||
|
const existingUserIds = this.allMembers.map((m) => m.userId)
|
||||||
|
const newUserIds = this.addMemberFormData.selectedUsers.filter((id) => !existingUserIds.includes(id))
|
||||||
|
|
||||||
|
const allUserIds = [...existingUserIds, ...newUserIds]
|
||||||
|
|
||||||
|
const userOrDept = allUserIds.map((userId) => ({
|
||||||
|
userOrDeptId: userId,
|
||||||
|
isDept: 0
|
||||||
|
}))
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
...api.GET_ROLE_PERMISSION_BING,
|
...api.GET_ROLE_PERMISSION_BING,
|
||||||
data: {
|
data: {
|
||||||
roleID: this.roleId,
|
roleId: this.roleId,
|
||||||
userIDs: this.addMemberFormData.selectedUsers
|
userOrDept: userOrDept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,19 +408,26 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteMembers() {
|
deleteMembers() {
|
||||||
const userIds = this.selectedMembers.map((member) => member.userId)
|
const deleteUserIds = this.selectedMembers.map((member) => member.userId)
|
||||||
// 使用现有接口删除角色用户绑定
|
const retainUsers = this.allMembers.filter((member) => !deleteUserIds.includes(member.userId))
|
||||||
|
|
||||||
|
const userOrDept = retainUsers.map((user) => ({
|
||||||
|
userOrDeptId: user.userId,
|
||||||
|
isDept: 0
|
||||||
|
}))
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
...api.DELETE_ROLE_PERMISSION,
|
...api.GET_ROLE_PERMISSION_BING,
|
||||||
params: {
|
data: {
|
||||||
roleID: this.roleId,
|
roleId: this.roleId,
|
||||||
userIDs: userIds.join(',')
|
userOrDept: userOrDept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$request(request)
|
this.$request(request)
|
||||||
.asyncThen((resp) => {
|
.asyncThen((resp) => {
|
||||||
this.$message.success('删除成员成功')
|
this.$message.success('删除成员成功')
|
||||||
|
this.selectedMembers = []
|
||||||
this.loadMemberList()
|
this.loadMemberList()
|
||||||
})
|
})
|
||||||
.asyncErrorCatch((err) => {
|
.asyncErrorCatch((err) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user