管理端角色判断

dev
zhangjinzhe 2024-09-27 18:14:14 +08:00
parent 809bf85984
commit 49fabaa9a6
3 changed files with 86 additions and 42 deletions

View File

@ -47,6 +47,9 @@
<script setup>
import { getCount } from "@/api/activityInfo/info";
import {
getLoginUserinfo
} from "@/api/talk/post";
import {
ref,
reactive,
@ -104,6 +107,7 @@ const list2 = ref([
const grid1Click1 = (e) => {
console.log(e);
}
onMounted(() => {
getUserRoles()
})
@ -132,46 +136,55 @@ const getCountInfo = () =>{
})
}
//
const getUserRoles = () => {
const userInfo = uni.getStorageSync('loginUserPost');
if (userInfo && Array.isArray(userInfo.roles)) {
userInfo.roles.forEach(role => {
//
if (role.roleKey === 'kfuser') {
uni.setTabBarItem({
index: 0,
visible: false
});
//
} else if (role.roleKey === 'audituser') {
uni.setTabBarItem({
index: 1,
visible: false
});
list2.value = [
{ icon: talkautid, title: '话题审核' },
{ icon: adacaudit, title: '活动审核' },
{ icon: stuaudit, title: '认证审核' },
]
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 === 'audituser') {
hasAuditUser = true;
}
//
if (role.roleKey === 'taskLevel') {
hasTaskLevel = true;
}
//
else if (role.roleKey === 'taskLevel') {
uni.setTabBarItem({
index: 1,
visible: false
});
list2.value = [
{ icon: adcoin, title: '校园币管理' },
{ icon: adgrade, title: '等级管理' }
]
quanx.value = false
}
});
} else {
console.error('loginUserPost 不存在或 roles 不是一个数组');
}
};
if (hasKfUser && hasAuditUser && hasTaskLevel) {
console.log('全部权限')
}
else if (!hasAuditUser && !hasTaskLevel) {
uni.setTabBarItem({
index: 0,
visible: false
});
}
else if (hasTaskLevel && !hasKfUser && !hasAuditUser) {
list2.value = [
{ icon: adcoin, title: '校园币管理' },
{ icon: adgrade, title: '等级管理' }
];
quanx.value = false;
uni.setTabBarItem({
index: 1,
visible: false
});
}else{
console.log('拥有全部权限')
}
//
} else {
console.error('loginUserPost 不存在或 roles 不是一个数组');
}
};
// aaa
const grid1Click2 = (e) => {

View File

@ -59,6 +59,7 @@
<script setup>
import { getCodeImg } from '@/api/login'
import { getUserProfile } from '@/api/system/user.js'
import { useStore } from 'vuex';
const store = useStore();
import { ref, getCurrentInstance, reactive, toRefs } from 'vue';
@ -95,7 +96,6 @@ onLoad((options) => {
getCode()
})
//
function getCode() {
getCodeImg().then(res => {
@ -158,11 +158,41 @@ const pwdLogin = async () => {
//
const loginSuccess = (result) => {
//
proxy.$store.dispatch('GetInfo').then(res => {
proxy.$store.dispatch('getQNDomainInfo')
proxy.$store.dispatch('GetUserInfo');
proxy.$tab.reLaunch('/pages/index')
setTimeout(function(){
getUserProfile().then(res => {
uni.setStorageSync('loginUserPost', res.data)
let hasRequiredRole = false;
res.data.roles.forEach(role => {
if (role.roleKey === 'audituser' || role.roleKey === 'taskLevel') {
hasRequiredRole = true;
}else{
hasRequiredRole = false;
}
});
if (hasRequiredRole) {
// proxy.$tab.reLaunch('/pages/index');
uni.switchTab({
url: "/pages/index"
});
uni.setTabBarItem({
index: 0,
visible: true
});
} else {
uni.setTabBarItem({
index: 0,
visible: false
});
uni.switchTab({
url: "/pages/message/index"
});
}
})
},1000)
})
}

View File

@ -198,7 +198,8 @@ const user = {
commit("SET_ROLES", []);
commit("SET_PERMISSIONS", []);
removeToken();
storage.clean();
// storage.clean();
uni.clearStorage(); // 清除所有存储项
resolve();
})
.catch((error) => {