wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
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
 
import http from '@/../src/api/http.js'
import buttons from '@/../config/buttons.js'
import store from '../store/index'
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;