mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
158 lines
5.4 KiB
Vue
158 lines
5.4 KiB
Vue
<template>
|
|
<div class="pageBox">
|
|
<el-card>
|
|
<div class="opaBox">
|
|
<el-button type="primary" icon="el-icon-plus" @click="dialogVisible2 = true">新增</el-button>
|
|
</div>
|
|
<el-table v-loading="loading" :data="tableList" style="width: 100%" border>
|
|
<el-table-column prop="id" label="ID"> </el-table-column>
|
|
<el-table-column prop="name" label="角色名称"> </el-table-column>
|
|
<el-table-column label="权限内容">
|
|
<template slot-scope="scope">
|
|
<span v-for="item in scope.row.permissions" :key="item.id">{{ item.name }} </span>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="操作">
|
|
<template slot-scope="scope">
|
|
<el-button type="primary" @click="onEdit(scope.row)" icon="el-icon-edit">编辑权限</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</el-card>
|
|
|
|
<!-- 点击编辑弹出权限框 -->
|
|
<el-dialog title="编辑权限" :visible.sync="dialogVisible" width="30%" :close-on-click-modal="false">
|
|
<el-tree v-if="isShowtree" :data="Role_Permission" show-checkbox :default-expand-all="false" node-key="id"
|
|
ref="tree" highlight-current :props="defaultProps" :default-checked-keys="chekedKeys"
|
|
v-model="permissionIds">
|
|
</el-tree>
|
|
<span slot="footer" class="dialog-footer">
|
|
<el-button @click="cancel()">取 消</el-button>
|
|
<el-button type="primary" @click="getCheckedKeys()">确 定</el-button>
|
|
</span>
|
|
</el-dialog>
|
|
|
|
<el-dialog title="新增角色" :visible.sync="dialogVisible2" width="30%" :close-on-click-modal="false">
|
|
<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 @click="dialogVisible2 = false">取消</el-button>
|
|
<el-button type="primary" @click="onSubmit">确认</el-button>
|
|
</div>
|
|
</el-form>
|
|
</div>
|
|
</el-dialog>
|
|
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { roleList, roleAdd, jurisdiction, jurisdictionEdit } from "@/api/role.js"
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
id: "", //点击角色的id
|
|
loading: true,
|
|
tableList: [], //列表数据
|
|
rolePermissions: [],
|
|
newrole: "", //添加角色框input
|
|
dialogVisible: false, //编辑按钮打开表单变量
|
|
dialogVisible2: false, //新增按钮打开表单变量
|
|
permissionIds: [], //复选框选中权限的ID
|
|
allpermissionIds: {}, //id数组添加进对象
|
|
Role_Permission: [], //权限列表数据
|
|
defaultProps: {
|
|
children: "children",
|
|
label: "name",
|
|
},
|
|
isShowtree: false,
|
|
chekedKeys: [],
|
|
};
|
|
},
|
|
|
|
mounted() {
|
|
this.getroleList();
|
|
this.getJurisdiction();
|
|
},
|
|
methods: {
|
|
//角色表单数据请求
|
|
getroleList() {
|
|
roleList().then((res) => {
|
|
this.tableList = res.data.data;
|
|
});
|
|
this.loading = false;
|
|
},
|
|
|
|
//角色权限数据请求
|
|
getJurisdiction() {
|
|
jurisdiction().then((res) => {
|
|
this.Role_Permission = res.data.data;
|
|
});
|
|
},
|
|
|
|
// 点击新增
|
|
onSubmit() {
|
|
let roleName = {
|
|
name: this.newrole,
|
|
};
|
|
roleAdd(roleName).then((res) => {
|
|
this.dialogVisible2 = false;
|
|
this.getroleList();
|
|
if (res.status == 201) {
|
|
this.$message({
|
|
message: "角色添加成功!",
|
|
type: "success",
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
// 点击编辑
|
|
onEdit(row) {
|
|
this.id = row.id;
|
|
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;
|
|
},
|
|
|
|
//编辑权限确认
|
|
getCheckedKeys() {
|
|
let id = this.id; //选中角色的ID
|
|
this.permissionIds = this.$refs.tree.getCheckedKeys(); //选中权限的ID
|
|
this.allpermissionIds = {
|
|
permissionIds: this.permissionIds,
|
|
};
|
|
jurisdictionEdit(id, this.allpermissionIds).then((res) => {
|
|
if (res.status === 200) {
|
|
this.dialogVisible = false;
|
|
this.getroleList();
|
|
this.$message({
|
|
message: "权限修改成功!",
|
|
type: "success",
|
|
});
|
|
}
|
|
});
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.opaBox{
|
|
margin-bottom: 15px;
|
|
}
|
|
</style>
|