menu-dist.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <!-- 分配菜单 -->
  3. <el-dialog title="分配菜单" :visible.sync="dialogVisible" width="50%" top="10vh" append-to-body>
  4. <el-row>
  5. <el-col>
  6. <el-button
  7. type="primary"
  8. plain
  9. icon="el-icon-plus"
  10. size="mini"
  11. :disabled="distribution"
  12. @click="distMenuAuthBtns"
  13. >
  14. 批量分配</el-button>
  15. </el-col>
  16. </el-row>
  17. <el-table ref="multipleTable" v-loading="loading" :data="addMenuAuthList" row-key="id" @selection-change="handelAddMenuAuth">
  18. <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
  19. <el-table-column label="接口名称" prop="permissionUrl" :show-overflow-tooltip="true" align="center" />
  20. <el-table-column label="备注" prop="permissionName" :show-overflow-tooltip="true" align="center" />
  21. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  22. <template slot-scope="scope">
  23. <el-button
  24. type="primary"
  25. plain
  26. icon="el-icon-circle-plus"
  27. size="mini"
  28. :disabled="!distribution"
  29. @click="distMenuAuthBtn(scope.row)"
  30. >分配菜单
  31. </el-button>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. <pagination
  36. v-show="addTotal > 0"
  37. :total="addTotal"
  38. :page.sync="allAuthQuery.page"
  39. :limit.sync="allAuthQuery.limit"
  40. @pagination="getAllAuthApi"
  41. />
  42. </el-dialog>
  43. </template>
  44. <script>
  45. import { getAllAuthApi, distMenuAuth } from '@/api/system/menu'
  46. export default {
  47. data() {
  48. return {
  49. // 所有权限接口查询参数
  50. allAuthQuery: {
  51. page: 1,
  52. limit: 10
  53. },
  54. // 分配菜单权限参数
  55. menuAuthObj: {
  56. id: null,
  57. permissionList: []
  58. },
  59. // 添加菜单权限数据
  60. addMenuAuthList: [],
  61. // 弹出框表格总数
  62. addTotal: 0,
  63. // 添加菜单权限按钮禁用
  64. distribution: true,
  65. // 开关弹框
  66. dialogVisible: false,
  67. // 加载状态
  68. loading: true
  69. }
  70. },
  71. created() {
  72. if (this.$route.params.userId) {
  73. this.menuAuthObj.id = this.$route.params.userId
  74. }
  75. },
  76. methods: {
  77. /** 查看所有权限接口 */
  78. getAllAuthApi() {
  79. getAllAuthApi(this.allAuthQuery).then(res => {
  80. const data = res.data
  81. this.addMenuAuthList = data.permissionList
  82. this.addTotal = data.count
  83. this.loading = false
  84. })
  85. },
  86. /** 添加菜单权限多选框选中数据 */
  87. handelAddMenuAuth(selection) {
  88. selection.forEach(item => {
  89. this.menuAuthObj.permissionList.push({ id: item.id })
  90. })
  91. this.menuAuthObj.permissionList = this._.uniqBy(this.menuAuthObj.permissionList, 'id')
  92. this.distribution = !selection.length
  93. },
  94. /** 分配按钮操作 */
  95. distMenuAuthBtn(row) {
  96. this.$confirm('是否分配接口权限?', '提示', {
  97. confirmButtonText: '确定',
  98. cancelButtonText: '取消',
  99. type: 'warning'
  100. }).then(() => {
  101. this.menuAuthObj.permissionList.push({ id: row.id })
  102. this.distMenuAuth()
  103. }).catch(() => {
  104. this.$message({
  105. type: 'info',
  106. message: '取消操作'
  107. })
  108. })
  109. },
  110. /** 批量分配按钮操作 */
  111. distMenuAuthBtns() {
  112. this.$confirm('是否批量分配接口权限?', '提示', {
  113. confirmButtonText: '确定',
  114. cancelButtonText: '取消',
  115. type: 'warning'
  116. }).then(() => {
  117. this.distMenuAuth()
  118. }).catch(() => {
  119. this.$message({
  120. type: 'info',
  121. message: '取消操作'
  122. })
  123. })
  124. },
  125. /** 分配菜单权限接口 */
  126. distMenuAuth() {
  127. distMenuAuth(this.menuAuthObj).then(res => {
  128. if (res.code === 200) {
  129. this.$message({
  130. type: 'success',
  131. message: '已分配权限'
  132. })
  133. this.$emit('handelUpdate')
  134. }
  135. })
  136. },
  137. /** 显示弹框 */
  138. show() {
  139. this.allAuthQuery.page = 1
  140. this.menuAuthObj.permissionList = []
  141. this.getAllAuthApi()
  142. this.dialogVisible = true
  143. this.$nextTick(() => {
  144. this.$refs.multipleTable.clearSelection()
  145. })
  146. }
  147. }
  148. }
  149. </script>