fix: 修复人员管理删除成员问题

- 删除成员时传入需要保留的用户,而不是删除的用户
- 添加成员时合并现有用户和新用户
- 使用正确的接口格式:roleId + userOrDept数组
This commit is contained in:
Zhou 2026-06-23 10:41:41 +08:00
parent 46b01b4504
commit 8ded5e9fa4

View File

@ -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) => {