ll
liukangdong
2025-03-11 6ea077ecfd9c3ed956570692600e7e55796c9bfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script>
import { mapState } from 'vuex'
import BaseComputHeightDefault from '@/components/base/BaseComputHeightDefault'
export default {
  extends: BaseComputHeightDefault,
  name: 'BasePage',
  data () {
    return {
      // 超级管理员角色code
      adminCode: 'admin'
    }
  },
  computed: {
    ...mapState(['userInfo']),
    // 是否为超级管理员
    isAdmin() {
      return this.userInfo.roles.findIndex(code => code === this.adminCode) > -1
    }
  },
  methods: {
    // 是否包含指定角色
    containRoles (roles) {
      if (roles == null) {
        return true
      }
      if (this.userInfo == null) {
        return false
      }
      if (this.userInfo.roles == null || this.userInfo.roles.length === 0) {
        return false
      }
      for (const code of roles) {
        if (this.userInfo.roles.findIndex(r => r === code) > -1) {
          return true
        }
      }
      return false
    },
    // 是否包含指定权限
    containPermissions (permissions) {
      if (permissions == null) {
        return true
      }
      if (this.userInfo == null) {
        return false
      }
      if (this.userInfo.permissions == null || this.userInfo.permissions.length === 0) {
        return false
      }
      for (const code of permissions) {
        if (this.userInfo.permissions.findIndex(p => p === code) > -1) {
          return true
        }
      }
      return false
    }
  }
}
</script>