181 lines
4.5 KiB
Vue
Raw Normal View History

2022-08-02 10:16:07 +08:00
<template>
2022-08-02 20:19:15 +08:00
<div class="conent">
2022-08-06 20:03:35 +08:00
<!-- 新增按钮 -->
2022-08-02 20:19:15 +08:00
<div class="btn">
2022-08-06 20:03:35 +08:00
<el-button type="primary" @click="dialogVisible2 = true">新增</el-button>
2022-08-02 20:19:15 +08:00
</div>
2022-08-02 10:16:07 +08:00
2022-08-06 20:03:35 +08:00
<!-- 点击新增弹出表单 -->
<div class="from">
<el-dialog title="新增角色" :visible.sync="dialogVisible2" width="30%">
<div>
<el-form label-width="80px">
<el-form-item label="角色名称">
<el-input v-model="newrole"></el-input>
</el-form-item>
<div class="from-btn">
<el-button type="danger" @click="dialogVisible2 = false"
>取消</el-button
>
<el-button @click="onSubmit">确认</el-button>
</div>
</el-form>
</div>
</el-dialog>
</div>
<!-- 角色表单 -->
2022-08-02 20:19:15 +08:00
<div class="table">
<el-table :data="tableList" style="width: 100%">
2022-08-06 20:03:35 +08:00
<el-table-column prop="id" label="ID"> </el-table-column>
<el-table-column prop="name" label="角色名称"> </el-table-column>
2022-08-12 18:26:27 +08:00
<el-table-column label="权限内容">
<template slot-scope="scope">
{{ scope.row.permissions.join(",") }}
</template>
</el-table-column>
2022-08-02 20:19:15 +08:00
<el-table-column label="操作">
2022-08-06 20:03:35 +08:00
<template slot-scope="scope">
<el-button @click="onEdit(scope.row)">编辑</el-button>
</template>
2022-08-02 20:19:15 +08:00
</el-table-column>
</el-table>
</div>
2022-08-06 20:03:35 +08:00
<!-- 点击编辑弹出权限框 -->
<el-dialog title="编辑权限" :visible.sync="dialogVisible" width="30%">
<el-tree
:data="Role_Permission"
show-checkbox
:default-expand-all="false"
node-key="id"
ref="tree"
highlight-current
:props="defaultProps"
v-model="permissionIds"
>
</el-tree>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="getCheckedKeys"> </el-button>
</span>
</el-dialog>
2022-08-02 10:16:07 +08:00
</div>
</template>
<script>
2022-08-12 18:26:27 +08:00
import {
roleList,
roleAdd,
jurisdiction,
jurisdictionEdit,
} from "../../api/role.js";
2022-08-02 10:16:07 +08:00
export default {
data() {
2022-08-02 20:19:15 +08:00
return {
2022-08-06 20:03:35 +08:00
id: "", //点击角色的id
2022-08-02 20:19:15 +08:00
tableList: [], //列表数据
2022-08-06 20:03:35 +08:00
newrole: "", //添加角色框input
dialogVisible: false, //编辑按钮打开表单变量
dialogVisible2: false, //新增按钮打开表单变量
permissionIds: [], //复选框选中权限的ID
allpermissionIds: {}, //id数组添加进对象
Role_Permission: [], //权限列表数据
defaultProps: {
children: "children",
label: "name",
},
2022-08-02 20:19:15 +08:00
};
2022-08-02 10:16:07 +08:00
},
2022-08-02 20:19:15 +08:00
mounted() {
2022-08-06 20:03:35 +08:00
this.getroleList();
},
methods: {
2022-08-02 20:19:15 +08:00
//角色表单数据请求
2022-08-06 20:03:35 +08:00
getroleList() {
2022-08-12 18:26:27 +08:00
this.getJurisdiction();
roleList().then((res) => {
console.log(res);
this.tableList = res.data.data;
});
2022-08-06 20:03:35 +08:00
},
2022-08-12 18:26:27 +08:00
//角色权限数据请求
2022-08-06 20:03:35 +08:00
getJurisdiction() {
2022-08-12 18:26:27 +08:00
jurisdiction().then((res) => {
this.Role_Permission = res.data.data;
});
2022-08-06 20:03:35 +08:00
},
// 点击新增
onSubmit() {
let roleName = {
name: this.newrole,
};
2022-08-12 18:26:27 +08:00
roleAdd(roleName).then((res) => {
this.dialogVisible2 = false;
this.getroleList();
if (res.status == 201) {
this.$message({
message: "角色添加成功!",
type: "success",
});
}
});
2022-08-06 20:03:35 +08:00
},
// 点击编辑
onEdit(row) {
this.dialogVisible = true;
this.id = row.id;
},
//编辑权限确认
getCheckedKeys() {
let id = this.id; //选中角色的ID
this.permissionIds = this.$refs.tree.getCheckedKeys(); //选中权限的ID
this.allpermissionIds = {
permissionIds: this.permissionIds,
};
2022-08-12 18:26:27 +08:00
jurisdictionEdit(id, this.allpermissionIds).then((res) => {
if (res.status === 200) {
this.dialogVisible = false;
this.getroleList();
this.$message({
message: "权限修改成功!",
type: "success",
});
}
});
2022-08-06 20:03:35 +08:00
},
2022-08-02 20:19:15 +08:00
},
};
2022-08-02 10:16:07 +08:00
</script>
<style lang="scss" scoped>
2022-08-02 20:19:15 +08:00
.conent {
width: 100%;
min-height: calc(100vh - 200px);
}
.btn {
height: 104px;
border-radius: 5px;
display: flex;
align-items: center;
.el-button {
width: 114px;
height: 44px;
border-radius: 3px;
}
}
.table {
margin-top: 20px;
}
2022-08-06 20:03:35 +08:00
.from-btn {
display: flex;
justify-content: space-around;
align-content: center;
}
2022-08-02 10:16:07 +08:00
</style>