/** * 获取本地存储的用户权限标识数组 */ export function getPermList() { const perms = uni.getStorageSync('userPermission') return Array.isArray(perms) ? perms : [] } /** * 权限校验函数 * @param perm 单个权限字符串 / 多个权限数组 * @param mode or满足任一 / and全部满足,默认or * @returns 是否拥有权限 */ 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 { // 有一个即可 return checkArr.some(item => permList.includes(item)) } } /** * 退出登录清空权限 */ export function clearPermList() { uni.removeStorageSync('userPermission') }