权限管理

This commit is contained in:
yl 2023-03-15 22:45:37 +08:00 committed by yovinchen
parent 13a9ff9ffd
commit e8e41560e1
3 changed files with 284 additions and 204 deletions

View File

@ -3,97 +3,130 @@
<!-- 工具条 --> <!-- 工具条 -->
<div class="tools-div"> <div class="tools-div">
<el-button type="success" icon="el-icon-plus" size="mini" @click="add()"> </el-button> <el-button
:disabled="$hasBP('bnt.sysMenu.add') === false"
icon="el-icon-plus"
size="mini"
type="success"
@click="add()"
>
</el-button>
</div> </div>
<el-table <el-table
:data="sysMenuList" :data="sysMenuList"
style="width: 100%;margin-bottom: 20px;margin-top: 10px;"
row-key="id"
border
:default-expand-all="false" :default-expand-all="false"
:tree-props="{children: 'children'}"> :tree-props="{children: 'children'}"
border
row-key="id"
style="width: 100%;margin-bottom: 20px;margin-top: 10px;"
>
<el-table-column prop="name" label="菜单名称" width="160"/> <el-table-column label="菜单名称" prop="name" width="160"/>
<el-table-column label="图标"> <el-table-column label="图标">
<template slot-scope="scope"> <template slot-scope="scope">
<i :class="scope.row.icon"></i> <i :class="scope.row.icon"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="perms" label="权限标识" width="160"/> <el-table-column label="权限标识" prop="perms" width="160"/>
<el-table-column prop="path" label="路由地址" width="120"/> <el-table-column label="路由地址" prop="path" width="120"/>
<el-table-column prop="component" label="组件路径" width="160"/> <el-table-column label="组件路径" prop="component" width="160"/>
<el-table-column prop="sortValue" label="排序" width="60"/> <el-table-column label="排序" prop="sortValue" width="60"/>
<el-table-column label="状态" width="80"> <el-table-column label="状态" width="80">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
v-model="scope.row.status === 1" disabled="true"> v-model="scope.row.status === 1"
</el-switch> disabled="true"
/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="createTime" label="创建时间" width="160"/> <el-table-column label="创建时间" prop="createTime" width="160"/>
<el-table-column label="操作" width="180" align="center" fixed="right"> <el-table-column align="center" fixed="right" label="操作" width="180">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="success" v-if="scope.row.type !== 2" icon="el-icon-plus" size="mini" @click="add(scope.row)" title="添加下级节点"/> <el-button
<el-button type="primary" icon="el-icon-edit" size="mini" @click="edit(scope.row)" title="修改"/> v-if="scope.row.type !== 2"
<el-button type="danger" icon="el-icon-delete" size="mini" @click="removeDataById(scope.row.id)" title="删除" :disabled="scope.row.children.length > 0"/> icon="el-icon-plus"
size="mini"
title="添加下级节点"
type="success"
@click="add(scope.row)"
/>
<el-button
:disabled="$hasBP('bnt.sysMenu.update') === false"
icon="el-icon-edit"
size="mini"
title="修改"
type="primary"
@click="edit(scope.row)"
/>
<el-button
:disabled="(scope.row.children.length > 0) || !$hasBP('bnt.sysMenu.remove')"
icon="el-icon-delete"
size="mini"
title="删除"
type="danger"
@click="removeDataById(scope.row.id)"
/>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="40%" > <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="40%">
<el-form ref="dataForm" :model="sysMenu" label-width="150px" size="small" style="padding-right: 40px;"> <el-form ref="dataForm" :model="sysMenu" label-width="150px" size="small" style="padding-right: 40px;">
<el-form-item label="上级部门" v-if="sysMenu.id === ''"> <el-form-item v-if="sysMenu.id === ''" label="上级部门">
<el-input v-model="sysMenu.parentName" disabled="true"/> <el-input v-model="sysMenu.parentName" disabled="true"/>
</el-form-item> </el-form-item>
<el-form-item label="菜单类型" prop="type"> <el-form-item label="菜单类型" prop="type">
<el-radio-group v-model="sysMenu.type" :disabled="typeDisabled"> <el-radio-group v-model="sysMenu.type" :disabled="typeDisabled">
<el-radio :label="0" :disabled="type0Disabled">目录</el-radio> <el-radio :disabled="type0Disabled" :label="0">目录</el-radio>
<el-radio :label="1" :disabled="type1Disabled">菜单</el-radio> <el-radio :disabled="type1Disabled" :label="1">菜单</el-radio>
<el-radio :label="2" :disabled="type2Disabled">按钮</el-radio> <el-radio :disabled="type2Disabled" :label="2">按钮</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="菜单名称" prop="name"> <el-form-item label="菜单名称" prop="name">
<el-input v-model="sysMenu.name"/> <el-input v-model="sysMenu.name"/>
</el-form-item> </el-form-item>
<el-form-item label="图标" prop="icon" v-if="sysMenu.type !== 2"> <el-form-item v-if="sysMenu.type !== 2" label="图标" prop="icon">
<el-select v-model="sysMenu.icon" clearable> <el-select v-model="sysMenu.icon" clearable>
<el-option v-for="item in iconList" :key="item.class" :label="item.class" :value="item.class"> <el-option v-for="item in iconList" :key="item.class" :label="item.class" :value="item.class">
<span style="float: left;"> <span style="float: left;">
<i :class="item.class"></i> <!-- 如果动态显示图标这里添加判断 --> <i :class="item.class"/> <!-- 如果动态显示图标这里添加判断 -->
</span> </span>
<span style="padding-left: 6px;">{{ item.class }}</span> <span style="padding-left: 6px;">{{ item.class }}</span>
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="排序"> <el-form-item label="排序">
<el-input-number v-model="sysMenu.sortValue" controls-position="right" :min="0" /> <el-input-number v-model="sysMenu.sortValue" :min="0" controls-position="right"/>
</el-form-item> </el-form-item>
<el-form-item prop="path"> <el-form-item prop="path">
<span slot="label"> <span slot="label">
<el-tooltip content="访问的路由地址,如:`sysUser`" placement="top"> <el-tooltip content="访问的路由地址,如:`sysUser`" placement="top">
<i class="el-icon-question"></i> <i class="el-icon-question"/>
</el-tooltip> </el-tooltip>
路由地址 路由地址
</span> </span>
<el-input v-model="sysMenu.path" placeholder="请输入路由地址" /> <el-input v-model="sysMenu.path" placeholder="请输入路由地址"/>
</el-form-item> </el-form-item>
<el-form-item prop="component" v-if="sysMenu.type !== 0"> <el-form-item v-if="sysMenu.type !== 0" prop="component">
<span slot="label"> <span slot="label">
<el-tooltip content="访问的组件路径,如:`system/user/index`,默认在`views`目录下" placement="top"> <el-tooltip content="访问的组件路径,如:`system/user/index`,默认在`views`目录下" placement="top">
<i class="el-icon-question"></i> <i class="el-icon-question"/>
</el-tooltip> </el-tooltip>
组件路径 组件路径
</span> </span>
<el-input v-model="sysMenu.component" placeholder="请输入组件路径" /> <el-input v-model="sysMenu.component" placeholder="请输入组件路径"/>
</el-form-item> </el-form-item>
<el-form-item v-if="sysMenu.type === 2"> <el-form-item v-if="sysMenu.type === 2">
<el-input v-model="sysMenu.perms" placeholder="请输入权限标识" maxlength="100" /> <el-input v-model="sysMenu.perms" maxlength="100" placeholder="请输入权限标识"/>
<span slot="label"> <span slot="label">
<el-tooltip content="控制器中定义的权限字符,如:@PreAuthorize(hasAuthority('bnt.sysRole.list'))" placement="top"> <el-tooltip
<i class="el-icon-question"></i> content="控制器中定义的权限字符,如:@PreAuthorize(hasAuthority('bnt.sysRole.list'))"
</el-tooltip> placement="top"
权限字符 >
</span> <i class="el-icon-question"/>
</el-tooltip>
权限字符
</span>
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="type"> <el-form-item label="状态" prop="type">
<el-radio-group v-model="sysMenu.status"> <el-radio-group v-model="sysMenu.status">
@ -103,16 +136,16 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" size="small" icon="el-icon-refresh-right"> </el-button> <el-button icon="el-icon-refresh-right" size="small" @click="dialogVisible = false"> </el-button>
<el-button type="primary" icon="el-icon-check" @click="saveOrUpdate()" size="small"> </el-button> <el-button icon="el-icon-check" size="small" type="primary" @click="saveOrUpdate()"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import api from '@/api/system/sysMenu' import api from '@/api/system/sysMenu'
const defaultForm = { const defaultForm = {
id: '', id: '',
parentId: '', parentId: '',
@ -144,55 +177,55 @@ export default {
iconList: [ iconList: [
{ {
class: "el-icon-s-tools", class: 'el-icon-s-tools'
}, },
{ {
class: "el-icon-s-custom", class: 'el-icon-s-custom'
}, },
{ {
class: "el-icon-setting", class: 'el-icon-setting'
}, },
{ {
class: "el-icon-user-solid", class: 'el-icon-user-solid'
}, },
{ {
class: "el-icon-s-help", class: 'el-icon-s-help'
}, },
{ {
class: "el-icon-phone", class: 'el-icon-phone'
}, },
{ {
class: "el-icon-s-unfold", class: 'el-icon-s-unfold'
}, },
{ {
class: "el-icon-s-operation", class: 'el-icon-s-operation'
}, },
{ {
class: "el-icon-more-outline", class: 'el-icon-more-outline'
}, },
{ {
class: "el-icon-s-check", class: 'el-icon-s-check'
}, },
{ {
class: "el-icon-tickets", class: 'el-icon-tickets'
}, },
{ {
class: "el-icon-s-goods", class: 'el-icon-s-goods'
}, },
{ {
class: "el-icon-document-remove", class: 'el-icon-document-remove'
}, },
{ {
class: "el-icon-warning", class: 'el-icon-warning'
}, },
{ {
class: "el-icon-warning-outline", class: 'el-icon-warning-outline'
}, },
{ {
class: "el-icon-question", class: 'el-icon-question'
}, },
{ {
class: "el-icon-info", class: 'el-icon-info'
} }
] ]
} }
@ -235,7 +268,7 @@ export default {
}, },
// ------------- // -------------
add(row){ add(row) {
debugger debugger
this.typeDisabled = false this.typeDisabled = false
this.dialogTitle = '添加下级节点' this.dialogTitle = '添加下级节点'
@ -243,17 +276,17 @@ export default {
this.sysMenu = Object.assign({}, defaultForm) this.sysMenu = Object.assign({}, defaultForm)
this.sysMenu.id = '' this.sysMenu.id = ''
if(row) { if (row) {
this.sysMenu.parentId = row.id this.sysMenu.parentId = row.id
this.sysMenu.parentName = row.name this.sysMenu.parentName = row.name
//this.sysMenu.component = 'ParentView' // this.sysMenu.component = 'ParentView'
if(row.type === 0) { if (row.type === 0) {
this.sysMenu.type = 1 this.sysMenu.type = 1
this.typeDisabled = false this.typeDisabled = false
this.type0Disabled = false this.type0Disabled = false
this.type1Disabled = false this.type1Disabled = false
this.type2Disabled = true this.type2Disabled = true
} else if(row.type === 1) { } else if (row.type === 1) {
this.sysMenu.type = 2 this.sysMenu.type = 2
this.typeDisabled = true this.typeDisabled = true
} }
@ -276,7 +309,7 @@ export default {
}, },
saveOrUpdate() { saveOrUpdate() {
if(this.sysMenu.type === 0 && this.sysMenu.parentId !== 0) { if (this.sysMenu.type === 0 && this.sysMenu.parentId !== 0) {
this.sysMenu.component = 'ParentView' this.sysMenu.component = 'ParentView'
} }
this.$refs.dataForm.validate(valid => { this.$refs.dataForm.validate(valid => {

View File

@ -7,10 +7,10 @@
<el-col :span="24"> <el-col :span="24">
<el-form-item label="角色名称"> <el-form-item label="角色名称">
<el-input <el-input
style="width: 100%"
v-model="searchObj.roleName" v-model="searchObj.roleName"
style="width: 100%"
placeholder="角色名称" placeholder="角色名称"
></el-input> />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
@ -21,17 +21,24 @@
size="mini" size="mini"
:loading="loading" :loading="loading"
@click="fetchData()" @click="fetchData()"
>搜索</el-button >搜索</el-button>
> <el-button
<el-button icon="el-icon-refresh" size="mini" @click="resetData" icon="el-icon-refresh"
>重置</el-button size="mini"
> @click="resetData"
<el-button type="success" icon="el-icon-plus" size="mini" @click="add" :disabled="$hasBP('bnt.sysRole.add') === false" >重置</el-button>
> </el-button <el-button
> type="success"
<el-button class="btn-add" size="mini" @click="batchRemove()" icon="el-icon-plus"
>批量删除</el-button size="mini"
> :disabled="$hasBP('bnt.sysRole.add') === false"
@click="add"
> </el-button>
<el-button
class="btn-add"
size="mini"
@click="batchRemove()"
>批量删除</el-button>
</el-row> </el-row>
</el-form> </el-form>
</div> </div>
@ -65,17 +72,26 @@
type="primary" type="primary"
icon="el-icon-edit" icon="el-icon-edit"
size="mini" size="mini"
@click="edit(scope.row.id)" :disabled="$hasBP('bnt.sysRole.update') === false"
title="修改" title="修改"
@click="edit(scope.row.id)"
/> />
<el-button <el-button
type="danger" type="danger"
icon="el-icon-delete" icon="el-icon-delete"
:disabled="$hasBP('bnt.sysRole.remove') === false"
size="mini" size="mini"
@click="removeDataById(scope.row.id)"
title="删除" title="删除"
@click="removeDataById(scope.row.id)"
/>
<el-button
type="warning"
:disabled="$hasBP('bnt.sysRole.assignAuth') === false"
icon="el-icon-baseball"
size="mini"
title="分配权限"
@click="showAssignAuth(scope.row)"
/> />
<el-button type="warning" icon="el-icon-baseball" size="mini" @click="showAssignAuth(scope.row)" title="分配权限"/>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -106,24 +122,22 @@
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button <el-button
@click="dialogVisible = false"
size="small" size="small"
icon="el-icon-refresh-right" icon="el-icon-refresh-right"
> </el-button @click="dialogVisible = false"
> > </el-button>
<el-button <el-button
type="primary" type="primary"
icon="el-icon-check" icon="el-icon-check"
@click="saveOrUpdate()"
size="small" size="small"
> </el-button @click="saveOrUpdate()"
> > </el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import api from "@/api/system/sysRole"; import api from '@/api/system/sysRole'
export default { export default {
// //
// //
@ -133,126 +147,126 @@ export default {
list: [], // list: [], //
total: 0, // total: 0, //
page: 1, // page: 1, //
limit: 3, // limit: 10, //
searchObj: {}, // searchObj: {}, //
sysRole: {}, // sysRole: {}, //
multipleSelection: [], // multipleSelection: [], //
dialogVisible: false, dialogVisible: false
}; }
}, },
// //
created() { created() {
this.fetchData(); this.fetchData()
}, },
// //
methods: { methods: {
showAssignAuth(row) { showAssignAuth(row) {
this.$router.push('/system/assignAuth?id='+row.id+'&roleName='+row.roleName); this.$router.push('/system/assignAuth?id=' + row.id + '&roleName=' + row.roleName)
}, },
edit(id) { edit(id) {
this.dialogVisible = true; this.dialogVisible = true
this.fetchDataById(id); this.fetchDataById(id)
}, },
fetchDataById(id) { fetchDataById(id) {
api.getById(id).then((response) => { api.getById(id).then((response) => {
this.sysRole = response.data; this.sysRole = response.data
}); })
}, },
add() { add() {
this.dialogVisible = true; this.dialogVisible = true
}, },
saveOrUpdate() { saveOrUpdate() {
this.saveBtnDisabled = true; // this.saveBtnDisabled = true //
if (!this.sysRole.id) { if (!this.sysRole.id) {
this.saveData(); this.saveData()
} else { } else {
this.updateData(); this.updateData()
} }
}, },
// //
saveData() { saveData() {
api.save(this.sysRole).then((response) => { api.save(this.sysRole).then((response) => {
this.$message.success(response.message || "操作成功"); this.$message.success(response.message || '操作成功')
this.dialogVisible = false; this.dialogVisible = false
this.fetchData(this.page); this.fetchData(this.page)
}); })
}, },
updateData() { updateData() {
api.updateById(this.sysRole).then((response) => { api.updateById(this.sysRole).then((response) => {
this.$message.success(response.message || "操作成功"); this.$message.success(response.message || '操作成功')
this.dialogVisible = false; this.dialogVisible = false
this.fetchData(this.page); this.fetchData(this.page)
}); })
}, },
fetchData(current = 1) { fetchData(current = 1) {
this.page = current; this.page = current
// api // api
api api
.getPageList(this.page, this.limit, this.searchObj) .getPageList(this.page, this.limit, this.searchObj)
.then((response) => { .then((response) => {
this.list = response.data.records; this.list = response.data.records
this.total = response.data.total; this.total = response.data.total
}); })
}, },
// //
resetData() { resetData() {
console.log("重置查询表单"); console.log('重置查询表单')
this.searchObj = {}; this.searchObj = {}
this.fetchData(); this.fetchData()
}, },
// id // id
removeDataById(id) { removeDataById(id) {
// debugger // debugger
this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", { this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
confirmButtonText: "确定", confirmButtonText: '确定',
cancelButtonText: "取消", cancelButtonText: '取消',
type: "warning", type: 'warning'
}) })
.then(() => { .then(() => {
// promise // promise
// ajax // ajax
return api.removeById(id); return api.removeById(id)
}) })
.then((response) => { .then((response) => {
this.fetchData(this.page); this.fetchData(this.page)
this.$message.success(response.message || "删除成功"); this.$message.success(response.message || '删除成功')
}); })
}, },
// //
handleSelectionChange(selection) { handleSelectionChange(selection) {
console.log(selection); console.log(selection)
this.multipleSelection = selection; this.multipleSelection = selection
}, },
// //
batchRemove() { batchRemove() {
if (this.multipleSelection.length === 0) { if (this.multipleSelection.length === 0) {
this.$message.warning("请选择要删除的记录!"); this.$message.warning('请选择要删除的记录!')
return; return
} }
this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", { this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
confirmButtonText: "确定", confirmButtonText: '确定',
cancelButtonText: "取消", cancelButtonText: '取消',
type: "warning", type: 'warning'
}) })
.then(() => { .then(() => {
// ajax // ajax
// selectionidid // selectionidid
var idList = []; var idList = []
this.multipleSelection.forEach((item) => { this.multipleSelection.forEach((item) => {
idList.push(item.id); idList.push(item.id)
}); })
// api // api
return api.batchRemove(idList); return api.batchRemove(idList)
}) })
.then((response) => { .then((response) => {
this.fetchData(); this.fetchData()
this.$message.success(response.message); this.$message.success(response.message)
}); })
}, }
}, }
}; }
</script> </script>

