|
@ -6,8 +6,9 @@ |
|
|
<el-table :data="tableData" border stripe> |
|
|
<el-table :data="tableData" border stripe> |
|
|
<el-table-column label="角色id" min-width="180" prop="authorityId"></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 label="角色名称" min-width="180" prop="authorityName"></el-table-column> |
|
|
<el-table-column fixed="right" label="操作" width="100"> |
|
|
|
|
|
|
|
|
<el-table-column fixed="right" label="操作" width="500"> |
|
|
<template slot-scope="scope"> |
|
|
<template slot-scope="scope"> |
|
|
|
|
|
<el-button @click="addAuthMenu(scope.row)" size="small" type="text">增加角色菜单</el-button> |
|
|
<el-button @click="deleteAuth(scope.row)" size="small" type="text">删除角色</el-button> |
|
|
<el-button @click="deleteAuth(scope.row)" size="small" type="text">删除角色</el-button> |
|
|
</template> |
|
|
</template> |
|
|
</el-table-column> |
|
|
</el-table-column> |
|
@ -23,7 +24,7 @@ |
|
|
hide-on-single-page |
|
|
hide-on-single-page |
|
|
layout="total, sizes, prev, pager, next, jumper" |
|
|
layout="total, sizes, prev, pager, next, jumper" |
|
|
></el-pagination> |
|
|
></el-pagination> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 新增角色弹窗 --> |
|
|
<el-dialog :visible.sync="dialogFormVisible" title="新增角色"> |
|
|
<el-dialog :visible.sync="dialogFormVisible" title="新增角色"> |
|
|
<el-form :model="form"> |
|
|
<el-form :model="form"> |
|
|
<el-form-item label="角色ID"> |
|
|
<el-form-item label="角色ID"> |
|
@ -38,35 +39,69 @@ |
|
|
<el-button @click="enterDialog" type="primary">确 定</el-button> |
|
|
<el-button @click="enterDialog" type="primary">确 定</el-button> |
|
|
</div> |
|
|
</div> |
|
|
</el-dialog> |
|
|
</el-dialog> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 关联menu弹窗 --> |
|
|
|
|
|
<el-dialog :visible.sync="menuDialogFlag" title="关联菜单"> |
|
|
|
|
|
<el-tree |
|
|
|
|
|
:data="treeData" |
|
|
|
|
|
:props="defaultProps" |
|
|
|
|
|
default-expand-all |
|
|
|
|
|
highlight-current |
|
|
|
|
|
node-key="ID" |
|
|
|
|
|
:default-checked-keys="treeIds" |
|
|
|
|
|
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> |
|
|
</div> |
|
|
</div> |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script> |
|
|
<script> |
|
|
import { getAuthorityList, deleteAuthority, createAuthority } from '@/api/authority' |
|
|
|
|
|
|
|
|
import { |
|
|
|
|
|
getAuthorityList, |
|
|
|
|
|
deleteAuthority, |
|
|
|
|
|
createAuthority |
|
|
|
|
|
} from '@/api/authority' |
|
|
|
|
|
import { getBaseMenuTree, addMenuAuthority, getMenuAuthority } from '@/api/menu' |
|
|
export default { |
|
|
export default { |
|
|
name: 'Authority', |
|
|
name: 'Authority', |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
|
|
|
activeUserId: 0, |
|
|
page: 1, |
|
|
page: 1, |
|
|
total: 10, |
|
|
total: 10, |
|
|
pageSize: 10, |
|
|
pageSize: 10, |
|
|
tableData: [], |
|
|
tableData: [], |
|
|
|
|
|
treeData: [], |
|
|
|
|
|
treeIds:[], |
|
|
|
|
|
defaultProps: { |
|
|
|
|
|
children: 'children', |
|
|
|
|
|
label: 'nickName' |
|
|
|
|
|
}, |
|
|
dialogFormVisible: false, |
|
|
dialogFormVisible: false, |
|
|
form:{ |
|
|
|
|
|
authorityId:"", |
|
|
|
|
|
authorityName:"" |
|
|
|
|
|
|
|
|
menuDialogFlag: false, |
|
|
|
|
|
form: { |
|
|
|
|
|
authorityId: '', |
|
|
|
|
|
authorityName: '' |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
|
|
|
// 条数 |
|
|
handleSizeChange(val) { |
|
|
handleSizeChange(val) { |
|
|
this.pageSize = val |
|
|
this.pageSize = val |
|
|
this.getAuthList() |
|
|
this.getAuthList() |
|
|
}, |
|
|
}, |
|
|
|
|
|
// 页码 |
|
|
handleCurrentChange(val) { |
|
|
handleCurrentChange(val) { |
|
|
this.page = val |
|
|
this.page = val |
|
|
this.getAuthList() |
|
|
this.getAuthList() |
|
|
}, |
|
|
}, |
|
|
|
|
|
// 删除角色 |
|
|
deleteAuth(row) { |
|
|
deleteAuth(row) { |
|
|
this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', { |
|
|
this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', { |
|
|
confirmButtonText: '确定', |
|
|
confirmButtonText: '确定', |
|
@ -95,25 +130,29 @@ export default { |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
initForm(){ |
|
|
|
|
|
for(const key in this.form){ |
|
|
|
|
|
|
|
|
// 初始化表单 |
|
|
|
|
|
initForm() { |
|
|
|
|
|
for (const key in this.form) { |
|
|
this.form[key] = '' |
|
|
this.form[key] = '' |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
closeDialog(){ |
|
|
|
|
|
|
|
|
// 关闭窗口 |
|
|
|
|
|
closeDialog() { |
|
|
this.initForm() |
|
|
this.initForm() |
|
|
this.dialogFormVisible = false |
|
|
this.dialogFormVisible = false |
|
|
|
|
|
this.menuDialogFlag = false |
|
|
}, |
|
|
}, |
|
|
async enterDialog(){ |
|
|
|
|
|
|
|
|
// 确定弹窗 |
|
|
|
|
|
async enterDialog() { |
|
|
const res = await createAuthority(this.form) |
|
|
const res = await createAuthority(this.form) |
|
|
if(res.success){ |
|
|
|
|
|
|
|
|
if (res.success) { |
|
|
this.$message({ |
|
|
this.$message({ |
|
|
type: 'success', |
|
|
type: 'success', |
|
|
message: '添加成功!' |
|
|
message: '添加成功!' |
|
|
}) |
|
|
}) |
|
|
this.getAuthList() |
|
|
this.getAuthList() |
|
|
this.closeDialog() |
|
|
this.closeDialog() |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
this.$message({ |
|
|
this.$message({ |
|
|
type: 'error', |
|
|
type: 'error', |
|
|
message: '添加失败!' |
|
|
message: '添加失败!' |
|
@ -123,9 +162,11 @@ export default { |
|
|
this.initForm() |
|
|
this.initForm() |
|
|
this.dialogFormVisible = false |
|
|
this.dialogFormVisible = false |
|
|
}, |
|
|
}, |
|
|
|
|
|
// 增加角色 |
|
|
addAuthority() { |
|
|
addAuthority() { |
|
|
this.dialogFormVisible = true |
|
|
this.dialogFormVisible = true |
|
|
}, |
|
|
}, |
|
|
|
|
|
// 获取用户列表 |
|
|
async getAuthList(page = this.page, pageSize = this.pageSize) { |
|
|
async getAuthList(page = this.page, pageSize = this.pageSize) { |
|
|
try { |
|
|
try { |
|
|
const table = await getAuthorityList({ page, pageSize }) |
|
|
const table = await getAuthorityList({ page, pageSize }) |
|
@ -133,10 +174,41 @@ export default { |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
console.log(err) |
|
|
console.log(err) |
|
|
} |
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
async addAuthMenu(row) { |
|
|
|
|
|
const res1 = await getMenuAuthority({authorityId:row.authorityId}) |
|
|
|
|
|
const menus = res1.data.menus |
|
|
|
|
|
const arr = [] |
|
|
|
|
|
menus.map(item=>{arr.push(Number(item.menuId))}) |
|
|
|
|
|
this.treeIds = arr |
|
|
|
|
|
const res2 = await getBaseMenuTree() |
|
|
|
|
|
this.treeData = res2.data.menus |
|
|
|
|
|
console.log(this.treeData) |
|
|
|
|
|
this.activeUserId = row.authorityId |
|
|
|
|
|
this.menuDialogFlag = true |
|
|
|
|
|
}, |
|
|
|
|
|
// 关联树 |
|
|
|
|
|
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() |
|
|
} |
|
|
} |
|
|
|
|
|
// 获取基础menu树 |
|
|
}, |
|
|
}, |
|
|
created() { |
|
|
created() { |
|
|
this.getAuthList() |
|
|
this.getAuthList() |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|