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">
|
2022-08-15 19:55:44 +08:00
|
|
|
<el-dialog
|
|
|
|
|
title="新增角色"
|
|
|
|
|
:visible.sync="dialogVisible2"
|
|
|
|
|
width="30%"
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
>
|
2022-08-06 20:03:35 +08:00
|
|
|
<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">
|
2022-08-15 19:55:44 +08:00
|
|
|
<span v-for="item in scope.row.permissions" :key="item.id"
|
|
|
|
|
>{{ item.name }} </span
|
|
|
|
|
>
|
2022-08-12 18:26:27 +08:00
|
|
|
</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
|
|
|
|
|
|
|
|
<!-- 点击编辑弹出权限框 -->
|
2022-08-15 19:55:44 +08:00
|
|
|
<el-dialog
|
|
|
|
|
title="编辑权限"
|
|
|
|
|
:visible.sync="dialogVisible"
|
|
|
|
|
width="30%"
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
>
|
2022-08-06 20:03:35 +08:00
|
|
|
<el-tree
|
2022-08-15 19:55:44 +08:00
|
|
|
v-if="isShowtree"
|
2022-08-06 20:03:35 +08:00
|
|
|
:data="Role_Permission"
|
|
|
|
|
show-checkbox
|
|
|
|
|
:default-expand-all="false"
|
|
|
|
|
node-key="id"
|
|
|
|
|
ref="tree"
|
|
|
|
|
highlight-current
|
|
|
|
|
:props="defaultProps"
|
2022-08-15 19:55:44 +08:00
|
|
|
:default-checked-keys="chekedKeys"
|
2022-08-06 20:03:35 +08:00
|
|
|
v-model="permissionIds"
|
|
|
|
|
>
|
|
|
|
|
</el-tree>
|
|
|
|
|
<span slot="footer" class="dialog-footer">
|
2022-08-15 19:55:44 +08:00
|
|
|
<el-button @click="cancel()">取 消</el-button>
|
|
|
|
|
<el-button type="primary" @click="getCheckedKeys()">确 定</el-button>
|
2022-08-06 20:03:35 +08:00
|
|
|
</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-15 19:55:44 +08:00
|
|
|
rolePermissions: [],
|
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-15 19:55:44 +08:00
|
|
|
isShowtree: false,
|
|
|
|
|
chekedKeys: [],
|
2022-08-02 20:19:15 +08:00
|
|
|
};
|
2022-08-02 10:16:07 +08:00
|
|
|
},
|
2022-08-15 19:55:44 +08:00
|
|
|
|
2022-08-02 20:19:15 +08:00
|
|
|
mounted() {
|
2022-08-06 20:03:35 +08:00
|
|
|
this.getroleList();
|
2022-08-15 19:55:44 +08:00
|
|
|
this.getJurisdiction();
|
2022-08-06 20:03:35 +08:00
|
|
|
},
|
|
|
|
|
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
|
|
|
roleList().then((res) => {
|
|
|
|
|
this.tableList = res.data.data;
|
2022-08-15 19:55:44 +08:00
|
|
|
console.log("我是角色权限", this.tableList);
|
2022-08-12 18:26:27 +08:00
|
|
|
});
|
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-15 19:55:44 +08:00
|
|
|
console.log("我是所有权限", this.Role_Permission);
|
2022-08-12 18:26:27 +08:00
|
|
|
});
|
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.id = row.id;
|
2022-08-15 19:55:44 +08:00
|
|
|
console.log(row);
|
|
|
|
|
let arr = row.permissions.map((item) => {
|
|
|
|
|
return item.id;
|
|
|
|
|
});
|
|
|
|
|
this.chekedKeys = arr;
|
|
|
|
|
this.dialogVisible = true;
|
|
|
|
|
this.isShowtree = true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 点击取消
|
|
|
|
|
cancel() {
|
|
|
|
|
this.dialogVisible = false;
|
|
|
|
|
this.isShowtree = false;
|
2022-08-06 20:03:35 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//编辑权限确认
|
|
|
|
|
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>
|