修复权限缓存问题

This commit is contained in:
Zy
2026-07-20 16:43:09 +08:00
parent a5a883a652
commit 3a00c3dfe0
10 changed files with 343 additions and 306 deletions

View File

@@ -1,37 +0,0 @@
/**
* 获取本地存储的用户权限标识数组
*/
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')
}