authority.vue 4.9 KB
Newer Older
1
<template>
2
  <div class="authority">
3
    <div class="button-box clearflex">
4
      <el-button @click="addAuthority('0')" type="primary">新增角色</el-button>
5
    </div>
K
klausY 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    <el-table
            :data="tableData"
            style="width: 100%"
            row-key="ID"
            border
            stripe
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column label="id" min-width="180" prop="ID"></el-table-column>
        <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>
        <el-table-column fixed="right" label="操作" width="500">
            <template slot-scope="scope">
                <el-button @click="opdendrawer(scope.row)" size="small" type="text">设置权限</el-button>
                <el-button @click="deleteAuth(scope.row)" size="small" type="text">删除角色</el-button>
                <el-button @click="addAuthority(scope.row.authorityId)" size="small" type="text">新增子角色</el-button>
            </template>
        </el-table-column>
23
    </el-table>
24

Mr.奇淼('s avatar
Mr.奇淼( 已提交
25
    <!-- 新增角色弹窗 -->
26 27
    <el-dialog :visible.sync="dialogFormVisible" title="新增角色">
      <el-form :model="form">
28 29 30
         <el-form-item label="父级角色ID">
          <el-input autocomplete="off" disabled v-model="form.parentId"></el-input>
        </el-form-item>
31 32 33 34 35 36 37 38 39 40 41 42
        <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.奇淼( 已提交
43

44 45 46 47 48 49 50 51 52 53
    <el-drawer :visible.sync="drawer" v-if="drawer" :with-header="false" size="40%" title="角色配置">
      <el-tabs class="role-box" type="border-card">
        <el-tab-pane label="角色菜单">
          <Menus :row="activeRow" />
        </el-tab-pane>
        <el-tab-pane label="角色api">
          <apis :row="activeRow" />
        </el-tab-pane>
      </el-tabs>
    </el-drawer>
54 55 56 57
  </div>
</template>

<script>
Mr.奇淼('s avatar
注释  
Mr.奇淼( 已提交
58 59
// 获取列表内容封装在mixins内部  getTableData方法 初始化已封装完成

Mr.奇淼('s avatar
Mr.奇淼( 已提交
60 61 62 63 64
import {
  getAuthorityList,
  deleteAuthority,
  createAuthority
} from '@/api/authority'
65 66 67 68

import Menus from '@/view/superAdmin/authority/components/menus'
import Apis from '@/view/superAdmin/authority/components/apis'

69
import infoList from '@/components/mixins/infoList'
70 71
export default {
  name: 'Authority',
72
  mixins: [infoList],
73 74
  data() {
    return {
75
      listApi: getAuthorityList,
76
      listKey: 'list',
77 78
      drawer: false,
      activeRow: {},
Mr.奇淼('s avatar
Mr.奇淼( 已提交
79
      activeUserId: 0,
80
      dialogFormVisible: false,
Mr.奇淼('s avatar
Mr.奇淼( 已提交
81
      apiDialogFlag: false,
Mr.奇淼('s avatar
Mr.奇淼( 已提交
82 83
      form: {
        authorityId: '',
84 85
        authorityName: '',
        parentId:'0'
86 87 88
      }
    }
  },
89 90 91 92
  components: {
    Menus,
    Apis
  },
93
  methods: {
94 95 96 97
    opdendrawer(row) {
      this.drawer = true
      this.activeRow = row
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
98
    // 删除角色
99 100 101 102 103 104 105
    deleteAuth(row) {
      this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
106
          const res = await deleteAuthority({ authorityId: row.authorityId })
Mr.奇淼('s avatar
Mr.奇淼( 已提交
107 108 109 110 111
          if (res.success) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
112
            this.getTableData()
Mr.奇淼('s avatar
Mr.奇淼( 已提交
113
          }
114 115 116 117 118 119 120 121
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
122 123 124 125 126
    // 初始化表单
    initForm() {
      for (const key in this.form) {
        this.form[key] = ''
      }
127
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
128 129 130 131
    // 关闭窗口
    closeDialog() {
      this.initForm()
      this.dialogFormVisible = false
Mr.奇淼('s avatar
Mr.奇淼( 已提交
132
      this.apiDialogFlag = false
133
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
134
    // 确定弹窗
Mr.奇淼('s avatar
Mr.奇淼( 已提交
135

Mr.奇淼('s avatar
Mr.奇淼( 已提交
136 137 138 139 140 141 142
    async enterDialog() {
      const res = await createAuthority(this.form)
      if (res.success) {
        this.$message({
          type: 'success',
          message: '添加成功!'
        })
143
        this.getTableData()
Mr.奇淼('s avatar
Mr.奇淼( 已提交
144 145 146 147
        this.closeDialog()
      }
      this.initForm()
      this.dialogFormVisible = false
148
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
149
    // 增加角色
150 151
    addAuthority(parentId) {
      this.form.parentId = parentId
Mr.奇淼('s avatar
Mr.奇淼( 已提交
152
      this.dialogFormVisible = true
153
    }
154 155 156
  },
  created(){
    this.pageSize = 999
157 158 159
  }
}
</script>
160 161 162 163 164 165 166
<style lang="scss">
.authority {
  .button-box {
    padding: 10px 20px;
    .el-button {
      float: right;
    }
167 168
  }
}
169 170 171 172 173 174
.role-box {
    .el-tabs__content {
      height: calc(100vh - 150px);
      overflow: auto;
    }
  }
175
</style>