隐藏用户档案无效按钮

This commit is contained in:
胡圣锋 2025-11-24 02:55:19 +08:00
parent f04c73cbf6
commit a05f6401ca

View File

@ -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)
})
})
},
/** 导出按钮操作 */