permission.js 976 B

123456789101112131415161718192021222324252627
  1. // #ifndef VUE3
  2. export function initPermission(Vue) {
  3. Vue.prototype.$hasPermission = function hasPermission(name) {
  4. const permission = this.$store.state.user.userInfo.permission || []
  5. const role = this.$store.state.user.userInfo.role || []
  6. return role.indexOf('admin') > -1 || permission.indexOf(name) > -1
  7. }
  8. Vue.prototype.$hasRole = function hasRole(name) {
  9. const role = this.$store.state.user.userInfo.role || []
  10. return role.indexOf(name) > -1
  11. }
  12. }
  13. // #endif
  14. // #ifdef VUE3
  15. export function initPermission(app) {
  16. app.config.globalProperties.$hasPermission = function hasPermission(name) {
  17. const permission = this.$store.state.user.userInfo.permission || []
  18. const role = this.$store.state.user.userInfo.role || []
  19. return role.indexOf('admin') > -1 || permission.indexOf(name) > -1
  20. }
  21. app.config.globalProperties.$hasRole = function hasRole(name) {
  22. const role = this.$store.state.user.userInfo.role || []
  23. return role.indexOf(name) > -1
  24. }
  25. }
  26. // #endif