Blame view

src/components/staff/staffDetailOrgPrivilege.vue 3.97 KB
b25b036d   wuxw   v1.9 优化日期
1
  <template>
ebc1053d   wuxw   加入运营员工详情功能
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    <el-row class="margin-top" :gutter="20">
      <el-col :span="18">
        <el-card>
          <div class="text-left">
            <h5>{{ $t('staffDetailOrgPrivilege.relatedOrg') }}</h5>
            <el-row v-for="(item, index) in orgs" :key="index" class="margin-top">
              <el-col :span="12">{{ $t('staffDetailOrgPrivilege.org') }}:{{ item.orgName }}</el-col>
              <el-col :span="12">{{ $t('staffDetailOrgPrivilege.position') }}:{{ item.relCdName }}</el-col>
            </el-row>
          </div>
        </el-card>
  
        <el-card class="margin-top">
          <div class="text-left">
            <h5>{{ $t('staffDetailOrgPrivilege.relatedRole') }}</h5>
            <el-row v-for="(item, index) in roles" :key="index">
              <el-col :span="24">
                <p v-if="item.roleCommunityDtoList.length > 0">{{ item.roleName }}</p>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
  
      <el-col :span="6">
        <el-card>
          <div class="mail-box-header border-radius-top text-left">
            <h2>{{ $t('staffDetailOrgPrivilege.staffPrivilege') }}</h2>
          </div>
  
          <el-tree :data="privilegesTree" node-key="id" default-expand-all :props="treeProps" :expand-on-click-node="false">
          </el-tree>
        </el-card>
      </el-col>
    </el-row>
  </template>
  
  <script>
  import { getStaffOrgs, getStaffRoles, getStaffPrivileges } from '@/api/staff/aStaffDetailApi'
  
  export default {
    name: 'StaffDetailOrgPrivilege',
    props: {
      staffId: {
        type: String,
        required: true
      }
    },
    data() {
      return {
        orgs: [],
        roles: [],
        privileges: [],
        privilegesTree: [],
        treeProps: {
          children: 'children',
          label: 'text'
        }
      }
    },
    watch: {
      staffId: {
        immediate: true,
        handler(newVal) {
          if (newVal) {
            this.loadData()
          }
        }
      }
    },
    methods: {
      async loadData() {
        await Promise.all([
          this.loadStaffOrgs(),
          this.loadStaffRoles(),
          this.loadStaffPrivileges()
        ])
        this.buildPrivilegesTree()
      },
      async loadStaffOrgs() {
        try {
          const response = await getStaffOrgs({
            staffId: this.staffId,
            page: 1,
            row: 999
          })
          this.orgs = response.data || []
        } catch (error) {
          this.$message.error(this.$t('staffDetailOrgPrivilege.loadOrgsError'))
        }
      },
      async loadStaffRoles() {
        try {
          const response = await getStaffRoles({
            staffId: this.staffId,
            page: 1,
            row: 999
          })
          this.roles = response.data || []
        } catch (error) {
          this.$message.error(this.$t('staffDetailOrgPrivilege.loadRolesError'))
        }
      },
      async loadStaffPrivileges() {
        try {
          const response = await getStaffPrivileges({
            staffId: this.staffId
          })
          this.privileges = response.datas || []
        } catch (error) {
          this.$message.error(this.$t('staffDetailOrgPrivilege.loadPrivilegesError'))
        }
      },
      buildPrivilegesTree() {
        const groupMap = new Map()
  
        // 构建组节点
        this.privileges.forEach(item => {
          if (!groupMap.has(item.gId)) {
            groupMap.set(item.gId, {
              id: `g_${item.gId}`,
              gId: item.gId,
              text: item.gName,
              children: []
            })
          }
        })
  
        // 构建菜单节点
        this.privileges.forEach(item => {
          const group = groupMap.get(item.gId)
          let menu = group.children.find(m => m.mId === item.mId)
  
          if (!menu) {
            menu = {
              id: `m_${item.mId}`,
              mId: item.mId,
              text: item.mName,
              children: []
            }
            group.children.push(menu)
          }
  
          // 添加权限节点
          menu.children.push({
            id: `p_${item.pId}`,
            pId: item.pId,
            text: item.pName
          })
        })
  
        this.privilegesTree = Array.from(groupMap.values())
      }
    }
  }
  </script>