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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<script setup lang="ts">
import type { TreeActionType } from '@jnpf/ui';
 
import { nextTick, onMounted, reactive, ref, toRefs, unref, watch } from 'vue';
 
import { BasicLeftTree, BasicTree } from '@jnpf/ui';
 
import { getAuthGroup, getAuthList } from '#/api/permission/user';
 
interface State {
  activeKey: string;
  authData: any;
  loading: boolean;
  treeLoading: boolean;
  treeData: any[];
  authGroupData: any[];
  key: number;
  selectedId: string;
}
 
const props = defineProps({
  userId: { default: '', type: String },
});
const state = reactive<State>({
  activeKey: 'module',
  authData: {},
  loading: false,
  treeLoading: false,
  treeData: [],
  authGroupData: [],
  key: Date.now(),
  selectedId: '',
});
const { activeKey, loading, treeLoading, key, treeData, authGroupData } = toRefs(state);
const leftTreeRef = ref<Nullable<TreeActionType>>(null);
 
watch(
  () => state.activeKey,
  (val) => {
    state.treeData = state.authData[val] || [];
    state.key = Date.now();
  },
);
 
function init() {
  state.selectedId = '';
  state.activeKey = 'module';
  state.authGroupData = [];
  state.authData = [];
  state.treeLoading = true;
  getAuthGroup({ userId: props.userId }).then((res) => {
    state.authGroupData = res.data.map((o) => ({ ...o, disabled: !!o.hasChildren })) || [];
    state.treeLoading = false;
    nextTick(() => {
      state.authGroupData?.length && unref(leftTreeRef)?.setSelectedKeys([state.authGroupData[0]?.id]);
      handleTreeSelect(state.authGroupData[0]?.id, state.authGroupData[0]);
    });
  });
}
function getAuthData(objectId, objectType) {
  state.loading = true;
  getAuthList({ userId: props.userId, objectId, objectType }).then((res) => {
    state.authData = res.data;
    state.treeData = state.authData[state.activeKey] || [];
    state.key = Date.now();
    nextTick(() => {
      state.activeKey = 'module';
      state.loading = false;
    });
  });
}
function handleTreeSelect(id, item) {
  if (state.selectedId == id || item.hasChildren) return;
  state.selectedId = id;
  getAuthData(id, item.type);
}
 
onMounted(() => {
  init();
});
</script>
<template>
  <div class="jnpf-content-wrapper authorize">
    <div class="jnpf-content-wrapper-left">
      <BasicLeftTree
        ref="leftTreeRef"
        :show-search="false"
        :show-toolbar="false"
        title="查看范围"
        :tree-data="authGroupData"
        :loading="treeLoading"
        @select="handleTreeSelect" />
    </div>
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content">
        <a-tabs v-model:active-key="activeKey">
          <a-tab-pane tab="菜单权限" key="module" />
          <a-tab-pane tab="按钮权限" key="button" />
          <a-tab-pane tab="列表权限" key="column" />
          <a-tab-pane tab="表单权限" key="form" />
          <a-tab-pane tab="数据权限" key="resource" />
          <a-tab-pane tab="流程权限" key="flow" />
          <a-tab-pane tab="打印文件权限" key="print" />
        </a-tabs>
        <div class="auth-tree">
          <BasicTree :tree-data="treeData" :loading="loading" :default-expand-level="1" :key="key" />
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.authorize {
  height: 100%;
 
  .jnpf-content-wrapper-left {
    margin-right: unset;
    border-right: 1px solid var(--border-color-base);
    border-radius: unset;
  }
 
  :deep(.ant-tabs-nav) {
    height: 50px;
 
    .ant-tabs-tab:first-child {
      padding-left: 10px;
    }
  }
 
  .auth-tree {
    height: calc(100% - 64px);
    overflow: auto;
  }
}
</style>