123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <template>
- <!-- 分配菜单 -->
- <el-dialog title="分配菜单" :visible.sync="dialogVisible" width="50%" top="10vh" append-to-body>
- <el-row>
- <el-col>
- <el-button
- type="primary"
- plain
- icon="el-icon-plus"
- size="mini"
- :disabled="distribution"
- @click="distMenuAuthBtns"
- >
- 批量分配</el-button>
- </el-col>
- </el-row>
- <el-table ref="multipleTable" v-loading="loading" :data="addMenuAuthList" row-key="id" @selection-change="handelAddMenuAuth">
- <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
- <el-table-column label="接口名称" prop="permissionUrl" :show-overflow-tooltip="true" align="center" />
- <el-table-column label="备注" prop="permissionName" :show-overflow-tooltip="true" align="center" />
- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
- <template slot-scope="scope">
- <el-button
- type="primary"
- plain
- icon="el-icon-circle-plus"
- size="mini"
- :disabled="!distribution"
- @click="distMenuAuthBtn(scope.row)"
- >分配菜单
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <pagination
- v-show="addTotal > 0"
- :total="addTotal"
- :page.sync="allAuthQuery.page"
- :limit.sync="allAuthQuery.limit"
- @pagination="getAllAuthApi"
- />
- </el-dialog>
- </template>
- <script>
- import { getAllAuthApi, distMenuAuth } from '@/api/system/menu'
- export default {
- data() {
- return {
- // 所有权限接口查询参数
- allAuthQuery: {
- page: 1,
- limit: 10
- },
- // 分配菜单权限参数
- menuAuthObj: {
- id: null,
- permissionList: []
- },
- // 添加菜单权限数据
- addMenuAuthList: [],
- // 弹出框表格总数
- addTotal: 0,
- // 添加菜单权限按钮禁用
- distribution: true,
- // 开关弹框
- dialogVisible: false,
- // 加载状态
- loading: true
- }
- },
- created() {
- if (this.$route.params.userId) {
- this.menuAuthObj.id = this.$route.params.userId
- }
- },
- methods: {
- /** 查看所有权限接口 */
- getAllAuthApi() {
- getAllAuthApi(this.allAuthQuery).then(res => {
- const data = res.data
- this.addMenuAuthList = data.permissionList
- this.addTotal = data.count
- this.loading = false
- })
- },
- /** 添加菜单权限多选框选中数据 */
- handelAddMenuAuth(selection) {
- selection.forEach(item => {
- this.menuAuthObj.permissionList.push({ id: item.id })
- })
- this.menuAuthObj.permissionList = this._.uniqBy(this.menuAuthObj.permissionList, 'id')
- this.distribution = !selection.length
- },
- /** 分配按钮操作 */
- distMenuAuthBtn(row) {
- this.$confirm('是否分配接口权限?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.menuAuthObj.permissionList.push({ id: row.id })
- this.distMenuAuth()
- }).catch(() => {
- this.$message({
- type: 'info',
- message: '取消操作'
- })
- })
- },
- /** 批量分配按钮操作 */
- distMenuAuthBtns() {
- this.$confirm('是否批量分配接口权限?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.distMenuAuth()
- }).catch(() => {
- this.$message({
- type: 'info',
- message: '取消操作'
- })
- })
- },
- /** 分配菜单权限接口 */
- distMenuAuth() {
- distMenuAuth(this.menuAuthObj).then(res => {
- if (res.code === 200) {
- this.$message({
- type: 'success',
- message: '已分配权限'
- })
- this.$emit('handelUpdate')
- }
- })
- },
- /** 显示弹框 */
- show() {
- this.allAuthQuery.page = 1
- this.menuAuthObj.permissionList = []
- this.getAllAuthApi()
- this.dialogVisible = true
- this.$nextTick(() => {
- this.$refs.multipleTable.clearSelection()
- })
- }
- }
- }
- </script>
|