Browse Source

improve: 首页跳转方法

From-wh 2 years ago
parent
commit
3edfaa7b9a

+ 1 - 1
template/admin/src/components/main/components/header-bar/custom-bread-crumb/custom-bread-crumb.vue

@@ -3,7 +3,7 @@
     <Breadcrumb :style="{ fontSize: `${fontSize}px` }">
       <BreadcrumbItem
         v-for="(item, index) in list"
-        :key="`${item.path}`"
+        :key="index"
         :to="index !== 1 ? item.path : ''"
         v-if="listLast[0].path !== homePath"
       >

+ 25 - 3
template/admin/src/pages/account/login/index.vue

@@ -159,7 +159,7 @@ export default {
     swiperData() {
       loginInfoApi()
         .then((res) => {
-          window.document.title = `${res.data.site_name} - 登录`
+          window.document.title = `${res.data.site_name} - 登录`;
           localStorage.setItem('ADMIN_TITLE', res.data.site_name || '');
           let data = res.data || {};
           this.login_logo = data.login_logo ? data.login_logo : require('@/assets/images/logo.png');
@@ -239,8 +239,10 @@ export default {
 
             this.checkSocket();
           } catch (e) {}
-
-          return this.$router.replace({ path: res.data.menus[0].path || this.$routeProStr + '/' });
+          // console.log(this.findFirstNonNullChildren(res.data.menus), 1111);
+          return this.$router.replace({
+            path: this.findFirstNonNullChildren(res.data.menus).path || this.$routeProStr + '/',
+          });
         })
         .catch((res) => {
           msg();
@@ -252,6 +254,26 @@ export default {
         this.loading = false;
       }, 1000);
     },
+    findFirstNonNullChildren(arr) {
+      // 如果数组为空,返回null
+      if (!arr || arr.length === 0) {
+        return null;
+      }
+      // 找到第一个对象
+      const firstObj = arr[0];
+      // 如果第一个对象没有children属性,返回该对象
+      if (!firstObj.children) {
+        return firstObj;
+      }
+
+      // 如果第一个对象的children属性是数组,
+      // 递归查找children属性中的第一个非null children属性
+      if (Array.isArray(firstObj.children)) {
+        return this.findFirstNonNullChildren(firstObj.children);
+      }
+      // 如果数组中没有非null children属性,返回null
+      return null;
+    },
     checkSocket() {
       getWorkermanUrl().then((res) => {
         let url = res.data.admin;