“837a78db2e550a690cc4804675f999c9c1928839”上不存在“app/views/groups/merge_requests.html.haml”
authority.vue 5.4 KB
Newer Older
1 2 3 4 5 6 7 8
<template>
  <div>
    <div class="button-box clearflex">
      <el-button @click="addAuthority" type="primary">新增角色</el-button>
    </div>
    <el-table :data="tableData" border stripe>
      <el-table-column label="角色id" min-width="180" prop="authorityId"></el-table-column>
      <el-table-column label="角色名称" min-width="180" prop="authorityName"></el-table-column>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
9
      <el-table-column fixed="right" label="操作" width="500">
10
        <template slot-scope="scope">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
11
          <el-button @click="addAuthMenu(scope.row)" size="small" type="text">增加角色菜单</el-button>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
          <el-button @click="deleteAuth(scope.row)" size="small" type="text">删除角色</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="page"
      :page-size="pageSize"
      :page-sizes="[10, 30, 50, 100]"
      :style="{float:'right',padding:'20px'}"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      hide-on-single-page
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
27
    <!-- 新增角色弹窗 -->
28 29 30 31 32 33 34 35 36 37 38 39 40 41
    <el-dialog :visible.sync="dialogFormVisible" title="新增角色">
      <el-form :model="form">
        <el-form-item label="角色ID">
          <el-input autocomplete="off" v-model="form.authorityId"></el-input>
        </el-form-item>
        <el-form-item label="角色姓名">
          <el-input autocomplete="off" v-model="form.authorityName"></el-input>
        </el-form-item>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button @click="enterDialog" type="primary">确 定</el-button>
      </div>
    </el-dialog>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
42 43 44 45 46

    <!-- 关联menu弹窗 -->
    <el-dialog :visible.sync="menuDialogFlag" title="关联菜单">
      <el-tree
        :data="treeData"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
47
        :default-checked-keys="treeIds"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
48 49 50 51 52 53 54 55 56 57 58 59
        :props="defaultProps"
        default-expand-all
        highlight-current
        node-key="ID"
        ref="tree"
        show-checkbox
      ></el-tree>
      <div class="dialog-footer" slot="footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button @click="relation" type="primary">确 定</el-button>
      </div>
    </el-dialog>
60 61 62 63
  </div>
</template>

<script>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
64 65 66 67 68 69
import {
  getAuthorityList,
  deleteAuthority,
  createAuthority
} from '@/api/authority'
import { getBaseMenuTree, addMenuAuthority, getMenuAuthority } from '@/api/menu'
70
import infoList from '@/view/superAdmin/mixins/infoList'
71 72
export default {
  name: 'Authority',
73
  mixins:[infoList],
74 75
  data() {
    return {
76 77
      listApi: getAuthorityList,
      listKey:'list',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
78 79
      activeUserId: 0,
      treeData: [],
Mr.奇淼('s avatar
Mr.奇淼( 已提交
80
      treeIds: [],
Mr.奇淼('s avatar
Mr.奇淼( 已提交
81 82 83 84
      defaultProps: {
        children: 'children',
        label: 'nickName'
      },
85
      dialogFormVisible: false,
Mr.奇淼('s avatar
Mr.奇淼( 已提交
86 87 88 89
      menuDialogFlag: false,
      form: {
        authorityId: '',
        authorityName: ''
90 91 92 93
      }
    }
  },
  methods: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
94
    // 删除角色
95 96 97 98 99 100 101
    deleteAuth(row) {
      this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
102
          const res = await deleteAuthority({ authorityId: row.authorityId })
Mr.奇淼('s avatar
Mr.奇淼( 已提交
103 104 105 106 107
          if (res.success) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
108
            this.getTableData()
Mr.奇淼('s avatar
Mr.奇淼( 已提交
109
          }
110 111 112 113 114 115 116 117
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
118 119 120 121 122
    // 初始化表单
    initForm() {
      for (const key in this.form) {
        this.form[key] = ''
      }
123
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
124 125 126 127 128
    // 关闭窗口
    closeDialog() {
      this.initForm()
      this.dialogFormVisible = false
      this.menuDialogFlag = false
129
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
130 131 132 133 134 135 136 137
    // 确定弹窗
    async enterDialog() {
      const res = await createAuthority(this.form)
      if (res.success) {
        this.$message({
          type: 'success',
          message: '添加成功!'
        })
138
        this.getTableData()
Mr.奇淼('s avatar
Mr.奇淼( 已提交
139 140 141 142
        this.closeDialog()
      }
      this.initForm()
      this.dialogFormVisible = false
143
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
144
    // 增加角色
145
    addAuthority() {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
146
      this.dialogFormVisible = true
147
    },
148
    
Mr.奇淼('s avatar
Mr.奇淼( 已提交
149
    // 关联用户列表关系
Mr.奇淼('s avatar
Mr.奇淼( 已提交
150
    async addAuthMenu(row) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
151
      const res1 = await getMenuAuthority({ authorityId: row.authorityId })
Mr.奇淼('s avatar
Mr.奇淼( 已提交
152 153
      const menus = res1.data.menus
      const arr = []
Mr.奇淼('s avatar
Mr.奇淼( 已提交
154 155 156
      menus.map(item => {
        arr.push(Number(item.menuId))
      })
Mr.奇淼('s avatar
Mr.奇淼( 已提交
157 158 159 160 161 162
      this.treeIds = arr
      const res2 = await getBaseMenuTree()
      this.treeData = res2.data.menus
      this.activeUserId = row.authorityId
      this.menuDialogFlag = true
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
163
    // 关联树 确认方法
Mr.奇淼('s avatar
Mr.奇淼( 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    async relation() {
      const checkArr = this.$refs.tree
        .getCheckedNodes()
        .concat(this.$refs.tree.getHalfCheckedNodes())
      const res = await addMenuAuthority({
        menus: checkArr,
        authorityId: this.activeUserId
      })
      if (res.success) {
        this.$message({
          type: 'success',
          message: '添加成功!'
        })
      }
      this.closeDialog()
179
    }
Mr.奇淼('s avatar
Mr.奇淼( 已提交
180
    // 获取基础menu树
181 182
  },
  created() {
183
    this.getTableData()
184 185 186
  }
}
</script>
187
<style scoped lang="scss">
188 189 190 191 192 193 194
.button-box {
  padding: 10px 20px;
  .el-button {
    float: right;
  }
}
</style>