AuthManage.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div id="AuthManageContainer">
  3. <h3>角色权限管理</h3>
  4. <el-divider />
  5. <el-card class="box-card" style="width: 35%; display: inline-block;vertical-align: top">
  6. <template #header>
  7. <div class="card-header">
  8. <span style="font-weight: bold">角色列表</span>
  9. </div>
  10. </template>
  11. <div v-for="role in roleList" :key="role.id" class="roleItem" :style="currRole.id===role.id?checkRoleStyle:''" @click="handleRoleSelect(role)">{{ role.noteStr }}</div>
  12. </el-card>
  13. <div class="authDetails" v-show="currRole.id">
  14. <h4 style="display: inline-block;padding-top: 3px">权限管理</h4>
  15. <el-button type="default" title="保存" @click="submit" style="display: inline-block;font-size: 15px;float: right">
  16. <el-icon><IconPark-save /></el-icon>
  17. </el-button>
  18. <el-divider />
  19. <el-tree v-loading="authLoading" ref="authTree" :data="authData" :props="authDataProps" node-key="id" show-checkbox />
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import api from "@/api/data/AuthInfo";
  25. export default {
  26. data() {
  27. return {
  28. roleList: [],
  29. authData: [],
  30. authDataProps: {
  31. children: 'children',
  32. label: 'name',
  33. },
  34. currRole: {},
  35. checkRoleStyle: {
  36. background: 'rgba(101,102,244,0.7)',
  37. color: 'white',
  38. },
  39. currCheckedAuth: [],
  40. authLoading: false
  41. }
  42. },
  43. created() {
  44. this.getRoleList();
  45. this.getAuthList();
  46. },
  47. mounted() {
  48. },
  49. methods: {
  50. getRoleList() {
  51. let app = this;
  52. let params = {
  53. serviceId: this.$constant.serviceId,
  54. }
  55. api.getRoleList(params).then(res=>{
  56. if (res.code===200) {
  57. app.roleList = []
  58. res.content.list.forEach(item => {
  59. if (item.id>1) {
  60. app.roleList.push(item)
  61. }
  62. })
  63. }
  64. })
  65. },
  66. handleRoleSelect(role) {
  67. let app = this;
  68. this.authLoading = true;
  69. this.currRole = role;
  70. this.$refs.authTree.setCheckedKeys([]);
  71. if (role.permissionId) {
  72. this.$refs.authTree.setCheckedKeys(role.permissionId.split(','))
  73. }
  74. setTimeout(function () {
  75. app.authLoading = false
  76. },300)
  77. },
  78. getAuthList() {
  79. let app = this;
  80. let params = {
  81. serviceId: this.$constant.serviceId,
  82. type: app.$constant.authType,
  83. }
  84. api.getAuthList(params).then(res=>{
  85. if (res.code===200) {
  86. app.authData = res.content
  87. }
  88. })
  89. },
  90. submit() {
  91. let app = this;
  92. let params = {
  93. serviceId: this.$constant.serviceId,
  94. type: app.$constant.authType,
  95. roleId: this.currRole.id,
  96. permissionId: this.$refs.authTree.getCheckedKeys().join(','),
  97. }
  98. app.$util.loading.handleLoading(true);
  99. api.updateRoleAuth(params).then(res=>{
  100. if (res.code===200) {
  101. app.$message({ message: '保存成功', type: 'success' });
  102. app.getRoleList()
  103. app.$util.loading.handleLoading(false);
  104. }
  105. })
  106. },
  107. }
  108. }
  109. </script>
  110. <style scoped>
  111. #AuthManageContainer {
  112. width: 100%;
  113. height: 100%;
  114. padding-left: 2%;
  115. }
  116. .roleItem {
  117. padding: 5px 15px;
  118. cursor: pointer;
  119. border-radius: 12px;
  120. margin-bottom: 5px;
  121. }
  122. .roleItem:hover {
  123. background-color: rgba(100,90,200,0.1);
  124. }
  125. .authDetails {
  126. width: 45%;
  127. margin-left: 2%;
  128. padding: 1%;
  129. padding-left: 3%;
  130. border: 1px solid #e4e7ed;
  131. box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
  132. border-radius: 3px;
  133. height: 60%;
  134. display: inline-block;
  135. }
  136. </style>