huangxiaoqiang
2025-06-05 f0428c0ce5831765142690676d1b337a84e90b8b
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
import http from '@/api/http.js'
import buttons from './buttons.js'
import store from '@/store/index.js'
import { useRouter } from 'vue-router'
let permission = {
  getMenu() {
    return http.get('/api/getTreeMenu')
  },
 
  getButtons(path, extra, table, tableName) {
    //extra自定额外按钮
    //table获取指定表的权限
    if (table) {
      table = '/' + table
    }
    let permission = store.getters.getPermission(table || path)
    if (!permission) {
      permission = store.getters.getPermission(path.substring(1))
      if (!permission) {
        permission = store.getters.getPermission('/' + tableName)
        if (!permission) {
          to401()
          return
        }
      }
    }
 
    let permissions = permission.permission //.split(',');
    let gridButtons = buttons.filter((item) => {
      return !item.value || permissions.indexOf(item.value) != -1
    })
    if (extra && extra instanceof Array) {
      gridButtons.push(...extra)
    }
    return gridButtons
  },
  to401() {
    to401()
  }
}
function to401() {
  const router = useRouter()
  router.push({
    path: '/401'
  })
}
 
export default permission