Explorar o código

token携带判断

lifanagju_citu hai 3 meses
pai
achega
5875c4d966
Modificáronse 6 ficheiros con 15 adicións e 41 borrados
  1. 1 0
      components.d.ts
  2. 2 4
      src/config/axios/service.js
  3. 4 4
      src/hooks/web/useIM.js
  4. 0 1
      src/permission.js
  5. 0 15
      src/store/loginType.js
  6. 8 17
      src/utils/auth.js

+ 1 - 0
components.d.ts

@@ -33,6 +33,7 @@ declare module 'vue' {
     Echarts: typeof import('./src/components/Echarts/index.vue')['default']
     Echarts: typeof import('./src/components/Echarts/index.vue')['default']
     ElCascader: typeof import('element-plus/es')['ElCascader']
     ElCascader: typeof import('element-plus/es')['ElCascader']
     ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
     ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
+    ElTree: typeof import('element-plus/es')['ElTree']
     Empty: typeof import('./src/components/Empty/index.vue')['default']
     Empty: typeof import('./src/components/Empty/index.vue')['default']
     File: typeof import('./src/components/Upload/file.vue')['default']
     File: typeof import('./src/components/Upload/file.vue')['default']
     HeadSearch: typeof import('./src/components/headSearch/index.vue')['default']
     HeadSearch: typeof import('./src/components/headSearch/index.vue')['default']

+ 2 - 4
src/config/axios/service.js

@@ -23,8 +23,6 @@ const errorData = []
 
 
 const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
 const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
 const { result_code, base_url, request_timeout } = config
 const { result_code, base_url, request_timeout } = config
-// const entUrlStr = '/recruit' // 包含这个就是企业接口,特殊的在api function中设置tokenIndex(优先)
-// let isEnterprise = config.url.includes(entUrlStr)
 
 
 // 需要忽略的提示。忽略后,自动 Promise.reject('error')
 // 需要忽略的提示。忽略后,自动 Promise.reject('error')
 const ignoreMsgs = [
 const ignoreMsgs = [
@@ -67,7 +65,7 @@ service.interceptors.request.use(
     config.headers['Accept-Language'] = getCurrentLocaleLang() ?? 'zh_CN'
     config.headers['Accept-Language'] = getCurrentLocaleLang() ?? 'zh_CN'
     // 是否需要设置 token
     // 是否需要设置 token
     let isToken = (config.headers || {}).isToken === false
     let isToken = (config.headers || {}).isToken === false
-    // token类型
+    // token类型. api》function中设置tokenIndex(优先)
     const tokenIndex = config.tokenIndex ? config.tokenIndex : getIsEnterprise() ? 1 : 2
     const tokenIndex = config.tokenIndex ? config.tokenIndex : getIsEnterprise() ? 1 : 2
     console.log('令牌类型', tokenIndex === 1 ? '企业:' : '个人:', getToken(tokenIndex))
     console.log('令牌类型', tokenIndex === 1 ? '企业:' : '个人:', getToken(tokenIndex))
     whiteList.some((v) => {
     whiteList.some((v) => {
@@ -208,7 +206,7 @@ service.interceptors.response.use(
     }
     }
     if (code === 401) {
     if (code === 401) {
       // 如果未认证,并且未进行刷新令牌,说明可能是访问令牌过期了
       // 如果未认证,并且未进行刷新令牌,说明可能是访问令牌过期了
-      // token类型
+      // token类型. api》function中设置tokenIndex(优先)
       const tokenIndex = config.tokenIndex ? config.tokenIndex : getIsEnterprise() ? 1 : 2
       const tokenIndex = config.tokenIndex ? config.tokenIndex : getIsEnterprise() ? 1 : 2
 
 
       if (!isRefreshToken) {
       if (!isRefreshToken) {

+ 4 - 4
src/hooks/web/useIM.js

@@ -6,7 +6,7 @@ import { getConversationSync, getMessageSync, getChatKey, setUnread, deleteConve
 import { Base64 } from 'js-base64'
 import { Base64 } from 'js-base64'
 
 
 import { useUserStore } from '@/store/user'
 import { useUserStore } from '@/store/user'
-import { isEnterprise } from '@/utils/auth'
+import { getIsEnterprise } from '@/utils/auth'
 import { useIMStore } from '@/store/im'
 import { useIMStore } from '@/store/im'
 
 
 
 
@@ -97,7 +97,7 @@ export function useDataSource () {
     const query = {
     const query = {
       msg_count: 1
       msg_count: 1
     }
     }
-    if (isEnterprise()) {
+    if (getIsEnterprise()) {
       Object.assign(query, { enterpriseId: userStore.entBaseInfo.enterpriseId })
       Object.assign(query, { enterpriseId: userStore.entBaseInfo.enterpriseId })
     }
     }
     const resultConversations = []
     const resultConversations = []
@@ -130,7 +130,7 @@ export function useDataSource () {
       limit,
       limit,
       pull_mode,
       pull_mode,
     }
     }
-    if (isEnterprise()) {
+    if (getIsEnterprise()) {
       Object.assign(query, { enterpriseId: userStore.entBaseInfo.enterpriseId })
       Object.assign(query, { enterpriseId: userStore.entBaseInfo.enterpriseId })
     }
     }
     const resp = await getMessageSync(query)
     const resp = await getMessageSync(query)
@@ -159,7 +159,7 @@ async function getKey () {
     // userId: userStore.accountInfo.userId
     // userId: userStore.accountInfo.userId
     userId: JSON.parse(localStorage.getItem('accountInfo')).userId
     userId: JSON.parse(localStorage.getItem('accountInfo')).userId
   }
   }
-  if (isEnterprise()) {
+  if (getIsEnterprise()) {
     Object.assign(keyQuery, { enterpriseId: userStore.entBaseInfo.enterpriseId })
     Object.assign(keyQuery, { enterpriseId: userStore.entBaseInfo.enterpriseId })
     console.log('企业模式', keyQuery)
     console.log('企业模式', keyQuery)
   }
   }

+ 0 - 1
src/permission.js

@@ -19,7 +19,6 @@ let isRefresh = true
 //            3.personalCommon: 无需登录也能访问的页面
 //            3.personalCommon: 无需登录也能访问的页面
 // 路由守卫
 // 路由守卫
 router.beforeEach(async (to, from, next) => {
 router.beforeEach(async (to, from, next) => {
-  localStorage.setItem('routerTest', to.path) // 本地环境保存代码热更新会导致路径缺失问题
   // 获取商城装修模版
   // 获取商城装修模版
   const mallStore = useMallStore()
   const mallStore = useMallStore()
   const enterpriseStore = useEnterpriseStore()
   const enterpriseStore = useEnterpriseStore()

+ 0 - 15
src/store/loginType.js

@@ -1,15 +0,0 @@
-import { defineStore } from 'pinia'
-import { isEnterprise } from '@/utils/auth'
-
-export const useLoginType = defineStore('changeLoginType', {
-  state: () => ({
-    // loginType: 0
-    loginType: isEnterprise() ? 'enterprise' : 'personal'
-  }),
-  actions: {
-    change(type) {
-      this.loginType = type
-      localStorage.setItem('loginType', type) // 用户登录类型,0:企业, 1:用户
-    }
-  }
-})

+ 8 - 17
src/utils/auth.js

@@ -1,23 +1,14 @@
-import router from '@/router'
+const ENTERPRISE_PATH = '/recruit/enterprise'
 
 
-export const isEnterprise = () => {
-  const currentRoute = router.currentRoute.value
-  const substr = '/recruit/enterprise'
-
-  // 判断是否是企业路由
-  let bool = currentRoute?.path?.includes(substr)
-  if (currentRoute?.path === '/enterpriseVerification') bool = true
-
-  // 本地环境保存代码热更新会导致路径缺失问题
-  const testUsePath = localStorage.getItem('routerTest')
-  if (currentRoute?.path === '/' && (testUsePath?.includes(substr) || testUsePath?.includes('/enterpriseVerification'))) bool = true
-  // console.log('currentRoute', currentRoute.path)
-  console.log('=========================', bool, currentRoute.path, testUsePath)
-  return bool
+// 是否是企业路由
+export const getIsEnterprise = () => {
+  const PATH_NAME = window.location.pathname
+  if (PATH_NAME === '/enterpriseVerification') {
+    return true
+  }
+  return PATH_NAME.includes(ENTERPRISE_PATH)
 }
 }
 
 
-export const getIsEnterprise = () => { return isEnterprise() } // 是否是企业路由
-
 // 获取token
 // 获取token
 export const getToken = (index = 2) => { // index=1: 使用招聘token; index=2: 使用求职token
 export const getToken = (index = 2) => { // index=1: 使用招聘token; index=2: 使用求职token
   const arr = ['ENT_ACCESS_TOKEN', 'PER_ACCESS_TOKEN']
   const arr = ['ENT_ACCESS_TOKEN', 'PER_ACCESS_TOKEN']