隐藏用户档案无效按钮
This commit is contained in:
parent
f04c73cbf6
commit
a05f6401ca
|
|
@ -411,6 +411,8 @@
|
|||
<script>
|
||||
import { listProfile, getProfile, getProfileByUserId, delProfile, addProfile, updateProfile, getUserInfo, addUserInProfile, getUserInfoById, updateUserInProfile, delUserInProfile } from "@/api/psychology/profile"
|
||||
import { deptTreeSelect } from "@/api/system/user"
|
||||
import { allocatedUserList } from "@/api/system/role"
|
||||
import { listRole } from "@/api/system/role"
|
||||
import { getToken } from "@/utils/auth"
|
||||
import Treeselect from "@riophae/vue-treeselect"
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
|
||||
|
|
@ -436,6 +438,8 @@ export default {
|
|||
total: 0,
|
||||
// 档案表格数据
|
||||
profileList: [],
|
||||
// 学员角色ID(缓存)
|
||||
studentRoleId: null,
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
|
|
@ -535,17 +539,58 @@ export default {
|
|||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
this.getStudentRoleId().then(() => {
|
||||
this.getList()
|
||||
})
|
||||
this.getDeptTree()
|
||||
this.getConfigKey("sys.user.initPassword").then(response => {
|
||||
this.initPassword = response.msg
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
/** 获取学员角色ID */
|
||||
getStudentRoleId() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.studentRoleId) {
|
||||
resolve(this.studentRoleId)
|
||||
return
|
||||
}
|
||||
// 先尝试从角色列表中找到学员角色
|
||||
listRole({}).then(response => {
|
||||
const roles = response.rows || []
|
||||
// 查找学员角色:roleId=101 或 roleKey='student' 或 roleName包含'学员'
|
||||
const studentRole = roles.find(role => {
|
||||
return (role.roleId === 101) ||
|
||||
(role.roleKey && role.roleKey.toLowerCase() === 'student') ||
|
||||
(role.roleName && role.roleName.includes('学员'))
|
||||
})
|
||||
if (studentRole && studentRole.roleId) {
|
||||
this.studentRoleId = studentRole.roleId
|
||||
resolve(this.studentRoleId)
|
||||
} else {
|
||||
// 如果找不到,尝试使用默认值101
|
||||
console.warn("未找到学员角色,使用默认值101")
|
||||
this.studentRoleId = 101
|
||||
resolve(this.studentRoleId)
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error("获取角色列表失败:", error)
|
||||
// 如果获取角色列表失败,尝试使用默认值101
|
||||
this.studentRoleId = 101
|
||||
resolve(this.studentRoleId)
|
||||
})
|
||||
})
|
||||
},
|
||||
/** 查询档案列表 */
|
||||
getList() {
|
||||
this.loading = true
|
||||
listProfile(this.queryParams).then(response => {
|
||||
// 为了正确过滤学员用户,需要获取所有数据(不分页或获取足够多的数据)
|
||||
const queryParams = {
|
||||
...this.queryParams,
|
||||
pageNum: 1,
|
||||
pageSize: 10000 // 获取足够多的数据,确保能过滤所有记录
|
||||
}
|
||||
listProfile(queryParams).then(response => {
|
||||
const rows = response.rows || []
|
||||
// 为状态设置默认值,确保是字符串类型
|
||||
rows.forEach(row => {
|
||||
|
|
@ -555,23 +600,125 @@ export default {
|
|||
row.status = String(row.status) // 确保是字符串类型
|
||||
}
|
||||
})
|
||||
this.profileList = rows
|
||||
this.total = response.total || 0
|
||||
this.selectedRows = []
|
||||
this.ids = []
|
||||
this.single = true
|
||||
this.multiple = true
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.profileTable) {
|
||||
this.$refs.profileTable.clearSelection()
|
||||
}
|
||||
})
|
||||
this.loading = false
|
||||
// 如果已获取学员角色ID,过滤掉非学员用户
|
||||
if (this.studentRoleId) {
|
||||
this.filterStudentUsers(rows).then(filteredRows => {
|
||||
// 前端分页处理
|
||||
const pageNum = this.queryParams.pageNum || 1
|
||||
const pageSize = this.queryParams.pageSize || 10
|
||||
const start = (pageNum - 1) * pageSize
|
||||
const end = start + pageSize
|
||||
this.profileList = filteredRows.slice(start, end)
|
||||
this.total = filteredRows.length
|
||||
this.selectedRows = []
|
||||
this.ids = []
|
||||
this.single = true
|
||||
this.multiple = true
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.profileTable) {
|
||||
this.$refs.profileTable.clearSelection()
|
||||
}
|
||||
})
|
||||
this.loading = false
|
||||
}).catch(error => {
|
||||
console.error("过滤学员用户失败:", error)
|
||||
// 如果过滤失败,仍然显示所有用户(但不推荐)
|
||||
const pageNum = this.queryParams.pageNum || 1
|
||||
const pageSize = this.queryParams.pageSize || 10
|
||||
const start = (pageNum - 1) * pageSize
|
||||
const end = start + pageSize
|
||||
this.profileList = rows.slice(start, end)
|
||||
this.total = rows.length
|
||||
this.selectedRows = []
|
||||
this.ids = []
|
||||
this.single = true
|
||||
this.multiple = true
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.profileTable) {
|
||||
this.$refs.profileTable.clearSelection()
|
||||
}
|
||||
})
|
||||
this.loading = false
|
||||
})
|
||||
} else {
|
||||
// 如果还没有获取到学员角色ID,先获取再过滤
|
||||
this.getStudentRoleId().then(() => {
|
||||
this.filterStudentUsers(rows).then(filteredRows => {
|
||||
// 前端分页处理
|
||||
const pageNum = this.queryParams.pageNum || 1
|
||||
const pageSize = this.queryParams.pageSize || 10
|
||||
const start = (pageNum - 1) * pageSize
|
||||
const end = start + pageSize
|
||||
this.profileList = filteredRows.slice(start, end)
|
||||
this.total = filteredRows.length
|
||||
this.selectedRows = []
|
||||
this.ids = []
|
||||
this.single = true
|
||||
this.multiple = true
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.profileTable) {
|
||||
this.$refs.profileTable.clearSelection()
|
||||
}
|
||||
})
|
||||
this.loading = false
|
||||
}).catch(error => {
|
||||
console.error("过滤学员用户失败:", error)
|
||||
const pageNum = this.queryParams.pageNum || 1
|
||||
const pageSize = this.queryParams.pageSize || 10
|
||||
const start = (pageNum - 1) * pageSize
|
||||
const end = start + pageSize
|
||||
this.profileList = rows.slice(start, end)
|
||||
this.total = rows.length
|
||||
this.selectedRows = []
|
||||
this.ids = []
|
||||
this.single = true
|
||||
this.multiple = true
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.profileTable) {
|
||||
this.$refs.profileTable.clearSelection()
|
||||
}
|
||||
})
|
||||
this.loading = false
|
||||
})
|
||||
})
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error("查询档案列表失败:", error)
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
/** 过滤学员用户 */
|
||||
filterStudentUsers(rows) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.studentRoleId || rows.length === 0) {
|
||||
resolve(rows)
|
||||
return
|
||||
}
|
||||
// 获取所有学员用户ID列表
|
||||
allocatedUserList({
|
||||
roleId: this.studentRoleId,
|
||||
status: '0',
|
||||
pageNum: 1,
|
||||
pageSize: 10000
|
||||
}).then(response => {
|
||||
const studentUserIds = new Set()
|
||||
const studentUsers = response.rows || []
|
||||
studentUsers.forEach(user => {
|
||||
if (user.userId) {
|
||||
studentUserIds.add(user.userId)
|
||||
}
|
||||
})
|
||||
// 过滤出只包含学员用户的记录
|
||||
const filteredRows = rows.filter(row => {
|
||||
return row.userId && studentUserIds.has(row.userId)
|
||||
})
|
||||
resolve(filteredRows)
|
||||
}).catch(error => {
|
||||
console.error("获取学员用户列表失败:", error)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false
|
||||
|
|
@ -899,30 +1046,36 @@ export default {
|
|||
this.$modal.msgError("请选择要删除的记录")
|
||||
return
|
||||
}
|
||||
const profileIdSet = new Set()
|
||||
const userIdSet = new Set()
|
||||
const userIdsWithProfile = new Set() // 记录有档案的用户ID
|
||||
targets.forEach(item => {
|
||||
// 优先使用 profileId,如果没有则使用 userId
|
||||
if (item.profileId) {
|
||||
profileIdSet.add(item.profileId)
|
||||
// 记录有档案的用户ID(删除档案时会自动删除用户,不需要单独删除)
|
||||
if (item.userId) {
|
||||
userIdsWithProfile.add(item.userId)
|
||||
}
|
||||
} else if (item.userId) {
|
||||
// 没有 profileId,但有 userId,说明用户存在但可能没有档案,需要单独删除用户
|
||||
userIdSet.add(item.userId)
|
||||
// 检查是否都是学员用户(非学员用户不能删除)
|
||||
this.checkStudentUsers(targets).then(isAllStudents => {
|
||||
if (!isAllStudents) {
|
||||
this.$modal.msgError("只能删除学员用户,系统管理员等非学员用户不能删除")
|
||||
return
|
||||
}
|
||||
})
|
||||
const profileIds = Array.from(profileIdSet)
|
||||
// 只保留没有档案的用户ID(避免重复删除)
|
||||
const userIds = Array.from(userIdSet).filter(userId => !userIdsWithProfile.has(userId))
|
||||
const profileIdSet = new Set()
|
||||
const userIdSet = new Set()
|
||||
const userIdsWithProfile = new Set() // 记录有档案的用户ID
|
||||
targets.forEach(item => {
|
||||
// 优先使用 profileId,如果没有则使用 userId
|
||||
if (item.profileId) {
|
||||
profileIdSet.add(item.profileId)
|
||||
// 记录有档案的用户ID(删除档案时会自动删除用户,不需要单独删除)
|
||||
if (item.userId) {
|
||||
userIdsWithProfile.add(item.userId)
|
||||
}
|
||||
} else if (item.userId) {
|
||||
// 没有 profileId,但有 userId,说明用户存在但可能没有档案,需要单独删除用户
|
||||
userIdSet.add(item.userId)
|
||||
}
|
||||
})
|
||||
const profileIds = Array.from(profileIdSet)
|
||||
// 只保留没有档案的用户ID(避免重复删除)
|
||||
const userIds = Array.from(userIdSet).filter(userId => !userIdsWithProfile.has(userId))
|
||||
|
||||
if (!profileIds.length && !userIds.length) {
|
||||
this.$modal.msgError("未找到可删除的档案或用户")
|
||||
return
|
||||
}
|
||||
if (!profileIds.length && !userIds.length) {
|
||||
this.$modal.msgError("未找到可删除的档案或用户")
|
||||
return
|
||||
}
|
||||
|
||||
const parts = []
|
||||
if (profileIds.length) {
|
||||
|
|
@ -931,31 +1084,67 @@ export default {
|
|||
if (userIds.length) {
|
||||
parts.push(`用户编号 ${userIds.join(',')}`)
|
||||
}
|
||||
const message = `是否确认删除${parts.join(' 和 ')}?`
|
||||
const message = `是否确认删除${parts.join(' 和 ')}?`
|
||||
|
||||
this.$modal.confirm(message).then(() => {
|
||||
const tasks = []
|
||||
// 删除档案(如果有)
|
||||
profileIds.forEach(id => tasks.push(delProfile(id)))
|
||||
// 删除用户(只删除没有档案的用户)
|
||||
// 注意:如果用户有档案,删除档案时会自动删除用户,所以这里只删除没有档案的用户
|
||||
if (userIds.length) {
|
||||
// 找出没有档案的用户(在 targets 中没有 profileId 的用户)
|
||||
const userIdsWithoutProfile = userIds.filter(userId => {
|
||||
return !targets.some(item => item.userId === userId && item.profileId)
|
||||
})
|
||||
if (userIdsWithoutProfile.length > 0) {
|
||||
tasks.push(delUserInProfile(userIdsWithoutProfile))
|
||||
this.$modal.confirm(message).then(() => {
|
||||
const tasks = []
|
||||
// 删除档案(如果有)
|
||||
profileIds.forEach(id => tasks.push(delProfile(id)))
|
||||
// 删除用户(只删除没有档案的用户)
|
||||
// 注意:如果用户有档案,删除档案时会自动删除用户,所以这里只删除没有档案的用户
|
||||
if (userIds.length) {
|
||||
// 找出没有档案的用户(在 targets 中没有 profileId 的用户)
|
||||
const userIdsWithoutProfile = userIds.filter(userId => {
|
||||
return !targets.some(item => item.userId === userId && item.profileId)
|
||||
})
|
||||
if (userIdsWithoutProfile.length > 0) {
|
||||
tasks.push(delUserInProfile(userIdsWithoutProfile))
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.all(tasks)
|
||||
}).then(() => {
|
||||
this.getList()
|
||||
this.$modal.msgSuccess("删除成功")
|
||||
return Promise.all(tasks)
|
||||
}).then(() => {
|
||||
this.getList()
|
||||
this.$modal.msgSuccess("删除成功")
|
||||
}).catch(error => {
|
||||
console.error("删除失败:", error)
|
||||
const errorMsg = error.msg || error.message || "删除失败"
|
||||
this.$modal.msgError(errorMsg)
|
||||
})
|
||||
}).catch(error => {
|
||||
console.error("删除失败:", error)
|
||||
const errorMsg = error.msg || error.message || "删除失败"
|
||||
this.$modal.msgError(errorMsg)
|
||||
console.error("检查学员用户失败:", error)
|
||||
this.$modal.msgError("检查用户角色失败,无法删除")
|
||||
})
|
||||
},
|
||||
/** 检查用户是否都是学员用户 */
|
||||
checkStudentUsers(targets) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.studentRoleId || !targets || targets.length === 0) {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
// 获取所有学员用户ID列表
|
||||
allocatedUserList({
|
||||
roleId: this.studentRoleId,
|
||||
status: '0',
|
||||
pageNum: 1,
|
||||
pageSize: 10000
|
||||
}).then(response => {
|
||||
const studentUserIds = new Set()
|
||||
const studentUsers = response.rows || []
|
||||
studentUsers.forEach(user => {
|
||||
if (user.userId) {
|
||||
studentUserIds.add(user.userId)
|
||||
}
|
||||
})
|
||||
// 检查所有目标用户是否都是学员用户
|
||||
const allAreStudents = targets.every(item => {
|
||||
return item.userId && studentUserIds.has(item.userId)
|
||||
})
|
||||
resolve(allAreStudents)
|
||||
}).catch(error => {
|
||||
console.error("获取学员用户列表失败:", error)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
/** 导出按钮操作 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user