ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
60
61
62
63
64
65
66
67
68
69
70
71
import { useRoute } from 'vue-router';
 
import { useAccessStore } from '@vben/stores';
 
// User permissions related operations
export function usePermission() {
  const accessStore = useAccessStore();
 
  const { permissionList } = accessStore;
  const route = useRoute();
 
  // 确定是否有列表权限
  function hasColumnPermission(
    value?: string,
    def = true,
    modelId?: string,
  ): boolean {
    if (!value) return def;
    const currentModelId = modelId || route.meta.modelId || '';
    if (!currentModelId) return false;
    const list = permissionList.filter((o) => o.modelId === currentModelId);
    if (list.length === 0) return false;
    const columnList = list[0] && list[0].column ? list[0].column : [];
    if (columnList.length === 0) return false;
    const hasPermission = columnList.some((column) => column.enCode === value);
    if (hasPermission) return true;
    return false;
  }
 
  // 确定是否有表单权限
  function hasFormPermission(
    value?: string,
    def = true,
    modelId?: string,
  ): boolean {
    if (!value) return def;
    const currentModelId = modelId || route.meta.modelId || '';
    if (!currentModelId) return false;
    const list = permissionList.filter((o) => o.modelId === currentModelId);
    if (list.length === 0) return false;
    const formList = list[0] && list[0].form ? list[0].form : [];
    if (formList.length === 0) return false;
    const hasPermission = formList.some((form) => form.enCode === value);
    if (hasPermission) return true;
    return false;
  }
 
  // 确定是否有按钮权限
  function hasBtnPermission(
    value?: string,
    def = true,
    modelId?: string,
  ): boolean {
    if (!value) return def;
    const currentModelId = modelId || route.meta.modelId || '';
    if (!currentModelId) return false;
    const list = permissionList.filter((o) => o.modelId === currentModelId);
    if (list.length === 0) return false;
    const btnList = list[0] && list[0].button ? list[0].button : [];
    if (btnList.length === 0) return false;
    const hasPermission = btnList.some((btn) => btn.enCode === value);
    if (hasPermission) return true;
    return false;
  }
 
  return {
    hasBtnP: hasBtnPermission,
    hasColumnP: hasColumnPermission,
    hasFormP: hasFormPermission,
  };
}