角色权限

dev
zhangjinzhe 2024-09-27 20:01:16 +08:00
parent a9e95eeadf
commit b3b8a3a6a9
3 changed files with 84 additions and 41 deletions

View File

@ -96,13 +96,7 @@ const list1 = ref([
{ icon: adpass, title: `已通过(${adpassacount.value})` }
])
const list2 = ref([
{ icon: talkautid, title: '话题审核' },
{ icon: adacaudit, title: '活动审核' },
{ icon: stuaudit, title: '认证审核' },
{ icon: admyactivity, title: '我的活动' },
{ icon: puacti, title: '发布活动' },
{ icon: adcoin, title: '校园币管理' },
{ icon: adgrade, title: '等级管理' }
])
const grid1Click1 = (e) => {
console.log(e);
@ -116,6 +110,10 @@ onLoad(() => {
getCountInfo();
})
onShow(() => {
uni.setTabBarItem({
index: 0,
visible: true
});
proxy.$store.dispatch('webSockerInfo')
getCountInfo();
getUserRoles()
@ -136,55 +134,73 @@ const getCountInfo = () =>{
})
}
const getUserRoles = () => {
const getUserRoles = () => {
const userInfo = uni.getStorageSync('loginUserPost');
let hasKfUser = false;
let hasAuditUser = false;
let hasTaskLevel = false;
if (userInfo && Array.isArray(userInfo.roles)) {
const newList2 = []; // list2
userInfo.roles.forEach(role => {
//
if (role.roleKey === 'kfuser') {
hasKfUser = true;
// tabbar
}
//
if (role.roleKey === 'audituser') {
hasAuditUser = true;
// newList2
newList2.push(
{ icon: talkautid, title: '话题审核' },
{ icon: adacaudit, title: '活动审核' },
{ icon: stuaudit, title: '认证审核' }
);
}
//
if (role.roleKey === 'taskLevel') {
hasTaskLevel = true;
// newList2
newList2.push(
{ icon: adcoin, title: '校园币管理' },
{ icon: adgrade, title: '等级管理' }
);
}
// role roleKey
});
if (hasKfUser && hasAuditUser && hasTaskLevel) {
console.log('全部权限')
}
else if (!hasAuditUser && !hasTaskLevel) {
uni.setTabBarItem({
index: 0,
visible: false
});
}
else if (hasTaskLevel && !hasKfUser && !hasAuditUser) {
// list2
if (hasAuditUser && hasTaskLevel) {
//
list2.value = [
{ icon: adcoin, title: '校园币管理' },
{ icon: adgrade, title: '等级管理' }
...newList2,
{ icon: admyactivity, title: '我的活动' },
{ icon: puacti, title: '发布活动' }
];
quanx.value = false;
uni.setTabBarItem({
index: 1,
visible: false
});
}else{
console.log('拥有全部权限')
}
//
} else {
console.error('loginUserPost 不存在或 roles 不是一个数组');
}
};
} else {
// 使 newList2
list2.value = newList2;
}
// list1 audituser
if (hasAuditUser) {
list1.value = [
{ icon: auditreject, title: `未通过(${auditrejectacount.value})` },
{ icon: adaudit, title: `待审核(${adauditacount.value})` },
{ icon: adpass, title: `已通过(${adpassacount.value})` }
];
} else {
list1.value = [];
}
//
} else {
console.error('loginUserPost 不存在或 roles 不是一个数组');
}
};
// aaa
const grid1Click2 = (e) => {

View File

@ -166,7 +166,7 @@ const loginSuccess = (result) => {
uni.setStorageSync('loginUserPost', res.data)
let hasRequiredRole = false;
res.data.roles.forEach(role => {
if (role.roleKey === 'audituser' || role.roleKey === 'taskLevel') {
if (role.roleKey === 'audituser' || role.roleKey === 'taskLevel') {
hasRequiredRole = true;
}else{
hasRequiredRole = false;
@ -182,10 +182,10 @@ const loginSuccess = (result) => {
visible: true
});
} else {
uni.setTabBarItem({
index: 0,
visible: false
});
// uni.setTabBarItem({
// index: 0,
// visible: false
// });
uni.switchTab({
url: "/pages/message/index"
});

View File

@ -104,6 +104,32 @@ const toadUser = () => {
proxy.$tab.navigateTo('/pages/message/adUser');
}
const getUserRoles = () => {
const userInfo = uni.getStorageSync('loginUserPost');
let hasKfUser = false;
let hasAuditUser = false;
let hasTaskLevel = false;
if (userInfo && Array.isArray(userInfo.roles)) {
userInfo.roles.forEach(role => {
//
if (role.roleKey === 'kfuser') {
hasKfUser = true;
}
if(role.roleKey != 'taskLevel' && role.roleKey != 'audituser'){
// uni.setTabBarItem({
// index: 0,
// visible: false
// });
}
});
//
} else {
console.error('loginUserPost 不存在或 roles 不是一个数组');
}
};
// URL
const avatarUrl = ref("/static/images/icon/tu4-1.jpg");
const useDefaultAvatar = ref(true); // 使
@ -123,6 +149,7 @@ onUnmounted(() => {
// clearInterval(timer);
});
onShow(() => {
getUserRoles()
onWebSocket();
GetListSend();
// timer = setInterval(GetListSend, 60000);