Просмотр исходного кода

系统指引跳转增加路径错误提示

cyy 3 недель назад
Родитель
Сommit
da6f679f1e

+ 24 - 11
src/views/system/dashboard/components/util.js

@@ -88,7 +88,7 @@ export function buildComponent(name, column, preview, vm) {
           userId,
           userList = [],
           deptList = [],
-          menus,
+          menus = [],
           userInfo
         } = this.$store.getters
         const t1 = deptList.find((i) => i.positionId === first) || {}
@@ -100,7 +100,7 @@ export function buildComponent(name, column, preview, vm) {
           userId,
           userList,
           deptList,
-          menus,
+          menus: menus || [],
           locationName,
           newPng,
           imgOptionsData,
@@ -431,19 +431,28 @@ export function buildComponent(name, column, preview, vm) {
           this.applyCyzxbdTabData()
         },
         findPagePath(res) {
-          const resList = res.split('.')
-          const findAlias = (nodes, path) => {
+          const resList = String(res || '')
+            .split('.')
+            .filter(Boolean)
+          if (!resList.length) return ''
+          const findAlias = (nodes = [], path = []) => {
+            if (!Array.isArray(nodes) || !path.length) return null
             const [currentId, ...rest] = path
-            const node = nodes.find((n) => n.id === currentId)
-            return node && rest.length
-              ? [node.alias, ...findAlias(node.children, rest)]
-              : node && [node.alias]
+            const node = nodes.find(
+              (n) => String(n.id) === String(currentId)
+            )
+            if (!node) return null
+            if (!rest.length) return [node.alias]
+            const childAliases = findAlias(node.children || [], rest)
+            if (!childAliases) return null
+            return [node.alias, ...childAliases]
           }
           this.$store.dispatch('ibps/menu/activeHeaderSet', {
             activeHeader: resList[0],
             vm: this
           })
-          return findAlias(this.menus, resList).join('/')
+          const aliases = findAlias(this.menus || [], resList)
+          return aliases ? aliases.join('/') : ''
         },
         handleCyzxbdClick(data) {
           const { ziYuanLuJing = '' } = data
@@ -451,8 +460,12 @@ export function buildComponent(name, column, preview, vm) {
             this.$message.warning('未配置资源菜单!')
             return
           }
-          const path = '/' + this.findPagePath(ziYuanLuJing)
-          this.$router.push(path)
+          const pagePath = this.findPagePath(ziYuanLuJing)
+          if (!pagePath) {
+            this.$message.warning('未找到对应菜单路径,请检查资源配置或权限!')
+            return
+          }
+          this.$router.push('/' + pagePath)
         },
         formatParameters(data) {
           if (this.$utils.isEmpty(data)) {

+ 20 - 9
src/views/system/dashboard/templates/systemGuide.vue

@@ -382,8 +382,12 @@ export default {
         this.$message.warning('未配置资源菜单!')
         return
       }
-      const path = '/' + this.findPagePath(ziYuanLuJing)
-      this.$router.push(path)
+      const pagePath = this.findPagePath(ziYuanLuJing)
+      if (!pagePath) {
+        this.$message.warning('未找到对应菜单路径,请检查资源配置或权限!')
+        return
+      }
+      this.$router.push('/' + pagePath)
     },
     handleCollectClick(row) {
       if (!this.isSetting) return
@@ -451,19 +455,26 @@ export default {
       }
     },
     findPagePath(res) {
-      const resList = res.split('.')
-      const findAlias = (nodes, path) => {
+      const resList = String(res || '')
+        .split('.')
+        .filter(Boolean)
+      if (!resList.length) return ''
+      const findAlias = (nodes = [], path = []) => {
+        if (!Array.isArray(nodes) || !path.length) return null
         const [currentId, ...rest] = path
-        const node = nodes.find((n) => n.id === currentId)
-        return node && rest.length
-          ? [node.alias, ...findAlias(node.children, rest)]
-          : node && [node.alias]
+        const node = nodes.find((n) => String(n.id) === String(currentId))
+        if (!node) return null
+        if (!rest.length) return [node.alias]
+        const childAliases = findAlias(node.children || [], rest)
+        if (!childAliases) return null
+        return [node.alias, ...childAliases]
       }
       this.$store.dispatch('ibps/menu/activeHeaderSet', {
         activeHeader: resList[0],
         vm: this
       })
-      return findAlias(this.menus, resList).join('/')
+      const aliases = findAlias(this.menus || [], resList)
+      return aliases ? aliases.join('/') : ''
     }
   }
 }