View File

@ -6,58 +6,68 @@
<el-row> <el-row>
<el-col :span="8"> <el-col :span="8">
<el-form-item label="关 键 字"> <el-form-item label="关 键 字">
<el-input style="width: 95%" v-model="searchObj.keyword" placeholder="用户名/姓名/手机号码"></el-input> <el-input v-model="searchObj.keyword" placeholder="用户名/姓名/手机号码" style="width: 95%"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
<el-form-item label="操作时间"> <el-form-item label="操作时间">
<el-date-picker <el-date-picker
v-model="createTimes" v-model="createTimes"
type="datetimerange" end-placeholder="结束时间"
range-separator="至" range-separator="至"
start-placeholder="开始时间" start-placeholder="开始时间"
end-placeholder="结束时间"
value-format="yyyy-MM-dd HH:mm:ss"
style="margin-right: 10px;width: 100%;" style="margin-right: 10px;width: 100%;"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm:ss"
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row style="display:flex"> <el-row style="display:flex">
<el-button type="primary" icon="el-icon-search" size="mini" :loading="loading" @click="fetchData()">搜索</el-button> <el-button :loading="loading" icon="el-icon-search" size="mini" type="primary" @click="fetchData()">搜索
</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
<el-button type="success" icon="el-icon-plus" size="mini" @click="add"> </el-button> <el-button
:disabled="$hasBP('bnt.sysUser.add') === false"
icon="el-icon-plus"
size="mini"
type="success"
@click="add"
>
</el-button>
</el-row> </el-row>
</el-form> </el-form>
</div> </div>
<!-- 工具条 --> <!-- 工具条 -->
<!-- <div class="tools-div">--> <!-- <div class="tools-div">-->
<!-- <el-button type="success" icon="el-icon-plus" size="mini" @click="add"> </el-button>--> <!-- <el-button type="success" icon="el-icon-plus" size="mini" @click="add"> </el-button>-->
<!-- </div>--> <!-- </div>-->
<!-- 列表 --> <!-- 列表 -->
<el-table <el-table
v-loading="listLoading" v-loading="listLoading"
:data="list" :data="list"
stripe
border border
style="width: 100%;margin-top: 10px;"> stripe
style="width: 100%;margin-top: 10px;"
>
<el-table-column <el-table-column
align="center"
label="序号" label="序号"
width="70" width="70"
align="center"> >
<template slot-scope="scope"> <template slot-scope="scope">
{{ (page - 1) * limit + scope.$index + 1 }} {{ (page - 1) * limit + scope.$index + 1 }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="username" label="用户名" width="100"/> <el-table-column label="用户名" prop="username" width="100"/>
<el-table-column prop="name" label="姓名" width="70"/> <el-table-column label="姓名" prop="name" width="70"/>
<el-table-column prop="phone" label="手机" width="120"/> <el-table-column label="手机" prop="phone" width="120"/>
<el-table-column prop="postName" label="岗位" width="100"/> <el-table-column label="岗位" prop="postName" width="100"/>
<el-table-column prop="deptName" label="部门" width="100"/> <el-table-column label="部门" prop="deptName" width="100"/>
<el-table-column label="所属角色" width="130"> <el-table-column label="所属角色" width="130">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-for="item in scope.row.roleList" :key="item.id" style="margin-right: 10px;">{{ item.roleName }}</span> <span v-for="item in scope.row.roleList" :key="item.id" style="margin-right: 10px;">{{ item.roleName }}</span>
@ -67,17 +77,38 @@
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
v-model="scope.row.status === 1" v-model="scope.row.status === 1"
@change="switchStatus(scope.row)"> @change="switchStatus(scope.row)"
</el-switch> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="createTime" label="创建时间" width="160"/> <el-table-column label="创建时间" prop="createTime" width="160"/>
<el-table-column label="操作" width="180" align="center" fixed="right"> <el-table-column align="center" fixed="right" label="操作" width="180">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="primary" icon="el-icon-edit" size="mini" @click="edit(scope.row.id)" title="修改"/> <el-button
<el-button type="danger" icon="el-icon-delete" size="mini" @click="removeDataById(scope.row.id)" title="删除" /> :disabled="$hasBP('bnt.sysUser.update') === false"
<el-button type="warning" icon="el-icon-baseball" size="mini" @click="showAssignRole(scope.row)" title="分配角色"/> icon="el-icon-edit"
size="mini"
title="修改"
type="primary"
@click="edit(scope.row.id)"
/>
<el-button
:disabled="$hasBP('bnt.sysUser.remove') === false"
icon="el-icon-delete"
size="mini"
title="删除"
type="danger"
@click="removeDataById(scope.row.id)"
/>
<el-button
:disabled="$hasBP('bnt.sysUser.assignRole') === false"
icon="el-icon-baseball"
size="mini"
title="分配角色"
type="warning"
@click="showAssignRole(scope.row)"
/>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -85,17 +116,17 @@
<!-- 分页组件 --> <!-- 分页组件 -->
<el-pagination <el-pagination
:current-page="page" :current-page="page"
:total="total"
:page-size="limit" :page-size="limit"
:page-sizes="[5, 10, 20, 30, 40, 50, 100]" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
style="padding: 30px 0; text-align: center;" :total="total"
layout="sizes, prev, pager, next, jumper, ->, total, slot" layout="sizes, prev, pager, next, jumper, ->, total, slot"
style="padding: 30px 0; text-align: center;"
@current-change="fetchData" @current-change="fetchData"
@size-change="changeSize" @size-change="changeSize"
/> />
<el-dialog title="添加/修改" :visible.sync="dialogVisible" width="40%" > <el-dialog :visible.sync="dialogVisible" title="添加/修改" width="40%">
<el-form ref="dataForm" :model="sysUser" label-width="100px" size="small" style="padding-right: 40px;"> <el-form ref="dataForm" :model="sysUser" label-width="100px" size="small" style="padding-right: 40px;">
<el-form-item label="用户名" prop="username"> <el-form-item label="用户名" prop="username">
<el-input v-model="sysUser.username"/> <el-input v-model="sysUser.username"/>
</el-form-item> </el-form-item>
@ -110,28 +141,29 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" size="small" icon="el-icon-refresh-right"> </el-button> <el-button icon="el-icon-refresh-right" size="small" @click="dialogVisible = false"> </el-button>
<el-button type="primary" icon="el-icon-check" @click="saveOrUpdate()" size="small"> </el-button> <el-button icon="el-icon-check" size="small" type="primary" @click="saveOrUpdate()"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
<el-dialog title="分配角色" :visible.sync="dialogRoleVisible"> <el-dialog :visible.sync="dialogRoleVisible" title="分配角色">
<el-form label-width="80px"> <el-form label-width="80px">
<el-form-item label="用户名"> <el-form-item label="用户名">
<el-input disabled :value="sysUser.username"></el-input> <el-input :value="sysUser.username" disabled/>
</el-form-item> </el-form-item>
<el-form-item label="角色列表"> <el-form-item label="角色列表">
<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox> <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选
<div style="margin: 15px 0;"></div> </el-checkbox>
<div style="margin: 15px 0;"/>
<el-checkbox-group v-model="userRoleIds" @change="handleCheckedChange"> <el-checkbox-group v-model="userRoleIds" @change="handleCheckedChange">
<el-checkbox v-for="role in allRoles" :key="role.id" :label="role.id">{{role.roleName}}</el-checkbox> <el-checkbox v-for="role in allRoles" :key="role.id" :label="role.id">{{ role.roleName }}</el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer"> <div slot="footer">
<el-button type="primary" @click="assignRole" size="small">保存</el-button> <el-button size="small" type="primary" @click="assignRole">保存</el-button>
<el-button @click="dialogRoleVisible = false" size="small">取消</el-button> <el-button size="small" @click="dialogRoleVisible = false">取消</el-button>
</div> </div>
</el-dialog> </el-dialog>
</div> </div>
@ -140,6 +172,7 @@
<script> <script>
import api from '@/api/system/sysUser' import api from '@/api/system/sysUser'
import roleApi from '@/api/system/sysRole' import roleApi from '@/api/system/sysRole'
const defaultForm = { const defaultForm = {
id: '', id: '',
username: '', username: '',
@ -178,7 +211,7 @@ export default {
this.fetchData() this.fetchData()
roleApi.findAll().then(response => { roleApi.findAll().then(response => {
this.roleList = response.data; this.roleList = response.data
}) })
}, },
@ -201,14 +234,14 @@ export default {
this.page = page this.page = page
console.log('翻页。。。' + this.page) console.log('翻页。。。' + this.page)
if(this.createTimes && this.createTimes.length ==2) { if (this.createTimes && this.createTimes.length == 2) {
this.searchObj.createTimeBegin = this.createTimes[0] this.searchObj.createTimeBegin = this.createTimes[0]
this.searchObj.createTimeEnd = this.createTimes[1] this.searchObj.createTimeEnd = this.createTimes[1]
} }
api.getPageList(this.page, this.limit, this.searchObj).then( api.getPageList(this.page, this.limit, this.searchObj).then(
response => { response => {
//this.list = response.data.list // this.list = response.data.list
this.list = response.data.records this.list = response.data.records
this.total = response.data.total this.total = response.data.total
@ -245,7 +278,7 @@ export default {
}, },
// ------------- // -------------
add(){ add() {
this.dialogVisible = true this.dialogVisible = true
this.sysUser = Object.assign({}, defaultForm) this.sysUser = Object.assign({}, defaultForm)
}, },
@ -292,26 +325,26 @@ export default {
}) })
}, },
showAssignRole (row) { showAssignRole(row) {
this.sysUser = row this.sysUser = row
this.dialogRoleVisible = true this.dialogRoleVisible = true
this.getRoles() this.getRoles()
}, },
getRoles () { getRoles() {
roleApi.getRoles(this.sysUser.id).then(response => { roleApi.getRoles(this.sysUser.id).then(response => {
const {allRolesList, assginRoleList} = response.data const {allRolesList, assginRoleList} = response.data
this.allRoles = allRolesList this.allRoles = allRolesList
this.userRoleIds = assginRoleList.map(item => item.id) this.userRoleIds = assginRoleList.map(item => item.id)
this.checkAll = allRolesList.length===assginRoleList.length this.checkAll = allRolesList.length === assginRoleList.length
this.isIndeterminate = assginRoleList.length>0 && assginRoleList.length<allRolesList.length this.isIndeterminate = assginRoleList.length > 0 && assginRoleList.length < allRolesList.length
}) })
}, },
/* /*
全选勾选状态发生改变的监听 全选勾选状态发生改变的监听
*/ */
handleCheckAllChange (value) {// value true/false handleCheckAllChange(value) { // value true/false
// , userRoleIdsid, // , userRoleIdsid,
this.userRoleIds = value ? this.allRoles.map(item => item.id) : [] this.userRoleIds = value ? this.allRoles.map(item => item.id) : []
// , false // , false
@ -321,14 +354,14 @@ export default {
/* /*
角色列表选中项发生改变的监听 角色列表选中项发生改变的监听
*/ */
handleCheckedChange (value) { handleCheckedChange(value) {
const {userRoleIds, allRoles} = this const {userRoleIds, allRoles} = this
this.checkAll = userRoleIds.length === allRoles.length && allRoles.length>0 this.checkAll = userRoleIds.length === allRoles.length && allRoles.length > 0
this.isIndeterminate = userRoleIds.length>0 && userRoleIds.length<allRoles.length this.isIndeterminate = userRoleIds.length > 0 && userRoleIds.length < allRoles.length
}, },
assignRole () { assignRole() {
let assginRoleVo = { const assginRoleVo = {
userId: this.sysUser.id, userId: this.sysUser.id,
roleIdList: this.userRoleIds roleIdList: this.userRoleIds
} }