authority.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="authority">
  3. <div class="button-box clearflex">
  4. <el-button @click="addAuthority('0')" type="primary">新增角色</el-button>
  5. </div>
  6. <el-table
  7. :data="tableData"
  8. style="width: 100%"
  9. row-key="ID"
  10. border
  11. stripe
  12. :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  13. <el-table-column label="id" min-width="180" prop="ID"></el-table-column>
  14. <el-table-column label="角色id" min-width="180" prop="authorityId"></el-table-column>
  15. <el-table-column label="角色名称" min-width="180" prop="authorityName"></el-table-column>
  16. <el-table-column fixed="right" label="操作" width="500">
  17. <template slot-scope="scope">
  18. <el-button @click="opdendrawer(scope.row)" size="small" type="text">设置权限</el-button>
  19. <el-button @click="deleteAuth(scope.row)" size="small" type="text">删除角色</el-button>
  20. <el-button @click="addAuthority(scope.row.authorityId)" size="small" type="text">新增子角色</el-button>
  21. </template>
  22. </el-table-column>
  23. </el-table>
  24. <!-- 新增角色弹窗 -->
  25. <el-dialog :visible.sync="dialogFormVisible" title="新增角色">
  26. <el-form :model="form">
  27. <el-form-item label="父级角色ID">
  28. <el-input autocomplete="off" disabled v-model="form.parentId"></el-input>
  29. </el-form-item>
  30. <el-form-item label="角色ID">
  31. <el-input autocomplete="off" v-model="form.authorityId"></el-input>
  32. </el-form-item>
  33. <el-form-item label="角色姓名">
  34. <el-input autocomplete="off" v-model="form.authorityName"></el-input>
  35. </el-form-item>
  36. </el-form>
  37. <div class="dialog-footer" slot="footer">
  38. <el-button @click="closeDialog">取 消</el-button>
  39. <el-button @click="enterDialog" type="primary">确 定</el-button>
  40. </div>
  41. </el-dialog>
  42. <el-drawer :visible.sync="drawer" v-if="drawer" :with-header="false" size="40%" title="角色配置">
  43. <el-tabs class="role-box" type="border-card">
  44. <el-tab-pane label="角色菜单">
  45. <Menus :row="activeRow" />
  46. </el-tab-pane>
  47. <el-tab-pane label="角色api">
  48. <apis :row="activeRow" />
  49. </el-tab-pane>
  50. </el-tabs>
  51. </el-drawer>
  52. </div>
  53. </template>
  54. <script>
  55. // 获取列表内容封装在mixins内部 getTableData方法 初始化已封装完成
  56. import {
  57. getAuthorityList,
  58. deleteAuthority,
  59. createAuthority
  60. } from '@/api/authority'
  61. import Menus from '@/view/superAdmin/authority/components/menus'
  62. import Apis from '@/view/superAdmin/authority/components/apis'
  63. import infoList from '@/components/mixins/infoList'
  64. export default {
  65. name: 'Authority',
  66. mixins: [infoList],
  67. data() {
  68. return {
  69. listApi: getAuthorityList,
  70. listKey: 'list',
  71. drawer: false,
  72. activeRow: {},
  73. activeUserId: 0,
  74. dialogFormVisible: false,
  75. apiDialogFlag: false,
  76. form: {
  77. authorityId: '',
  78. authorityName: '',
  79. parentId:'0'
  80. }
  81. }
  82. },
  83. components: {
  84. Menus,
  85. Apis
  86. },
  87. methods: {
  88. opdendrawer(row) {
  89. this.drawer = true
  90. this.activeRow = row
  91. },
  92. // 删除角色
  93. deleteAuth(row) {
  94. this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', {
  95. confirmButtonText: '确定',
  96. cancelButtonText: '取消',
  97. type: 'warning'
  98. })
  99. .then(async () => {
  100. const res = await deleteAuthority({ authorityId: row.authorityId })
  101. if (res.success) {
  102. this.$message({
  103. type: 'success',
  104. message: '删除成功!'
  105. })
  106. this.getTableData()
  107. }
  108. })
  109. .catch(() => {
  110. this.$message({
  111. type: 'info',
  112. message: '已取消删除'
  113. })
  114. })
  115. },
  116. // 初始化表单
  117. initForm() {
  118. for (const key in this.form) {
  119. this.form[key] = ''
  120. }
  121. },
  122. // 关闭窗口
  123. closeDialog() {
  124. this.initForm()
  125. this.dialogFormVisible = false
  126. this.apiDialogFlag = false
  127. },
  128. // 确定弹窗
  129. async enterDialog() {
  130. const res = await createAuthority(this.form)
  131. if (res.success) {
  132. this.$message({
  133. type: 'success',
  134. message: '添加成功!'
  135. })
  136. this.getTableData()
  137. this.closeDialog()
  138. }
  139. this.initForm()
  140. this.dialogFormVisible = false
  141. },
  142. // 增加角色
  143. addAuthority(parentId) {
  144. this.form.parentId = parentId
  145. this.dialogFormVisible = true
  146. }
  147. },
  148. created(){
  149. this.pageSize = 999
  150. }
  151. }
  152. </script>
  153. <style lang="scss">
  154. .authority {
  155. .button-box {
  156. padding: 10px 20px;
  157. .el-button {
  158. float: right;
  159. }
  160. }
  161. }
  162. .role-box {
  163. .el-tabs__content {
  164. height: calc(100vh - 150px);
  165. overflow: auto;
  166. }
  167. }
  168. </style>