Browse Source

切换为招聘者时有角色无菜单清除企业信息时个人账户信息丢失

Xiao_123 3 months ago
parent
commit
94a6ee8540
3 changed files with 14 additions and 2 deletions
  1. 0 1
      src/permission.js
  2. 4 0
      src/store/user.js
  3. 10 1
      src/views/recruit/enterprise/permissionPrompt/index.vue

+ 0 - 1
src/permission.js

@@ -22,7 +22,6 @@ const ENTERPRISE_PATH = '/recruit/enterprise'
 router.beforeEach(async (to, from, next) => {
   start()
   // 个人端 404 处理
-  // debugger
   if (to.path === '/404') {
     next()
     return

+ 4 - 0
src/store/user.js

@@ -160,6 +160,10 @@ export const useUserStore = defineStore('user',
       },
       // 切换为招聘者
       async changeRole (res) {
+        // 切换企业时需将个人的账户信息另外储存起来,以防企业账户有角色无菜单权限返回首页清除企业信息时个人账户信息丢失
+        const perAccountData = JSON.parse(localStorage.getItem('accountInfo'))
+        localStorage.setItem('perAccountInfo', JSON.stringify(perAccountData))
+
         let data
         if (res?.type === 'emailLogin') {
           data = res

+ 10 - 1
src/views/recruit/enterprise/permissionPrompt/index.vue

@@ -17,8 +17,17 @@ const router = useRouter()
 const handleToHome = async () => {
 	// 退出企业登录
 	await logoutToken(getToken(1))
+	
+	// 有企业id则为求职者切换招聘者
+	// 切换招聘者时已将企业账户信息赋值给accountInfo,现退出企业登录后需将个人账户信息赋值给accountInfo
+	const isChangeRole = localStorage.getItem('enterpriseId')
+	if (isChangeRole) {
+		const perAccountData = JSON.parse(localStorage.getItem('perAccountInfo'))
+		localStorage.setItem('accountInfo', JSON.stringify(perAccountData))
+	} else localStorage.removeItem('accountInfo')
+	
 	// 清除企业相关缓存信息
-	const enterpriseLocalStorage = ['ENT_REFRESH_TOKEN', 'ENT_ACCESS_TOKEN', 'entBaseInfo', 'accountInfo', 'isAdmin', 'enterpriseUserAccount', 'entUpdatePassword', 'emailLoginInfo', 'enterpriseStore', 'enterpriseId']
+	const enterpriseLocalStorage = ['ENT_REFRESH_TOKEN', 'ENT_ACCESS_TOKEN', 'entBaseInfo', 'isAdmin', 'enterpriseUserAccount', 'entUpdatePassword', 'emailLoginInfo', 'enterpriseStore', 'enterpriseId']
 	enterpriseLocalStorage.forEach(e => localStorage.removeItem(e))
 
 	router.push('/')