用户身份切换

This commit is contained in:
熊丽君
2022-02-25 11:49:49 +08:00
parent d9ed341af9
commit dba078f637
10 changed files with 75 additions and 17 deletions

View File

@ -1,5 +1,5 @@
# 页面标题
VITE_APP_TITLE = 1管理系统
VITE_APP_TITLE = v1xxx管理系统
# 开发环境配置
VITE_APP_ENV = 'development'

View File

@ -12,6 +12,14 @@ export function settled() {
url: '/enterprise/v1/settled'
});
}
// 当前状态切换
export function identitySwitch(data) {
return request({
url: '/enterprise/v1/user/identity/switch',
method:'post',
data
});
}
// 公司企业入驻
export function company(data) {
return request({

View File

@ -106,9 +106,11 @@
</div>
<template #dropdown>
<el-dropdown-menu>
<router-link to="/identity/index">
<el-dropdown-item>个人中心</el-dropdown-item>
</router-link>
<!-- <router-link to="/identity/index"> -->
<el-dropdown-item @click="handlePage"
>个人中心</el-dropdown-item
>
<!-- </router-link> -->
<el-dropdown-item divided @click="logout">
<span>退出登录</span>
</el-dropdown-item>
@ -143,7 +145,16 @@ watch(
pagePath.value = route.path;
function handlePage() {
router.push("/identity/index");
// router.push("/identity/index");
let routeData = "";
const selectRole = localStorage.getItem("select_identity");
if (selectRole > 0) {
routeData = router.resolve({ path: "/admin" });
} else {
routeData = router.resolve({ path: "/identity/index" });
}
window.open(routeData.href, "_blank");
}
function handlePath(path) {

View File

@ -58,8 +58,16 @@ defineProps({
required: true,
},
});
const title = ref("这是xx管理系统");
const route = useRoute();
const selectRole = localStorage.getItem("select_identity");
const roles = {
1: "企业",
2: "专家",
4: "研究机构",
8: "实验室",
16: "科技经纪人",
};
const title = ref(`${roles[selectRole]}管理系统`);
const store = useStore();
const sideTheme = computed(() => store.state.settings.sideTheme);
</script>

View File

@ -13,7 +13,7 @@ const whiteList = ['/login', '/auth-redirect', '/bind', '/register'];
router.beforeEach((to, from, next) => {
NProgress.start()
// 跳过登录验证
next();
// next();
if (getToken()) {
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
/* has token*/
@ -27,6 +27,7 @@ router.beforeEach((to, from, next) => {
// 判断当前用户是否已拉取完user_info信息
store.dispatch('GetInfo').then((res) => {
store.dispatch('GenerateRoutes',res.data.select_identity).then(accessRoutes => {
// store.dispatch('GenerateRoutes',0).then(accessRoutes => { // 测试
// 根据roles权限生成可访问的路由表
// accessRoutes.forEach(route => {
// if (!isHttp(route.path)) {

View File

@ -277,14 +277,32 @@ export const constantRoutes = [
export const enterpriseRoutes = [
{
path: '/one',
path: '/technology',
component: Layout,
meta: { title: '技术管理', icon: 'dashboard' },
alwaysShow:true,
redirect: 'noRedirect',
children: [
{
path: 'enterprise',
component: () => import('@/views/admin/one/index'),
name: 'Enterprise',
meta: { title: '账号管理', icon: 'dashboard' }
path: 'achievement',
component: ParentView,
meta: { title: '成果列表', icon: 'list' },
alwaysShow:true,
redirect: 'noRedirect',
children:[
{
path: 'release',
component: () => import('@/views/admin/two/technology/release'),
name: 'release',
meta: { title: '发布成果', icon: 'dashboard' }
}
]
},
{
path: 'research',
component: () => import('@/views/admin/two/technology/research'),
name: 'Research',
meta: { title: '科研项目列表', icon: 'dashboard' }
}
]
},

View File

@ -40,6 +40,7 @@ const permission = {
GenerateRoutes({ commit },role) {
return new Promise(resolve => {
let data = []
// localStorage.setItem('select_identity',role) // 测试
if (role == 1) {
// 企业
data = enterpriseRoutes

View File

@ -63,6 +63,7 @@ const user = {
commit('SET_NAME', res.data.name)
commit('SET_AVATAR', avatar)
localStorage.setItem('select_identity',res.data.select_identity)
// localStorage.setItem('select_identity',0) // 测试
resolve(res)
}).catch(error => {
reject(error)

View File

@ -28,7 +28,7 @@ export default {
},
chartData: {
type: Object,
required: true,
// required: true,
},
},
data() {

View File

@ -51,7 +51,8 @@
</div>
</template>
<script setup>
import { identity, settled } from "@/api/identity/index";
import store from "@/store";
import { identity, settled, identitySwitch } from "@/api/identity/index";
const router = useRouter();
const identityList = ref([]);
onMounted(() => {
@ -107,7 +108,7 @@ function handlePage(item) {
let routeData = "";
if (item.id == 1) {
// 企业
routeData = router.resolve({ path: "/one" });
routeData = router.resolve({ path: "/admin" });
} else if (item.id == 2) {
// 专家
routeData = router.resolve({ path: "/admin" });
@ -121,6 +122,15 @@ function handlePage(item) {
// 科技经纪人
routeData = router.resolve({ path: "/five" });
}
window.open(routeData.href, "_blank");
// return window.open(routeData.href, "_blank");
// TODO ...... 切换身份待处理
identitySwitch({ identity: item.id - 0 }).then((res) => {
console.log(res);
window.open(routeData.href, "_blank");
});
// store.dispatch("GenerateRoutes", 1).then(() => {
// console.log(localStorage.getItem("select_identity"));
// window.open(routeData.href, "_blank");
// });
}
</script>