Files
property-manager-side/wuye-manager-uniapp/utils/permissions.js
2026-07-20 14:50:16 +08:00

38 lines
969 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 获取本地存储的用户权限标识数组
*/
export function getPermList() {
const perms = uni.getStorageSync('userPermission')
return Array.isArray(perms) ? perms : []
}
/**
* 权限校验函数
* @param perm 单个权限字符串 / 多个权限数组
* @param mode or满足任一 / and全部满足,默认or
* @returns 是否拥有权限 false 没有权限 true 有权限
*/
export function hasPermi(perm, mode = 'or') {
const permList = getPermList()
// 超级管理员通配符
if (permList.includes('*')) return true
const checkArr = Array.isArray(perm) ? perm : [perm]
if (mode === 'and') {
// 所有权限都要有
return checkArr.every(item => permList.includes(item))
} else {
console.log(permList, checkArr)
// 有一个即可
return checkArr.some(item => permList.includes(item))
}
}
/**
* 退出登录清空权限
*/
export function clearPermList() {
uni.removeStorageSync('userPermission')
}