diff --git a/.env.base b/.env.base index 2d3b1b8..19b9a09 100644 --- a/.env.base +++ b/.env.base @@ -4,8 +4,8 @@ VITE_NODE_ENV=development VITE_DEV=true # 请求路径 -# VITE_BASE_URL='http://47.98.161.246:48080' -VITE_BASE_URL='http://114.215.207.150:48080' +VITE_BASE_URL='http://47.98.161.246:48080' +# VITE_BASE_URL='http://114.215.207.150:48080' # 小程序接口请求路劲 VITE_APPLET_URL='https://cloud.ahduima.com' diff --git a/src/permission.js b/src/permission.js index 115c8cd..f0cb6e5 100644 --- a/src/permission.js +++ b/src/permission.js @@ -7,7 +7,8 @@ import { usePageLoading } from '@/hooks/web/usePageLoading' import { useDictStoreWithOut } from '@/store/modules/dict' import { useUserStoreWithOut } from '@/store/modules/user' import { usePermissionStoreWithOut } from '@/store/modules/permission' -import { getTenantId, getAppId } from '@/utils/auth' +import { useAppStoreWithOut } from '@/store/modules/app' +import { getTenantId, getAppId, setTenantId, setAppId } from '@/utils/auth' import cache from '@/plugins/cache' const { start, done } = useNProgress() @@ -39,13 +40,20 @@ router.beforeEach(async (to, from, next) => { } else { if (getAccessToken()) { if (to.path === '/login') { - next({ path: '/' }) + if (to.query?.tenantId && to.query?.appId) { + setApp(to.query.tenantId, to.query.appId) + setTimeout(() => { + next({ path: '/' }) + }, 1500) + } else { + next({ path: '/' }) + } } else { // 获取所有字典 const dictStore = useDictStoreWithOut() const userStore = useUserStoreWithOut() const permissionStore = usePermissionStoreWithOut() - if (!dictStore.getIsSetDict && to.path != '/nm-detail') { + if (!dictStore.getIsSetDict) { await dictStore.setDictMap() } if (!userStore.getIsSetUser) { @@ -72,15 +80,23 @@ router.beforeEach(async (to, from, next) => { const tenantId = getTenantId() const appId = getAppId() if (tenantId && appId) { - next(`/crm/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页 + next(`/oa/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页 } else { - next(`/crm/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 + next(`/oa/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 } } } } }) +function setApp(tenantId, appId) { + setTenantId(tenantId) + + setAppId(appId) + const appStore = useAppStoreWithOut() + appStore.setAppInfo(appId) +} + router.afterEach((to) => { useTitle(to?.meta?.title) done() // 结束Progress diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index fdd7af5..e379939 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -51,14 +51,26 @@ const remainingRouter: AppRouteRecordRaw[] = [ } }, { - path: '', + path: '/', component: Layout, - redirect: '/Home/index', + redirect: '/index', name: '', meta: { - title: '首页', - hidden: true - } + title: '首页' + }, + children: [ + { + path: '/index', + component: () => import('@/views/Home/index.vue'), + name: 'Home', + meta: { + title: '首页', + icon: 'ep:home-filled', + noTagsView: true, + affix: true + } + } + ] }, { path: '/swagger', @@ -137,7 +149,7 @@ const remainingRouter: AppRouteRecordRaw[] = [ // redirect: '/Basic/menu', // children: [ // { - // path: 'menu', + // path: '/menu', // component: () => import('@/views/Basic/Menu/index.vue'), // name: 'Menu', // meta: { diff --git a/src/store/modules/dict.ts b/src/store/modules/dict.ts index bf8126a..37e0852 100644 --- a/src/store/modules/dict.ts +++ b/src/store/modules/dict.ts @@ -45,7 +45,8 @@ export const useDictStore = defineStore('dict', { this.dictMap = dictMap this.isSetDict = true } else { - const res = await listSimpleDictData() + // const res = (await listSimpleDictData()) || [] + const res = [] // 设置数据 const dictDataMap = new Map() res.forEach((dictData: DictDataVO) => { diff --git a/src/utils/auth.ts b/src/utils/auth.ts index f4d9c88..bf91499 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -8,26 +8,34 @@ const RefreshTokenKey = 'REFRESH_TOKEN' // 获取token export const getAccessToken = () => { // 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错 - return cache.local.get(AccessTokenKey) - ? cache.local.get(AccessTokenKey) - : cache.local.get('ACCESS_TOKEN') + return localStorage.getItem(AccessTokenKey) + ? localStorage.getItem(AccessTokenKey) + : localStorage.getItem('ACCESS_TOKEN') + // return cache.local.get(AccessTokenKey) + // ? cache.local.get(AccessTokenKey) + // : cache.local.get('ACCESS_TOKEN') } // 刷新token export const getRefreshToken = () => { - return cache.local.get(RefreshTokenKey) + return localStorage.getItem(RefreshTokenKey) + // return cache.local.get(RefreshTokenKey) } // 设置token export const setToken = (token: TokenType) => { - cache.local.set(RefreshTokenKey, token.refreshToken) - cache.local.set(AccessTokenKey, token.accessToken) + localStorage.setItem(AccessTokenKey, token.accessToken) + localStorage.setItem(RefreshTokenKey, token.refreshToken) + // cache.local.set(RefreshTokenKey, token.refreshToken) + // cache.local.set(AccessTokenKey, token.accessToken) } // 删除token export const removeToken = () => { - cache.local.delete(AccessTokenKey) - cache.local.delete(RefreshTokenKey) + localStorage.removeItem(AccessTokenKey) + localStorage.removeItem(RefreshTokenKey) + // cache.local.delete(AccessTokenKey) + // cache.local.delete(RefreshTokenKey) } /** 格式化token(jwt格式) */