Forráskód Böngészése

handle deep menu auto jump to leaf descendant

hare8999@163.com 2 éve
szülő
commit
54fe9b3f33

+ 4 - 1
src/components/Top/index.vue

@@ -48,8 +48,10 @@
 import auth from "@/utils/auth";
 import { mapGetters } from "vuex";
 import { changeRole } from "@/api/login.js";
+import RouterHelpMixin from '@/router/router-help-mixin'
 
 export default {
+  mixins: [RouterHelpMixin],
   data() {
     return {
       app: false,
@@ -169,7 +171,7 @@ export default {
           path: item.path,
         });
       }
-      let path = this.gouAction(routesTo);
+      let path = this.findLeafDescendantPath(data);
       if (path) {
         this.$router.push({
           path: path,
@@ -192,6 +194,7 @@ export default {
       return path;
     },
     gouAction(data) {
+      // 22.6.7 hht 作废此方法,只处理了有限级跳转
       if (data && data.length > 0) {
         if (data[0].children && data[0].children.length > 0) {
           if (

+ 4 - 1
src/components/TopNav/index.vue

@@ -116,8 +116,10 @@ import path from 'path'
 import auth from '@/utils/auth'
 import Cookies from 'js-cookie'
 import { mapGetters } from 'vuex'
+import RouterHelpMixin from '@/router/router-help-mixin'
 
 export default {
+  mixins: [RouterHelpMixin],
   data() {
     return {
       // 顶部栏初始数
@@ -310,7 +312,7 @@ export default {
         auth.setMenuListAction(actionMenu)
       } else {
         console.log('routes', routes)
-        let path = this.gouAction(routes)
+        let path = this.findLeafDescendantPath(routes)
         if (path) {
           this.$router.push({ path: path })
           auth.setMenuListAction(path)
@@ -319,6 +321,7 @@ export default {
       }
     },
     gouAction(data) {
+      // 22.6.7 hht 作废此方法,只处理了有限级跳转
       if (data && data.length > 0) {
         if (data[0].children && data[0].children.length > 0) {
           if (

+ 15 - 0
src/router/router-help-mixin.js

@@ -0,0 +1,15 @@
+export default {
+  methods: {
+    findLeafDescendantPath(routeData, ancestorPath = '') {
+      if (!routeData) return ''
+      if (Array.isArray(routeData)) return this.findLeafDescendantPath(routeData.first())
+      const currentPath = routeData.path.startsWith('/')
+        ? routeData.path
+        : ancestorPath + '/' + routeData.path
+      if (!routeData.children?.length) {
+        return currentPath
+      }
+      return this.findLeafDescendantPath(routeData.children.first(), currentPath)
+    }
+  }
+}

+ 5 - 1
src/views/login.vue

@@ -179,7 +179,10 @@ import * as loginAxios from "@/api/login";
 import * as system from "@/api/webApi/system";
 import forgetPassword from "./components/forget-pwd.vue";
 import CompleteProfile from "./components/complete-profile.vue";
+import RouterHelpMixin from '@/router/router-help-mixin'
+
 export default {
+    mixins: [RouterHelpMixin],
     components: {
         forgetPassword,
         CompleteProfile,
@@ -365,6 +368,7 @@ export default {
             }
         },
         gouAction(data) {
+          // 22.6.7 hht 作废此方法,只处理了有限级跳转
             if (data && data.length > 0) {
                 if (data[0].children && data[0].children.length > 0) {
                     if (
@@ -425,7 +429,7 @@ export default {
                     path: item.path,
                 });
             }
-            let path = this.gouAction(routesTo);
+            let path = this.findLeafDescendantPath(data)
             if (path) {
                 this.$router.push({
                     path: path,