ZaiZai пре 1 година
родитељ
комит
ad4545ef85
2 измењених фајлова са 26 додато и 7 уклоњено
  1. 5 2
      src/store/modules/app.js
  2. 21 5
      src/store/modules/user.js

+ 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'
 import website from '~src/config/index'
@@ -98,7 +99,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 []
     }
     //处理合同段的别名
@@ -115,7 +117,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)

+ 21 - 5
src/store/modules/user.js

@@ -7,7 +7,7 @@ import tokenData from '~src/router/modules/token'
 import { getStoreValue, setStoreValue } from '~src/utils/storage'
 import { logout, refreshToken, userLogin } from '~api/user'
 import { userConfigInfo, userConfigSave } from '~api/other'
-import { ArrToOneObj, arrIndex, getArrValue, getObjValue } from 'js-fast-way'
+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'
@@ -127,19 +127,35 @@ export const setRouterData = async () => {
 
 //获取路由菜单的主入口路径
 const getHomeRouter = async () => {
-    const routes = getStoreValue('routesArr') ?? []
+    const routesArr = getStoreValue('routesArr') ?? []
+    const routes = store.menus
     //没有菜单路由数据
-    if (routes.length <= 0) {
+    if (routesArr.length <= 0 || routes.length <= 0) {
         store.setHomeUrl('home')
         return 'home'
     }
     //设置主入口
-    const isUsingStats = routes.indexOf('using-stats')
-    const code = isUsingStats !== -1 ? 'using-stats' : routes[0]
+    const isUsingStats = routesArr.indexOf('using-stats')
+    if (isUsingStats !== -1) {
+        store.setHomeUrl('using-stats')
+        return 'using-stats'
+    }
+    //没有或不存在
+    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
+    }
+}
+
 //刷新token
 export const RefreshToken = async () => {
     try {