yj
2024-12-05 ac3234c308e86f20cc63465573f321561ee00690
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
import store from '@/store'
 
/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default function checkPermission(value) {
  if (value && value instanceof Array && value.length > 0) {
    const perms = store.getters && store.getters.perms
    const permissions = value
 
    var hasPermission = false
 
    if (perms.indexOf('*') >= 0) {
      hasPermission = true
    } else {
      hasPermission = perms.some(perm => {
        return permissions.includes(perm)
      })
    }
 
    if (!hasPermission) {
      return false
    }
    return true
  } else {
    console.error(`need perms! Like v-permission="['GET /aaa','POST /bbb']"`)
    return false
  }
}