This commit is contained in:
2025-03-28 16:27:26 +08:00
parent f654e16c18
commit a3e6a6d8b8
494 changed files with 4072 additions and 47246 deletions
@@ -0,0 +1,39 @@
const {
ERROR
} = require('../common/error')
function hasRole (...roleList) {
const userRole = this.authInfo.role || []
if (userRole.includes('admin')) {
return
}
const isMatch = roleList.every(roleItem => {
return userRole.includes(roleItem)
})
if (!isMatch) {
throw {
errCode: ERROR.PERMISSION_ERROR
}
}
}
function hasPermission (...permissionList) {
const userRole = this.authInfo.role || []
const userPermission = this.authInfo.permission || []
if (userRole.includes('admin')) {
return
}
const isMatch = permissionList.every(permissionItem => {
return userPermission.includes(permissionItem)
})
if (!isMatch) {
throw {
errCode: ERROR.PERMISSION_ERROR
}
}
}
module.exports = {
hasRole,
hasPermission
}