permission.js 756 B

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