Blame view

src/components/role/RoleDiv.vue 3.25 KB
b25b036d   wuxw   v1.9 优化日期
1
  <template>
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
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
      <div class="role-div">
        <div class="role-div-header">
          <el-button type="link" size="small" @click="openAddModal">
            {{ $t('role.add') }}
          </el-button>
          <el-button type="link" size="small" @click="openEditModal">
            {{ $t('role.edit') }}
          </el-button>
          <el-button type="link" size="small" @click="openDeleteModal">
            {{ $t('role.delete') }}
          </el-button>
        </div>
        
        <div class="role-list">
          <ul>
            <li
              v-for="(role, index) in roles"
              :key="index"
              :class="{ active: currentRole.pgId === role.pgId }"
              @click="switchRole(role)"
            >
              {{ role.name }}
            </li>
          </ul>
        </div>
        
        <add-privilege-group
          ref="addPrivilegeGroup"
          @success="loadRoles"
        />
        <edit-privilege-group
          ref="editPrivilegeGroup"
          @success="loadRoles"
        />
        <delete-privilege-group
          ref="deletePrivilegeGroup"
          @success="loadRoles"
        />
      </div>
    </template>
    
    <script>
    import { queryPrivilegeGroup } from '@/api/role/roleApi'
    import AddPrivilegeGroup from './AddPrivilegeGroup'
    import EditPrivilegeGroup from './EditPrivilegeGroup'
    import DeletePrivilegeGroup from './DeletePrivilegeGroup'
    
    export default {
      name: 'RoleDiv',
      components: {
        AddPrivilegeGroup,
        EditPrivilegeGroup,
        DeletePrivilegeGroup
      },
      data() {
        return {
          roles: [],
          currentRole: {}
        }
      },
      created() {
        this.loadRoles()
      },
      methods: {
        async loadRoles() {
          try {
            const params = {
              communityId: '-1'
            }
            const res = await queryPrivilegeGroup(params)
            this.roles = res
            if (this.roles.length > 0) {
              this.switchRole(this.roles[0])
            }
          } catch (error) {
            this.$message.error(error.message)
          }
        },
        switchRole(role) {
          this.currentRole = role
          this.$emit('switch-role', role)
        },
        openAddModal() {
          this.$refs.addPrivilegeGroup.open()
        },
        openEditModal() {
          if (!this.currentRole.pgId) {
            this.$message.warning(this.$t('role.selectRole'))
            return
          }
          this.$refs.editPrivilegeGroup.show(this.currentRole)
        },
        openDeleteModal() {
          if (!this.currentRole.pgId) {
            this.$message.warning(this.$t('role.selectRole'))
            return
          }
          this.$refs.deletePrivilegeGroup.show(this.currentRole)
        }
      }
    }
    </script>
    
    <style lang="scss" scoped>
    .role-div {
      background: #fff;
      border-radius: 4px;
      padding: 15px;
      margin-top: 10px;
      
      .role-div-header {
        margin-bottom: 15px;
        .el-button {
          margin-right: 10px;
        }
      }
      
      .role-list {
        ul {
          list-style: none;
          padding: 0;
          margin: 0;
          
          li {
            padding: 8px 10px;
            cursor: pointer;
  
            text-align: left;
            
            &:hover {
              background: #f5f7fa;
            }
            
            &.active {
              background: #EAF0FE;
              color: #676a6c;
            }
          }
        }
      }
    }
    </style>