ZaiZai 7 сар өмнө
parent
commit
0d3ba167a5

+ 5 - 2
src/store/modules/app.js

@@ -2,6 +2,7 @@ import pinia from '~src/store/init'
 import { useAppStore } from '~src/store'
 import { getButtons } from '~api/menu'
 import projectApi from '~api/project'
+import router from '~src/router/index'
 import { getStoreValue } from '~src/utils/storage'
 import { ArrToOneObj, getArrValue, getObjVal, getObjValue, isNullES } from 'js-fast-way'
 
@@ -96,7 +97,8 @@ const setProjectStore = (project, contract) => {
 const getProjectArr = async (error, data) => {
     let projectList = getArrValue(data)
     if (error || projectList.length <= 0) {
-        window.$message?.error('没有相关项目权限')
+        window.$messageBox.alert('您账户下还没有任何项目,请先联系管理员给你配置相关项目', '登录失败')
+        router.push({ path: '/login-main' })
         return []
     }
     //处理合同段的别名
@@ -113,7 +115,8 @@ const getProjectArr = async (error, data) => {
         return contractList.length > 0
     })
     if (projectArr.length <= 0) {
-        window.$message?.error('没有相关项目权限')
+        window.$messageBox.alert('您账户下还没有任何项目,请先联系管理员给你配置相关项目', '登录失败')
+        router.push({ path: '/login-main' })
         return []
     }
     store.setProjectContract(projectArr)

+ 17 - 7
src/store/modules/user.js

@@ -7,8 +7,8 @@ import themeData from '~src/config/theme'
 import tokenData from '~src/router/modules/token'
 import { logout, refreshToken, userLogin } from '~api/user'
 import { userConfigInfo, userConfigSave } from '~api/other'
-import { getStoreValue, setStoreValue } from '~src/utils/storage'
-import { ArrToOneObj, arrIndex, getArrValue, getObjValue } from 'js-fast-way'
+import { setStoreValue } from '~src/utils/storage'
+import { ArrToOneObj, arrIndex, getArrValue, getObjValue, isNullES } from 'js-fast-way'
 import { useOsTheme } from 'hc-vue3-ui'
 import { setAppName } from '~uti/tools'
 import logoIcon from '~src/assets/logo/icon.png'
@@ -72,16 +72,26 @@ export const setUserTenantInfo = async (res = {}) => {
 
 //获取路由菜单的主入口路径
 const getHomeRouter = async () => {
-    const routes = getStoreValue('routesArr') ?? []
+    const routes = store.menus
     //没有菜单路由数据
     if (routes.length <= 0) {
         store.setHomeUrl('home')
         return 'home'
+    } else {
+        const code = await getRoutesHomeUrl(routes)
+        store.setHomeUrl(code)
+        return code
+    }
+}
+
+//递归获取最子级的菜单
+const getRoutesHomeUrl = async (arr) => {
+    const item = arr[0]
+    if (!isNullES(item.children) && item.children.length > 0) {
+        return await getRoutesHomeUrl(item.children)
+    } else {
+        return item.code
     }
-    //设置主入口
-    const code = routes[0]
-    store.setHomeUrl(code)
-    return code
 }
 
 //用户信息初始化

+ 1 - 0
src/views/login/index.vue

@@ -133,6 +133,7 @@ const formValidateClick = async () => {
     window?.$message?.success('登录成功')
     setTimeout(() => {
         loading.value = false
+        console.log(userStore.homeUrl)
         router.push({ name: userStore.homeUrl })
     }, 1500)
 }