permission.js 621 B

12345678910111213141516171819202122232425
  1. import store from '@/store'
  2. /**
  3. * 字符权限校验
  4. * @param {Array} value 校验值
  5. * @returns {Boolean}
  6. */
  7. export function checkPermi(value) {
  8. if (value && value instanceof Array && value.length > 0) {
  9. const permissions = store.getters && store.getters.permissions
  10. const permissionDatas = value
  11. const hasPermission = permissions.some(permission => {
  12. return permissionDatas.includes(permission)
  13. })
  14. if (!hasPermission) {
  15. return false
  16. }
  17. return true
  18. } else {
  19. console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
  20. return false
  21. }
  22. }