吴雨瞳添加了注释

master
wyt 4 months ago
parent fd01452699
commit e76056d14f

@ -1,110 +1,150 @@
<template>
<!-- 主卡片容器包裹用于包裹整个角色管理页面内容 -->
<el-card class="main-card">
<!-- 页面标题使用当前路由名称作为标题 -->
<div class="title">{{ this.$route.name }}</div>
<!-- 操作按钮和搜索区域容器 -->
<div class="operation-container">
<el-button type="primary" size="small" icon="el-icon-plus" @click="openMenuModel(null)"> </el-button>
<el-button
type="danger"
size="small"
icon="el-icon-delete"
:disabled="this.roleIds.length == 0"
@click="isDelete = true">
批量删除
</el-button>
<!-- 新增角色按钮 -->
<el-button type="primary" size="small" icon="el-icon-plus" @click="openModel(null)"> </el-button>
<!-- 搜索区域居右显示 -->
<div style="margin-left: auto">
<!-- 搜索输入框支持回车搜索 -->
<el-input
v-model="keywords"
prefix-icon="el-icon-search"
size="small"
placeholder="请输入角色名"
style="width: 200px"
@keyup.enter.native="searchRoles" />
<el-button type="primary" size="small" icon="el-icon-search" style="margin-left: 1rem" @click="searchRoles">
v-model="keywords"
prefix-icon="el-icon-search"
size="small"
placeholder="请输入角色名"
style="width: 200px"
@keyup.enter.native="listRoles" />
<!-- 搜索按钮 -->
<el-button type="primary" size="small" icon="el-icon-search" style="margin-left: 1rem" @click="listRoles">
搜索
</el-button>
</div>
</div>
<!-- 角色列表表格加载时显示loading状态支持选择功能 -->
<el-table border :data="roles" @selection-change="selectionChange" v-loading="loading">
<!-- 选择列 -->
<el-table-column type="selection" width="55" />
<el-table-column prop="roleName" label="角色名" align="center" />
<el-table-column prop="roleLabel" label="权限标签" align="center">
<!-- 角色名称列 -->
<el-table-column prop="roleName" label="角色名称" align="center" />
<!-- 角色权限标识列 -->
<el-table-column prop="roleKey" label="权限标识" align="center" />
<!-- 角色排序列 -->
<el-table-column prop="roleSort" label="排序" align="center" />
<!-- 角色状态列使用开关控制 -->
<el-table-column prop="status" label="状态" align="center" width="100">
<template slot-scope="scope">
<el-tag>
{{ scope.row.roleName }}
</el-tag>
<el-switch
v-model="scope.row.status"
active-color="#13ce66"
inactive-color="#F4F4F5"
:active-value="1" <!-- 1表示启用状态 -->
:inactive-value="0" <!-- 0表示禁用状态 -->
@change="changeStatus(scope.row)" /> <!-- 状态变化时触发的事件 -->
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" width="150" align="center">
<!-- 创建时间列使用date过滤器格式化时间 -->
<el-table-column prop="createTime" label="创建时间" align="center">
<template slot-scope="scope">
<i class="el-icon-time" style="margin-right: 5px" />
{{ scope.row.createTime | date }}
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="220">
<!-- 操作列 -->
<el-table-column label="操作" align="center" width="200">
<template slot-scope="scope">
<el-button type="text" size="mini" @click="openMenuModel(scope.row)">
<i class="el-icon-edit" /> 菜单权限
</el-button>
<el-button type="text" size="mini" @click="openResourceModel(scope.row)">
<i class="el-icon-folder-checked" /> 资源权限
</el-button>
<el-popconfirm title="确定删除吗?" style="margin-left: 10px" @confirm="deleteRoles(scope.row.id)">
<el-button size="mini" type="text" slot="reference"> <i class="el-icon-delete" /> 删除 </el-button>
<!-- 权限分配按钮 -->
<el-button type="primary" size="mini" @click="openAuthModel(scope.row)"> </el-button>
<!-- 编辑按钮 -->
<el-button type="success" size="mini" @click="openModel(scope.row)"> </el-button>
<!-- 删除确认弹窗触发器 -->
<el-popconfirm title="确定删除吗?" style="margin-left: 1rem" @confirm="deleteRole(scope.row.id)">
<el-button size="mini" type="danger" slot="reference"> 删除 </el-button>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<el-pagination
class="pagination-container"
background
@size-change="sizeChange"
@current-change="currentChange"
:current-page="current"
:page-size="size"
:total="count"
:page-sizes="[10, 20]"
layout="total, sizes, prev, pager, next, jumper" />
<el-dialog :visible.sync="roleMenu" width="30%">
<div class="dialog-title-container" slot="title" ref="roleTitle" />
<el-form label-width="80px" size="medium" :model="roleForm">
<el-form-item label="角色名">
<el-input v-model="roleForm.roleName" style="width: 250px" />
</el-form-item>
<el-form-item label="菜单权限">
<el-tree :data="menus" :default-checked-keys="roleForm.menuIds" show-checkbox node-key="id" ref="menuTree" />
</el-form-item>
</el-form>
class="pagination-container"
background
@size-change="sizeChange" <!-- 每页条数改变事件 -->
@current-change="currentChange" <!-- 当前页码改变事件 -->
:current-page="current" <!-- 当前页码 -->
:page-size="size" <!-- 每页条数 -->
:total="count" <!-- 总条数 -->
:page-sizes="[10, 20]" <!-- 可选每页条数 -->
layout="total, sizes, prev, pager, next, jumper" /> <!-- 分页布局 -->
<!-- 批量删除确认弹窗 -->
<el-dialog :visible.sync="isDelete" width="30%">
<div class="dialog-title-container" slot="title"><i class="el-icon-warning" style="color: #ff9900" />提示</div>
<div style="font-size: 1rem">是否删除选中项</div>
<div slot="footer">
<el-button @click="roleMenu = false"> </el-button>
<el-button type="primary" @click="saveOrUpdateRoleMenu"> </el-button>
<el-button @click="isDelete = false"> </el-button>
<el-button type="primary" @click="deleteRole(null)"> </el-button>
</div>
</el-dialog>
<el-dialog :visible.sync="roleResource" width="30%" top="9vh">
<div class="dialog-title-container" slot="title">修改资源权限</div>
<!-- 新增/编辑角色弹窗 -->
<el-dialog :visible.sync="addOrEdit" width="30%">
<div class="dialog-title-container" slot="title" ref="roleTitle" /> <!-- 弹窗标题动态设置 -->
<el-form label-width="80px" size="medium" :model="roleForm">
<el-form-item label="角色名">
<el-input v-model="roleForm.roleName" style="width: 250px" />
<el-form-item label="角色名称">
<el-input v-model="roleForm.roleName" style="width: 220px" />
</el-form-item>
<el-form-item label="权限标识">
<el-input v-model="roleForm.roleKey" style="width: 220px" />
</el-form-item>
<el-form-item label="显示排序">
<el-input-number v-model="roleForm.roleSort" controls-position="right" :min="1" :max="100" />
</el-form-item>
<el-form-item label="资源权限">
<el-tree
:data="resources"
:default-checked-keys="roleForm.resourceIds"
show-checkbox
node-key="id"
ref="resourceTree" />
<el-form-item label="角色状态">
<el-radio-group v-model="roleForm.status">
<el-radio :label="1">启用</el-radio>
<el-radio :label="0">禁用</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div slot="footer">
<el-button @click="roleResource = false"> </el-button>
<el-button type="primary" @click="saveOrUpdateRoleResource"> </el-button>
<el-button @click="addOrEdit = false"> </el-button>
<el-button type="primary" @click="addOrEditRole"> </el-button>
</div>
</el-dialog>
<el-dialog :visible.sync="isDelete" width="30%">
<div class="dialog-title-container" slot="title"><i class="el-icon-warning" style="color: #ff9900" />提示</div>
<div style="font-size: 1rem">是否删除选中项</div>
<!-- 角色权限分配弹窗 -->
<el-dialog :visible.sync="authDialog" width="40%" height="600px">
<div class="dialog-title-container" slot="title">
<i class="el-icon-lock" /> 角色权限
</div>
<!-- 权限树形结构选择器 -->
<el-tree
ref="tree"
:data="resources" <!-- 权限数据 -->
show-checkbox <!-- 显示复选框 -->
node-key="id" <!-- 节点唯一标识 -->
:default-checked-keys="checkedKeys" <!-- 默认选中的节点ID数组 -->
:props="defaultProps" <!-- 树形结构配置 -->
:expand-on-click-node="false" <!-- 点击节点不展开只通过图标展开 -->
:check-strictly="false" <!-- 父子节点关联选择 -->
/>
<div slot="footer">
<el-button @click="isDelete = false"> </el-button>
<el-button type="primary" @click="deleteRoles(null)"> </el-button>
<el-button @click="authDialog = false"> </el-button>
<el-button type="primary" @click="saveAuth"> </el-button>
</div>
</el-dialog>
</el-card>
@ -112,75 +152,102 @@
<script>
export default {
//
created() {
//
this.current = this.$store.state.pageState.role
//
this.listRoles()
},
data: function () {
data() {
return {
loading: true,
isDelete: false,
roles: [],
roleIds: [],
keywords: null,
current: 1,
size: 10,
count: 0,
roleMenu: false,
roleResource: false,
resources: [],
menus: [],
loading: true, //
isDelete: false, //
addOrEdit: false, // /
authDialog: false, //
keywords: '', //
roleIds: [], // ID
roles: [], //
resources: [], //
checkedKeys: [], // ID
currentRoleId: null, // ID
//
roleForm: {
roleName: '',
roleLabel: '',
resourceIds: [],
menuIds: []
}
id: null, // ID使
roleName: '', //
roleKey: '', //
roleSort: 1, //
status: 1 // 10
},
//
defaultProps: {
children: 'children', //
label: 'resourceName' //
},
current: 1, //
size: 10, //
count: 0 //
}
},
methods: {
searchRoles() {
this.current = 1
this.listRoles()
// ID
selectionChange(roles) {
this.roleIds = []
roles.forEach((item) => {
this.roleIds.push(item.id)
})
},
// 1
listRoles() {
this.axios
.get('/api/admin/roles', {
params: {
current: this.current,
size: this.size,
keywords: this.keywords
}
})
.then(({ data }) => {
this.roles = data.data.records //
this.count = data.data.count //
this.loading = false //
})
},
//
sizeChange(size) {
this.size = size
this.listRoles()
},
//
currentChange(current) {
this.current = current
//
this.$store.commit('updateRolePageState', current)
this.listRoles()
},
selectionChange(roles) {
this.roleIds = []
roles.forEach((item) => {
this.roleIds.push(item.id)
})
},
listRoles() {
this.axios
.get('/api/admin/roles', {
params: {
current: this.current,
size: this.size,
keywords: this.keywords
}
})
.then(({ data }) => {
this.roles = data.data.records
this.count = data.data.count
this.loading = false
})
this.axios.get('/api/admin/role/resources').then(({ data }) => {
this.resources = data.data
})
this.axios.get('/api/admin/role/menus').then(({ data }) => {
this.menus = data.data
// /
changeStatus(role) {
this.axios.post('/api/admin/roles', role).then(({ data }) => {
if (data.flag) {
//
this.$notify.success({
title: '成功',
message: data.message
})
this.listRoles() //
} else {
//
this.$notify.error({
title: '失败',
message: data.message
})
}
})
},
deleteRoles(id) {
var param = {}
//
deleteRole(id) {
let param = {}
// IDID
if (id == null) {
param = { data: this.roleIds }
} else {
@ -188,86 +255,113 @@ export default {
}
this.axios.delete('/api/admin/roles', param).then(({ data }) => {
if (data.flag) {
//
this.$notify.success({
title: '成功',
message: data.message
})
this.listRoles()
this.listRoles() //
} else {
//
this.$notify.error({
title: '失败',
message: data.message
})
}
//
this.isDelete = false
})
},
openMenuModel(role) {
this.$nextTick(function () {
this.$refs.menuTree.setCheckedKeys([])
})
this.$refs.roleTitle.innerHTML = role ? '修改角色' : '新增角色'
if (role != null) {
// /
openModel(role) {
if (role != null) { //
this.roleForm = JSON.parse(JSON.stringify(role))
} else {
this.$refs.roleTitle.innerHTML = '修改角色' //
} else { //
this.roleForm = {
id: null,
roleName: '',
roleLabel: '',
resourceIds: [],
menuIds: []
roleKey: '',
roleSort: 1,
status: 1
}
this.$refs.roleTitle.innerHTML = '添加角色' //
}
this.roleMenu = true
//
this.addOrEdit = true
},
openResourceModel(role) {
this.$nextTick(function () {
this.$refs.resourceTree.setCheckedKeys([])
})
this.roleForm = JSON.parse(JSON.stringify(role))
this.roleResource = true
},
saveOrUpdateRoleResource() {
this.roleForm.menuIds = null
this.roleForm.resourceIds = this.$refs.resourceTree.getCheckedKeys()
this.axios.post('/api/admin/role', this.roleForm).then(({ data }) => {
//
addOrEditRole() {
//
if (this.roleForm.roleName.trim() === '') {
this.$message.error('角色名称不能为空')
return false
}
if (this.roleForm.roleKey.trim() === '') {
this.$message.error('权限标识不能为空')
return false
}
// /
this.axios.post('/api/admin/roles', this.roleForm).then(({ data }) => {
if (data.flag) {
//
this.$notify.success({
title: '成功',
message: data.message
})
this.listRoles()
this.listRoles() //
} else {
//
this.$notify.error({
title: '失败',
message: data.message
})
}
this.roleResource = false
//
this.addOrEdit = false
})
},
saveOrUpdateRoleMenu() {
if (this.roleForm.roleName.trim() == '') {
this.$message.error('角色名不能为空')
return false
//
openAuthModel(role) {
this.currentRoleId = role.id // ID
//
this.axios.get('/api/admin/resources').then(({ data }) => {
this.resources = data.data //
//
this.axios.get('/api/admin/roles/' + role.id + '/resources').then(({ data }) => {
this.checkedKeys = data.data // ID
this.authDialog = true //
})
})
},
//
saveAuth() {
// ID
const checkedKeys = this.$refs.tree.getCheckedKeys()
//
const param = {
roleId: this.currentRoleId,
resourceIds: checkedKeys
}
this.roleForm.resourceIds = null
this.roleForm.menuIds = this.$refs.menuTree.getCheckedKeys().concat(this.$refs.menuTree.getHalfCheckedKeys())
this.axios.post('/api/admin/role', this.roleForm).then(({ data }) => {
//
this.axios.post('/api/admin/roles/resources', param).then(({ data }) => {
if (data.flag) {
//
this.$notify.success({
title: '成功',
message: data.message
})
this.listRoles()
} else {
//
this.$notify.error({
title: '失败',
message: data.message
})
}
this.roleMenu = false
//
this.authDialog = false
})
}
}
}
</script>
</script>
Loading…
Cancel
Save