menu-dist.vue 4.6 KB

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