1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import router from '@/router'
- 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('isEnterpriseBool', bool)
- return bool
- }
- export const getIsEnterprise = () => { return isEnterprise() } // 是否是企业路由
- // 获取token
- export const getToken = (index = 2) => { // index=1: 使用招聘token; index=2: 使用求职token
- const arr = ['ENT_ACCESS_TOKEN', 'PER_ACCESS_TOKEN']
- return localStorage.getItem(arr[index-1])
- }
- // 设置token
- export const setToken = (token, index = 2) => { // index=1: 招聘token; index=2: 求职token
- return localStorage.setItem((index === 1 ? 'ENT_ACCESS_TOKEN' : 'PER_ACCESS_TOKEN'), token)
- }
- // 清除token
- export const removeToken = () => {
- localStorage.removeItem('ENT_ACCESS_TOKEN')
- localStorage.removeItem('PER_ACCESS_TOKEN')
- localStorage.removeItem('ENT_REFRESH_TOKEN')
- localStorage.removeItem('PER_REFRESH_TOKEN')
- }
- // 获取刷新token
- export const getRefreshToken = (index) => {
- return localStorage.getItem(index === 1 ? 'ENT_REFRESH_TOKEN' : 'PER_REFRESH_TOKEN')
- }
- // 设置刷新token
- export const setRefreshToken = (refreshToken, index = 2) => { // index=1: 招聘token; index=2: 求职token
- return localStorage.setItem((index === 1 ? 'ENT_REFRESH_TOKEN' : 'PER_REFRESH_TOKEN'), refreshToken)
- }
- // 租户ID
- export const getTenantId = () => {
- return localStorage.getItem('tenantId')
- }
- export const setTenantId = (username) => {
- localStorage.setItem('tenantId', username)
- }
|