<template>
|
<div class="roles-management-page subpages-containter-box">
|
<search-bar @search="onSearch" @reset="onReset">
|
<el-form :inline="true" class="search-form">
|
<el-form-item>
|
<el-input placeholder="请输入角色名称" clearable v-model.trim="query.searchVal" class="default-form-width"></el-input>
|
</el-form-item>
|
</el-form>
|
</search-bar>
|
|
<div class="table-header-row">
|
<el-button type="primary" @click="onNew"><el-icon class="btn-left-icon"><e-icon-plus /></el-icon>新建</el-button>
|
</div>
|
|
<el-table :data="list" border stripe>
|
<el-table-column width="50" label="序号" fixed>
|
<template #default="scope">{{(queried.page-1)*queried.pageSize+(scope.$index+1)}}</template>
|
</el-table-column>
|
<el-table-column prop="Name" label="角色名称" min-width="50" />
|
<el-table-column prop="Description" label="描述" min-width="100" />
|
<el-table-column prop="CreateTime" label="创建时间" width="160" />
|
<el-table-column prop="ModifyTime" label="修改时间" width="160" />
|
<el-table-column prop="CreateBy" label="创建人" width="100" />
|
<el-table-column prop="ModifyBy" label="修改人" width="100" />
|
<el-table-column label="是否启用" width="80" align="center">
|
<template #default="scope">
|
<el-switch :model-value="scope.row.Enabled" :disabled="scope.row.Name==='SuperAdmin'" inactive-color="#eeeef0" @change="onChangeEnabled(scope.row,$event)" />
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" width="300" fixed="right" align="center">
|
<template #default="scope">
|
<el-button type="primary" size="small" @click="onOpenModifyModal(scope.row)" :disabled="scope.row.Name==='SuperAdmin'"><el-icon class="btn-left-icon"><e-icon-edit /></el-icon>编辑</el-button>
|
<el-button type="danger" size="small" @click="onCancel(scope.row.Id)" :disabled="scope.row.Name==='SuperAdmin'"><el-icon class="btn-left-icon"><e-icon-delete /></el-icon>删除</el-button>
|
<el-button type="success" size="small" @click="onOpenAuthorityModal(scope.row)"><span class="iconfont icon-fenpei btn-left-icon"></span>分配权限</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<div class="pagination-row" v-if="total>queried.pageSize">
|
<el-pagination :pager-count="5" layout="total, prev, pager, next, jumper" :total="total" @current-change="onPageList" />
|
</div>
|
|
<form-modal v-model:visible="formVisible" :type="formType" :role="actionRole" @submitCallback="onFormSubmitCallback" />
|
|
<authority-modal v-model:visible="authorityVisible" :role="actionRole" />
|
</div>
|
</template>
|
|
<script>
|
import SearchBar from '@/components/SearchBar.vue'
|
import FormModal from './compontents/FormModal.vue'
|
import AuthorityModal from './compontents/AuthorityModal.vue'
|
import {Plus,Edit,Delete} from '@element-plus/icons'
|
const defaultQuery = {
|
searchVal:'',
|
searchVal_FilterMode:1,
|
searchFormInputAttrs:['Name']
|
}
|
export default {
|
name:'rolesManagementPage',
|
components:{SearchBar,FormModal,AuthorityModal,'e-icon-plus':Plus,'e-icon-edit':Edit,'e-icon-delete':Delete},
|
data(){
|
return {
|
list:[],
|
total:0,
|
query:{...defaultQuery},
|
queried:{...this.$config.pagination},
|
actionRole:{},
|
formVisible:false,
|
formType:'',
|
authorityVisible:false
|
}
|
},
|
mounted() {
|
this.init()
|
},
|
methods:{
|
/* 页面初始化 */
|
init(){
|
this.newList()
|
},
|
/* 搜索按钮 */
|
onSearch(){
|
this.newList()
|
},
|
/* 重置按钮 */
|
onReset(){
|
this.query = {...defaultQuery}
|
this.newList()
|
},
|
/* 翻页功能 */
|
onPageList(page){
|
this.queried.page = page;
|
this.getList();
|
},
|
/* 表格刷新至首页 */
|
newList(needLoading=true){
|
this.queried = {...this.query,...this.$config.pagination}
|
this.getList(()=>{},needLoading)
|
},
|
/* 删除后的表格刷新 */
|
delRefresh(callback){
|
let len = this.list.length;
|
if (len===1 && this.queried.page>1) {
|
this.queried.page--;
|
}
|
this.getList(callback,false)
|
},
|
/* 更新数据表 */
|
getList(callback,needLoading=true){
|
if (needLoading) {
|
this.$loading();
|
}
|
this.$api.post('Get',this.queried,{block:'role'}).then((d)=>{
|
this.total = d.total;
|
this.list = d.list.map((currentItem)=>{
|
currentItem.CreateTime = this.$utils.project.parseTimeStr(currentItem.CreateTime)
|
currentItem.ModifyTime = this.$utils.project.parseTimeStr(currentItem.ModifyTime)
|
return currentItem
|
})
|
if (needLoading) {
|
this.$loading().close();
|
}
|
callback && callback(true)
|
}).catch((err)=>{
|
if (needLoading) {
|
this.$loading().close();
|
}
|
callback && callback(false)
|
})
|
},
|
/* 启用/禁用开关 */
|
onChangeEnabled(row,val){
|
//row.Enabled = val;
|
this.dealEnableDisable(row.Id,val,(f)=>{
|
if (f) {
|
row.Enabled = val;
|
}
|
})
|
},
|
/* 打开新建弹窗 */
|
onNew(){
|
this.formType = 'add';
|
this.formVisible = true;
|
},
|
/* 打开编辑弹窗 */
|
onOpenModifyModal(obj){
|
this.actionRole = obj;
|
this.formType = 'modify';
|
this.formVisible = true;
|
},
|
/* 打开分配权限弹窗 */
|
onOpenAuthorityModal(obj){
|
this.actionRole = obj;
|
this.authorityVisible = true;
|
},
|
/* 角色新增/编辑成功提交后的回调 */
|
onFormSubmitCallback(needLoading) {
|
if (this.formType==='add') {
|
this.newList(needLoading)
|
} else {
|
this.getList()
|
}
|
},
|
/* 删除按钮 */
|
onCancel(id){
|
this.$confirm('确定要删除该角色吗?<br />角色一旦删除,不可恢复!', '删除警示', {
|
dangerouslyUseHTMLString:true,
|
center:true
|
}).then(()=>{
|
this.dealCancel(id)
|
}).catch(()=>{});
|
},
|
/* 删除处理事件 */
|
dealCancel(id){
|
this.$loading();
|
this.$api.delete('Delete',{id},{block:'role'}).then(()=>{
|
this.delRefresh(()=>{
|
this.$loading().close();
|
})
|
}).catch((err)=>{
|
this.$loading().close();
|
})
|
},
|
/* 启用/禁用处理事件 */
|
dealEnableDisable(id,status,callback){
|
this.$loading();
|
this.$api.put('Enable',{},{block:'role'},{id,isEnabled:status}).then(()=>{
|
this.$loading().close();
|
this.$message.success('角色状态修改成功!')
|
callback(true)
|
}).catch((err)=>{
|
this.$loading().close();
|
callback(false)
|
})
|
}
|
}
|
}
|
</script>
|
|
<style scoped lang="scss">
|
</style>
|