Browse Source

【接口看板】权限配置页面开发

faster_AG_grid
安虹睿 1 year ago
parent
commit
fcbd4cb988
  1. 112
      PC/InterFace.Dash/src/api/wms-auth.js
  2. 351
      PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkRoles.vue

112
PC/InterFace.Dash/src/api/wms-auth.js

@ -1,13 +1,6 @@
import request from '@/utils/request' import request from '@/utils/request'
let authApi = localStorage.getItem('authApi') + '/api' let authApi = localStorage.getItem('authApi') + '/api'
let loginApi = localStorage.getItem('loginApi')
export function login(data) {
return request({
url: authApi + '/account/login',
method: 'post',
data
})
}
export function logout() { export function logout() {
return request({ return request({
@ -18,10 +11,19 @@ export function logout() {
// faster-new // faster-new
// 登录
export function login(data) {
return request({
url: loginApi + '/CustAccount/login',
method: 'post',
data
})
}
// 获取token // 获取token
export function token(data) { export function token(data) {
return request({ return request({
url: localStorage.getItem('authApi') + '/connect/token', url: authApi + '/connect/token',
method: 'post', method: 'post',
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded'
@ -30,10 +32,10 @@ export function token(data) {
}) })
} }
// 获取用户信息(单点登录) // 通过token获取用户信息(单点登录)
export function getUsersByToken(token) { export function getUsersByToken(token) {
return request({ return request({
url: localStorage.getItem('oidcLogin_url') + '/connect/userinfo', url: loginApi + '/connect/userinfo',
method: 'get', method: 'get',
Token:token Token:token
}) })
@ -78,7 +80,7 @@ export async function getApiDefinition() {
}) })
} }
// *************权限页面维护************* // *************权限Roles页面维护*************
//获取列表 //获取列表
export function getPageListRoles(data) { export function getPageListRoles(data) {
return request({ return request({
@ -106,6 +108,23 @@ export function postCreateRoles(data) {
}) })
} }
//编辑角色
export function postUpdateRoles(data, id) {
return request({
url: authApi+'/identity/roles/' + id,
method: 'put',
data
})
}
//删除角色
export function postDeleteRoles(id) {
return request({
url: authApi + '/identity/roles/' + id,
method: 'delete',
})
}
//保存权限模板 //保存权限模板
export function savePermissionsRoles(URL, data) { export function savePermissionsRoles(URL, data) {
return request({ return request({
@ -114,3 +133,72 @@ export function savePermissionsRoles(URL, data) {
data data
}) })
} }
// 更新权限
export function updatePermissionsGranted(pname,pkey) {
return request({
url: authApi + `/permissions/get-isGranted?name=demox&providerName=${pname}&providerKey=${pkey}`,
method: 'post',
})
}
// *************用户Users页面维护*************
//获取全部用户信息
export function getPageListUsers(data) {
return request({
url: authApi + '/identity/users',
method: 'get',
params: data
})
}
//新建用户
export function postCreateUser(data) {
return request({
url: authApi + '/identity/users',
method: 'post',
data
})
}
//编辑用户
export function postUpdateUser(data, id) {
return request({
url: authApi + '/identity/users/' + id,
method: 'put',
data
})
}
//删除用户
export function postDeleteUser(id) {
return request({
url: authApi + '/identity/users/' + id,
method: 'delete',
})
}
// 获取当前用户的角色
export function usersroles() {
return request({
url: authApi + '/identity/users/assignable-roles',
method: 'get'
})
}
//获取当前角色
export function getusersID(data) {
return request({
url: authApi + '/identity/users/' + data + '/roles',
method: 'get'
})
}
//重置密码
export function resetPassword(id) {
return request({
url: authApi + '/identity/users/reset-password/' + id,
method: 'post'
})
}

351
PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkRoles.vue

@ -45,16 +45,9 @@
prop="name" prop="name"
label="角色名" label="角色名"
sortable="custom" sortable="custom"
width="180" :align="'left'"
align="left"
/> />
<el-table-column <el-table-column label="操作" :align="'center'" width="150">
prop="extraProperties.Description"
label="角色描述"
align="left"
:show-overflow-tooltip="true"
/>
<el-table-column label="操作" align="center" width="150">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
type="text" type="text"
@ -73,8 +66,6 @@
> >
</template> </template>
</el-table-column> </el-table-column>
<!-- <el-table-column prop="address" label="创建时间" />
<el-table-column prop="address" label="编辑" /> -->
</el-table> </el-table>
</div> </div>
<div class="Footer"> <div class="Footer">
@ -97,7 +88,11 @@
> >
</div> </div>
</el-col> </el-col>
<el-col :md="8" v-permission="['AbpIdentity.Roles.Update']"> <el-col
v-loading="treeLoading"
:md="8"
v-permission="['AbpIdentity.Roles.Update']"
>
<el-card class="box-card" shadow="never"> <el-card class="box-card" shadow="never">
<div slot="header" class="clearfix" style="height: 20px"> <div slot="header" class="clearfix" style="height: 20px">
<el-tooltip <el-tooltip
@ -109,24 +104,24 @@
<span class="role-span">{{name}}角色模块权限</span> <span class="role-span">{{name}}角色模块权限</span>
</el-tooltip> </el-tooltip>
<el-button <el-button
:loading="savePerLoading" :loading="treeLoading"
:disabled="multipleSelection.length != 1" :disabled="multipleSelection.length != 1"
icon="el-icon-check" icon="el-icon-check"
size="mini" size="mini"
style="float: right; padding: 6px 9px" style="float: right; padding: 6px 9px"
type="primary" type="primary"
@click="savePer" @click="savePer"
>保存 v-permission="['AbpIdentity.Roles.ManagePermissions']"
</el-button> v-if="name != 'admin'"
>保存</el-button>
</div> </div>
<el-tree <el-tree
ref="tree" ref="tree"
v-loading="treeLoading"
:check-strictly="false" :check-strictly="false"
:data="permissionsData" :data="permissionsData"
:props="defaultProps" :props="defaultProps"
show-checkbox show-checkbox
node-key="id" node-key="name"
class="permission-tree" class="permission-tree"
/> />
</el-card> </el-card>
@ -149,16 +144,6 @@
<el-form-item label="名称" prop="name"> <el-form-item label="名称" prop="name">
<el-input v-model="form.name" style="width: 380px" maxlength="23" /> <el-input v-model="form.name" style="width: 380px" maxlength="23" />
</el-form-item> </el-form-item>
<el-form-item label="描述">
<el-input
type="textarea"
:rows="2"
placeholder="请输入描述信息"
style="width: 380px"
v-model="form.extraProperties.Description"
>
</el-input>
</el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button @click="resetform"> </el-button> <el-button @click="resetform"> </el-button>
@ -170,13 +155,12 @@
<script> <script>
import { import {
getPageListRoles, getPageListRoles,
getpermissionsRoles, getPermissionsRoles,
menuPermissions, savePermissionsRoles,
updatePermissionsGranted,
postCreateRoles, postCreateRoles,
postUpdateRoles, postUpdateRoles,
postDeleteRoles, postDeleteRoles,
putpermissionsRoles,
saveOrUpdateDescribe
} from "@/api/wms-auth"; } from "@/api/wms-auth";
import permission from "@/utils/permission/index"; import permission from "@/utils/permission/index";
import searchNormal from "@/components/searchNormal/index.vue" import searchNormal from "@/components/searchNormal/index.vue"
@ -192,8 +176,6 @@ export default {
URL: 'identity/roles', URL: 'identity/roles',
// //
name: '', name: '',
//
rolesAll: [],
// //
dialogVisible: false, dialogVisible: false,
// //
@ -210,12 +192,6 @@ export default {
pagesize: 20, pagesize: 20,
Sorting: "", Sorting: "",
}, },
// Thecurrent: '',
//
//
// value1: '',
//
// roleList: [],
//ID //ID
usersId: "", usersId: "",
// //
@ -225,14 +201,9 @@ export default {
name: "", name: "",
isDefault: true, isDefault: true,
isPublic: true, isPublic: true,
extraProperties: {
Description: "",
},
}, },
// table // table
tableLoading:false, tableLoading:false,
//
savePerLoading: false,
// //
treeLoading: false, treeLoading: false,
// //
@ -241,7 +212,7 @@ export default {
permissionsData: [], permissionsData: [],
defaultProps: { defaultProps: {
children: "children", children: "children",
label: "name", label: "displayName",
}, },
// //
params: { params: {
@ -269,45 +240,6 @@ export default {
this.pageList(); this.pageList();
}, },
methods: { methods: {
//sort () sort
sortData(sort){
return function(a,b){
const val1 = a[sort];
const val2 = b[sort];
return val1 - val2;
}
},
//
initTreeData(list,code = ""){
const children = []
// list,.parentCode==code,children
list.forEach(item => {
if (item['parentCode'] == code) {
// children.push(item)
children.push(
{
id: item.id,
displayName: item.permission,
name: item.name,
parentCode: item.parentCode,
code: item.code,
sort: item.sort,
children: []
}
)
//
children.find(findItem => findItem.id == item.id).children=this.initTreeData(list,item['code']).sort(this.sortData('sort'))
this.rolesAll.forEach(itemRes => {
if (item.permission == itemRes.name) {
if (itemRes.isGranted) {
this.checkedPermission.push(item.id);
}
}
})
}
})
return children
},
//table //table
pageList(val) { pageList(val) {
const data = { const data = {
@ -335,7 +267,6 @@ export default {
return; return;
} }
this.queryInfo.Sorting = prop + " " + order; this.queryInfo.Sorting = prop + " " + order;
// alert(this.listQuery.Sorting)
this.handleFilter(); this.handleFilter();
}, },
// //
@ -363,7 +294,6 @@ export default {
this.$refs.form.resetFields(); this.$refs.form.resetFields();
this.dialogVisible = false; this.dialogVisible = false;
this.form.name = ""; this.form.name = "";
this.form.extraProperties.Description = "";
this.$refs.multipleTable.clearSelection(); this.$refs.multipleTable.clearSelection();
}, },
// //
@ -388,7 +318,6 @@ export default {
this.usersId = row.id; this.usersId = row.id;
this.form.name = row.name; this.form.name = row.name;
this.concurrencyStamp = row.concurrencyStamp; this.concurrencyStamp = row.concurrencyStamp;
this.form.extraProperties.Description = row.extraProperties.Description;
} }
}, },
// //
@ -405,6 +334,7 @@ export default {
postDeleteRoles(row.id).then((res) => { postDeleteRoles(row.id).then((res) => {
this.$successMsg("删除成功!"); this.$successMsg("删除成功!");
this.pageList(); this.pageList();
this.permissionsData = []
}); });
}) })
.catch(() => {}); .catch(() => {});
@ -416,7 +346,6 @@ export default {
if (valid && !this.isEdit) { if (valid && !this.isEdit) {
postCreateRoles(this.form) postCreateRoles(this.form)
.then((res) => { .then((res) => {
this.saveOrUpdateDescribe(res.id)
this.resetform(); this.resetform();
this.$successMsg("创建成功!"); this.$successMsg("创建成功!");
this.queryInfo.currentPage = 1; this.queryInfo.currentPage = 1;
@ -432,7 +361,6 @@ export default {
postUpdateRoles(data, this.usersId) postUpdateRoles(data, this.usersId)
.then((res) => { .then((res) => {
this.$successMsg("编辑成功!"); this.$successMsg("编辑成功!");
this.saveOrUpdateDescribe(this.usersId)
this.pageList(); this.pageList();
this.resetform(); this.resetform();
}) })
@ -445,149 +373,60 @@ export default {
} }
}); });
}, },
//
saveOrUpdateDescribe (id) {
saveOrUpdateDescribe({description:this.form.extraProperties.Description}, id).then(res => {
// console.log(res)
}).catch(err => {
console.log(err)
})
},
handleSelectionChange(val) { handleSelectionChange(val) {
this.multipleSelection = val; this.multipleSelection = val;
}, },
// //
savePer() { savePer(){
this.savePerLoading = true; let _allList = []
let params = {};
let checkedKeys = this.$refs.tree.getCheckedKeys(); let checkedKeys = this.$refs.tree.getCheckedKeys();
params.permissions = []; this.permissionsData.forEach(item=>{
this.permissionsData.forEach((element) => { //
element.children.forEach((item) => { item.children.forEach(item_menu=>{
let perm = {}; let _Granted1 = checkedKeys.indexOf(item_menu.name) >= 0 ? true : false
perm.name = item.displayName; _allList.push({isGranted:_Granted1,name:item_menu.name})
perm.isGranted = false; //
if (checkedKeys.indexOf(item.id) > -1) { if(item_menu.children){
perm.isGranted = true; item_menu.children.forEach(item_handle=>{
} let _Granted2 = checkedKeys.indexOf(item_handle.name) >= 0 ? true : false
// _allList.push({isGranted:_Granted2,name:item_handle.name})
this.getZSG(item.displayName, params, perm.isGranted) // true
params.permissions.push(perm); if(_Granted2){
item.children.forEach((i) => { _allList.forEach((allItem)=>{
let perm = {}; if(allItem.name == item_handle.parentName){
perm.name = i.displayName; allItem.isGranted = true
perm.isGranted = false; }
if (checkedKeys.indexOf(i.id) > -1) { })
perm.isGranted = true; }
}
//
this.getZSG(i.displayName, params, perm.isGranted)
params.permissions.push(perm);
});
});
});
params.permissions.forEach((item,index) => {
//
if (item.name == 'skip') {
params.permissions.splice(index, 1)
}
// |
if (item.name == 'AbpIdentity.Users' ) {
if (item.isGranted) {
params.permissions.push({
isGranted: true,
name: 'AbpIdentity.Users.Create'
},{
isGranted: true,
name: 'AbpIdentity.Users.Update'
},{
isGranted: true,
name: 'AbpIdentity.Users.Delete'
},{
isGranted: true,
name: 'AbpIdentity.Users.ManagePermissions'
})
} else {
params.permissions.push({
isGranted: false,
name: 'AbpIdentity.Users.Create'
},{
isGranted: false,
name: 'AbpIdentity.Users.Update'
},{
isGranted: false,
name: 'AbpIdentity.Users.Delete'
},{
isGranted: false,
name: 'AbpIdentity.Users.ManagePermissions'
})
}
}
if (item.name == 'AbpIdentity.Roles' ) {
if (item.isGranted) {
params.permissions.push({
isGranted: true,
name: 'AbpIdentity.Roles.Create'
},{
isGranted: true,
name: 'AbpIdentity.Roles.Update'
},{
isGranted: true,
name: 'AbpIdentity.Roles.Delete'
})
} else {
params.permissions.push({
isGranted: false,
name: 'AbpIdentity.Roles.Create'
},{
isGranted: false,
name: 'AbpIdentity.Roles.Update'
},{
isGranted: false,
name: 'AbpIdentity.Roles.Delete'
}) })
} }
} })
})
// *************************
params.permissions.filter((item) => {
if (item.name == 'AbpIdentity.Roles.ManagePermissions' || item.name == 'Auth.UserMenu') {
item.isGranted = true
}
}) })
this.treeLoading = true;
putpermissionsRoles( savePermissionsRoles(
"/permission-management/permissions?providerName=R&providerKey=" + `/permission-management/permissions?providerName=${this.params.providerName}&providerKey=${this.multipleSelection[0].name}`,
this.multipleSelection[0].name, {permissions:_allList}
params
).then((response) => { ).then((response) => {
this.$notify({ updatePermissionsGranted(this.params.providerName,this.multipleSelection[0].name).then(()=>{
title: "成功", this.$notify({
message: "更新成功", title: "成功",
type: "success", message: "更新成功",
duration: 2000, type: "success",
}); duration: 2000,
this.savePerLoading = false; });
}).catch(err=>{ this.treeLoading = false;
this.savePerLoading = false; //
}); if(this.multipleSelection[0].name == this.$store.getters.currentUserInfo.name){
}, location.reload()
//
getZSG(name,params,isGranted) {
if (name !== 'skip') {
this.rolesAll.forEach(item => {
if (item.parentName == name ) {
let perm = {}
perm.name = item.name
perm.isGranted = isGranted
params.permissions.push(perm)
} }
}).catch(()=>{
this.treeLoading = false;
}) })
} }).catch(err=>{
this.treeLoading = false;
});
}, },
//table //table
handleRowClick(row, column, event) { handleRowClick(row, column, event) {
let that = this let that = this
@ -609,50 +448,48 @@ export default {
// } // }
this.params.providerKey = row.name; this.params.providerKey = row.name;
getpermissionsRoles(this.params).then((res) => { getPermissionsRoles(this.params).then((res) => {
this.rolesAll = []
this.permissionsData = []; this.permissionsData = [];
this.checkedPermission = []; this.checkedPermission = [];
// //
res.groups.forEach(itemRes => { res.groups.forEach((itemRes,indexRes) => {
itemRes.children = []
this.permissionsData.push(itemRes)
// todo:使
itemRes.permissions.forEach(item => { itemRes.permissions.forEach(item => {
// if (item.displayName !== '' && item.displayName !== '' && item.displayName !== '' && item.displayName !== '') { if(!item.parentName){
this.rolesAll.push(item) //
// } if(item.isGranted)this.checkedPermission.push(item.name)
this.permissionsData[indexRes].children.push(item)
}else{
//
if(item.isGranted)this.checkedPermission.push(item.name)
this.permissionsData[indexRes].children.forEach((pItem,pindex)=>{
if(pItem.name == item.parentName){
if(!this.permissionsData[indexRes].children[pindex].children)this.permissionsData[indexRes].children[pindex].children = []
this.permissionsData[indexRes].children[pindex].children.push(item)
// childrenflase
if(item.isGranted == false){
if(this.checkedPermission.indexOf(item.parentName) >= 0){
this.checkedPermission.splice(this.checkedPermission.indexOf(item.parentName),1)
}
}
}
})
}
}) })
}) })
let filters = [] that.$nextTick(() => {
filters.push({ that.$refs.tree.setCheckedKeys(this.checkedPermission)
logic: "And",
column: "portal",
action: "==",
value: "0"
}) })
const data = { console.log('拥有权限',this.checkedPermission)
condition: { console.log('菜单树',this.permissionsData)
filters: filters that.treeLoading = false;
}, })
Sorting: "", .catch((err)=>{
SkipCount: 0, this.$errorMsg('暂无更改权限')
MaxResultCount: 1000, that.treeLoading = false;
}; })
menuPermissions(data).then((res) => {
let rs = that.initTreeData(res.items,'').sort(that.sortData('sort'))
rs.forEach(item => {
that.permissionsData.push(item);
})
that.$nextTick(() => {
that.$refs.tree.setCheckedKeys(that.checkedPermission)
})
// console.log('',that.permissionsData)
// console.log('',that.checkedPermission)
// console.log('',that.rolesAll)
that.treeLoading = false;
}).catch((err)=>{
that.treeLoading = false;
console.log(err)
})
});
}, },
}, },
}; };

Loading…
Cancel
Save