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'
let authApi = localStorage.getItem('authApi') + '/api'
export function login(data) {
return request({
url: authApi + '/account/login',
method: 'post',
data
})
}
let loginApi = localStorage.getItem('loginApi')
export function logout() {
return request({
@ -18,10 +11,19 @@ export function logout() {
// faster-new
// 登录
export function login(data) {
return request({
url: loginApi + '/CustAccount/login',
method: 'post',
data
})
}
// 获取token
export function token(data) {
return request({
url: localStorage.getItem('authApi') + '/connect/token',
url: authApi + '/connect/token',
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
@ -30,10 +32,10 @@ export function token(data) {
})
}
// 获取用户信息(单点登录)
// 通过token获取用户信息(单点登录)
export function getUsersByToken(token) {
return request({
url: localStorage.getItem('oidcLogin_url') + '/connect/userinfo',
url: loginApi + '/connect/userinfo',
method: 'get',
Token:token
})
@ -78,7 +80,7 @@ export async function getApiDefinition() {
})
}
// *************权限页面维护*************
// *************权限Roles页面维护*************
//获取列表
export function getPageListRoles(data) {
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) {
return request({
@ -114,3 +133,72 @@ export function savePermissionsRoles(URL, 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"
label="角色名"
sortable="custom"
width="180"
align="left"
:align="'left'"
/>
<el-table-column
prop="extraProperties.Description"
label="角色描述"
align="left"
:show-overflow-tooltip="true"
/>
<el-table-column label="操作" align="center" width="150">
<el-table-column label="操作" :align="'center'" width="150">
<template slot-scope="scope">
<el-button
type="text"
@ -73,8 +66,6 @@
>
</template>
</el-table-column>
<!-- <el-table-column prop="address" label="创建时间" />
<el-table-column prop="address" label="编辑" /> -->
</el-table>
</div>
<div class="Footer">
@ -97,7 +88,11 @@
>
</div>
</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">
<div slot="header" class="clearfix" style="height: 20px">
<el-tooltip
@ -109,24 +104,24 @@
<span class="role-span">{{name}}角色模块权限</span>
</el-tooltip>
<el-button
:loading="savePerLoading"
:loading="treeLoading"
:disabled="multipleSelection.length != 1"
icon="el-icon-check"
size="mini"
style="float: right; padding: 6px 9px"
type="primary"
@click="savePer"
>保存
</el-button>
v-permission="['AbpIdentity.Roles.ManagePermissions']"
v-if="name != 'admin'"
>保存</el-button>
</div>
<el-tree
ref="tree"
v-loading="treeLoading"
:check-strictly="false"
:data="permissionsData"
:props="defaultProps"
show-checkbox
node-key="id"
node-key="name"
class="permission-tree"
/>
</el-card>
@ -149,16 +144,6 @@
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" style="width: 380px" maxlength="23" />
</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>
<div slot="footer" class="dialog-footer">
<el-button @click="resetform"> </el-button>
@ -170,13 +155,12 @@
<script>
import {
getPageListRoles,
getpermissionsRoles,
menuPermissions,
getPermissionsRoles,
savePermissionsRoles,
updatePermissionsGranted,
postCreateRoles,
postUpdateRoles,
postDeleteRoles,
putpermissionsRoles,
saveOrUpdateDescribe
} from "@/api/wms-auth";
import permission from "@/utils/permission/index";
import searchNormal from "@/components/searchNormal/index.vue"
@ -192,8 +176,6 @@ export default {
URL: 'identity/roles',
//
name: '',
//
rolesAll: [],
//
dialogVisible: false,
//
@ -210,12 +192,6 @@ export default {
pagesize: 20,
Sorting: "",
},
// Thecurrent: '',
//
//
// value1: '',
//
// roleList: [],
//ID
usersId: "",
//
@ -225,14 +201,9 @@ export default {
name: "",
isDefault: true,
isPublic: true,
extraProperties: {
Description: "",
},
},
// table
tableLoading:false,
//
savePerLoading: false,
//
treeLoading: false,
//
@ -241,7 +212,7 @@ export default {
permissionsData: [],
defaultProps: {
children: "children",
label: "name",
label: "displayName",
},
//
params: {
@ -269,45 +240,6 @@ export default {
this.pageList();
},
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
pageList(val) {
const data = {
@ -335,7 +267,6 @@ export default {
return;
}
this.queryInfo.Sorting = prop + " " + order;
// alert(this.listQuery.Sorting)
this.handleFilter();
},
//
@ -363,7 +294,6 @@ export default {
this.$refs.form.resetFields();
this.dialogVisible = false;
this.form.name = "";
this.form.extraProperties.Description = "";
this.$refs.multipleTable.clearSelection();
},
//
@ -388,7 +318,6 @@ export default {
this.usersId = row.id;
this.form.name = row.name;
this.concurrencyStamp = row.concurrencyStamp;
this.form.extraProperties.Description = row.extraProperties.Description;
}
},
//
@ -405,6 +334,7 @@ export default {
postDeleteRoles(row.id).then((res) => {
this.$successMsg("删除成功!");
this.pageList();
this.permissionsData = []
});
})
.catch(() => {});
@ -416,7 +346,6 @@ export default {
if (valid && !this.isEdit) {
postCreateRoles(this.form)
.then((res) => {
this.saveOrUpdateDescribe(res.id)
this.resetform();
this.$successMsg("创建成功!");
this.queryInfo.currentPage = 1;
@ -432,7 +361,6 @@ export default {
postUpdateRoles(data, this.usersId)
.then((res) => {
this.$successMsg("编辑成功!");
this.saveOrUpdateDescribe(this.usersId)
this.pageList();
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) {
this.multipleSelection = val;
},
//
savePer() {
this.savePerLoading = true;
let params = {};
savePer(){
let _allList = []
let checkedKeys = this.$refs.tree.getCheckedKeys();
params.permissions = [];
this.permissionsData.forEach((element) => {
element.children.forEach((item) => {
let perm = {};
perm.name = item.displayName;
perm.isGranted = false;
if (checkedKeys.indexOf(item.id) > -1) {
perm.isGranted = true;
}
//
this.getZSG(item.displayName, params, perm.isGranted)
params.permissions.push(perm);
item.children.forEach((i) => {
let perm = {};
perm.name = i.displayName;
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'
this.permissionsData.forEach(item=>{
//
item.children.forEach(item_menu=>{
let _Granted1 = checkedKeys.indexOf(item_menu.name) >= 0 ? true : false
_allList.push({isGranted:_Granted1,name:item_menu.name})
//
if(item_menu.children){
item_menu.children.forEach(item_handle=>{
let _Granted2 = checkedKeys.indexOf(item_handle.name) >= 0 ? true : false
_allList.push({isGranted:_Granted2,name:item_handle.name})
// true
if(_Granted2){
_allList.forEach((allItem)=>{
if(allItem.name == item_handle.parentName){
allItem.isGranted = true
}
})
}
})
}
}
})
// *************************
params.permissions.filter((item) => {
if (item.name == 'AbpIdentity.Roles.ManagePermissions' || item.name == 'Auth.UserMenu') {
item.isGranted = true
}
})
})
putpermissionsRoles(
"/permission-management/permissions?providerName=R&providerKey=" +
this.multipleSelection[0].name,
params
this.treeLoading = true;
savePermissionsRoles(
`/permission-management/permissions?providerName=${this.params.providerName}&providerKey=${this.multipleSelection[0].name}`,
{permissions:_allList}
).then((response) => {
this.$notify({
title: "成功",
message: "更新成功",
type: "success",
duration: 2000,
});
this.savePerLoading = false;
}).catch(err=>{
this.savePerLoading = false;
});
},
//
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)
updatePermissionsGranted(this.params.providerName,this.multipleSelection[0].name).then(()=>{
this.$notify({
title: "成功",
message: "更新成功",
type: "success",
duration: 2000,
});
this.treeLoading = false;
//
if(this.multipleSelection[0].name == this.$store.getters.currentUserInfo.name){
location.reload()
}
}).catch(()=>{
this.treeLoading = false;
})
}
}).catch(err=>{
this.treeLoading = false;
});
},
//table
handleRowClick(row, column, event) {
let that = this
@ -609,50 +448,48 @@ export default {
// }
this.params.providerKey = row.name;
getpermissionsRoles(this.params).then((res) => {
this.rolesAll = []
getPermissionsRoles(this.params).then((res) => {
this.permissionsData = [];
this.checkedPermission = [];
//
res.groups.forEach(itemRes => {
res.groups.forEach((itemRes,indexRes) => {
itemRes.children = []
this.permissionsData.push(itemRes)
// todo:使
itemRes.permissions.forEach(item => {
// if (item.displayName !== '' && item.displayName !== '' && item.displayName !== '' && item.displayName !== '') {
this.rolesAll.push(item)
// }
if(!item.parentName){
//
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 = []
filters.push({
logic: "And",
column: "portal",
action: "==",
value: "0"
that.$nextTick(() => {
that.$refs.tree.setCheckedKeys(this.checkedPermission)
})
const data = {
condition: {
filters: filters
},
Sorting: "",
SkipCount: 0,
MaxResultCount: 1000,
};
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)
})
});
console.log('拥有权限',this.checkedPermission)
console.log('菜单树',this.permissionsData)
that.treeLoading = false;
})
.catch((err)=>{
this.$errorMsg('暂无更改权限')
that.treeLoading = false;
})
},
},
};

Loading…
Cancel
Save