从一个页面跳转到目标页面之后,对应的顶部路由高亮

news2024/9/28 1:19:59

需求:页面跳转到目标页面之后,对应的顶部路由高亮 

上面的更多 跳转到 学情分析下面的学生分析

<template>
  <div class="topBar" ref="topBar" v-loading.fullscreen.lock="fullscreenLoading">
    <div class="topBar-navi">
      <div class="top-menu container">
        <div class="myMenu">
          <img :src="logo" alt="" />

          <!-- S2路由改造 -->
          <div class="parentRoute">
            <span
              :class="{ activeParent: currentIndex == index }"
              v-for="(item, index) in routeMenus"
              :key="index"
              @click="selectParentRoute(item, index)"
            >
              {{ filterTitle(item.meta.title) }}
              <!-- <i v-if="item.children" class="el-icon-arrow-down" /> -->
            </span>
          </div>
        </div>
        <!-- ***************** -->
        <div class="right-menu">
          <span class="right-menu-currentRole">{{ currentRoleObj.roleName }}</span>
          <el-button
            class="Topbar-identity"
            type="text"
            @click="handelShowDialog"
            :disabled="disabledRole"
          >
            切换角色
          </el-button>
          <el-dropdown class="Topbar-dropdown">
            <span class="Topbar-el-dropdown-link">
              {{ name }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown" class="Topbar-el-dropdown-menu">
              <div>
                姓名 <span>{{ name }}</span>
              </div>
              <div class="Topbar-Group">
                身份
                <span>{{ currentRoleObj.roleName }}</span>
              </div>
              <div>
                学校 <span>{{ school }}</span>
              </div>
              <div class="user-center">
                <!-- <span @click.stop="toUserCenter">个人中心</span> -->
                <a class="Topbar-logout" @click="logout">退出登录</a>
              </div>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

    <!-- S2二级菜单改造 -->
    <!-- ************ -->
    <div class="childRoute" v-if="subMenus">
      <div class="childRoute-menus container">
        <div
          :class="{ activeChild: currentChildIndex == index }"
          v-for="(item, index) in subMenus"
          :key="index"
          @click="selectChildRoute(item, index)"
        >
          {{ filterTitle(item.meta.title) }}
        </div>
      </div>
    </div>
    <!-- ************ -->

    <el-dialog
      title="是否退出登录"
      :visible.sync="DialogLogout"
      width="325px"
      height="134px"
      append-to-body
      center
      class="Topbar-el-dialog"
    >
      <span slot="footer" class="dialog-footer">
        <el-button @click="DialogLogout = false">取 消</el-button>
        <el-button type="primary" @click="LogoutConfirm">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="请选择你要切换的身份"
      :visible.sync="DialogVisible"
      width="474px"
      height="218px"
      append-to-body
      center
      class="Topbar-el-dialog"
    >
      <div
        v-for="(item, index) in teacherInfo.roleMap"
        :key="index"
        class="Topbar-role"
        :class="{ roleActive: currentRoleObj.roleType == item.roleType }"
        @click="selectRole(item)"
      >
        {{ item.roleName }}
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="DialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 筛选项组件 -->
    <filterItems />
  </div>
</template>

<script>
import variables from "@/assets/styles/variables.scss";
import { mapState, mapActions, mapGetters, mapMutations } from "vuex";
import $C from "@/assets/js/config.js";
import filterItems from "./Sidebar/filterItems.vue";

export default {
  components: { filterItems },
  name: "Topbar",
  data() {
    return {
      delaySearch: false, //搜索延迟
      DialogLogout: false,
      DialogVisible: false, //弹框默认影藏
      // 当前激活一级菜单的 index
      currentIndex: localStorage.getItem("parentPathIndex") || 0,
      // 二级菜单index
      currentChildIndex: localStorage.getItem("childPathIndex") || 0,
      // 角色
      currentRole: "", //当前角色名
      classesByRole: [], //角色下班级
      subjectByClass: [], //班级下学科
      currentGrade: "",
      currentGradeName: "",
      fullscreenLoading: false,
      disabledRole: false,
      // 当前班级
      current_class: "",
      currentSubject: "", //默认显示学科
      activeSubject: ""
    };
  },
  mounted() {
    this.GetUserStoreClasses();
  },
  watch: {
    currentRoleObj: {
      handler(val, old) {
        // 切换角色高亮默认第一个路由
        this.currentIndex = 0;
        this.currentChildIndex = 0;
      },
      deep: true
    }
  },
  computed: {
    ...mapGetters(["avatar", "storeClasses", "name", "school", "gradeList", "routeMenus"]),
    variables() {
      return variables;
    },

    // 二级菜单
    subMenus() {
      let menu = this.routeMenus[this.currentIndex]?.children || "";
      return menu;
    },

    // 一级路由
    parentMenu() {
      let parent = this.routeMenus[this.currentIndex].path;
      return parent;
    },

    // 页面logo图片
    logo() {
      return this.$store.state.user.teacherInfo.schoolVo.logo;
    },

    // 教师信息
    teacherInfo() {
      return this.$store.state.user.teacherInfo;
    },
    //角色信息
    currentRoleObj() {
      return this.$store.state.user.current_role;
    }
  },
  methods: {
    ...mapActions({ GetUserStoreClasses: "GetUserStoreClasses" }),
    ...mapMutations([
      "SET_CURRENT_CLASS",
      "SET_CURRENT_ROLE",
      "SET_CURRENT_SUBJECT",
      "SET_GRADE",
      "SET_CURRENT_GRADE",
      "SET_SUBJECT_LIST"
    ]),
    toUserCenter() {
      this.$router.push({ name: "UserCenterHome" });
    },

    // 点击一级路由菜单
    selectParentRoute(item, index) {
      this.currentIndex = index;
      localStorage.setItem("parentPathIndex", index);
      localStorage.setItem("childPathIndex", 0);
      let parentRoute = item.path;
      if (item.children) {
        // 有二级路由
        let defaultChild = item.children[0]?.path; //点击跳转默认第一个二级路由
        this.$router.push(`${parentRoute}/${defaultChild}`);
      } else {
        // 没有二级路由
        this.$router.push(parentRoute);
      }
    },

    // 子菜单选择事件
    selectChildRoute(item, index) {
      localStorage.setItem("childPathIndex", index);
      this.$router.push(`${this.parentMenu}/${item.path}`);
    },

    // 点击确认退出登录
    async LogoutConfirm() {
      this.$store.dispatch("LogOut").then(() => {
        location.href = "/";
      });
      this.DialogLogout = false;
    },
    // 点击退出登录
    logout() {
      this.DialogLogout = true;
    },
    handelShowDialog() {
      this.DialogVisible = true;
      this.disabledRole = true;
      let timer = setTimeout(() => {
        clearTimeout(timer);
        this.disabledRole = false;
      }, 6000);
    },

    // 切换角色
    selectRole(item) {
      this.fullscreenLoading = true;
      this.DialogVisible = false;

      localStorage.setItem("childPathIndex", 0);
      localStorage.setItem("parentPathIndex", 0);

      this.SET_CURRENT_ROLE(item);
      //当前角色下年级列表和默认年级
      if (item.grades[0]) {
        this.SET_GRADE(item.grades);
        this.SET_CURRENT_GRADE(item.grades[0]);
        this.currentGrade = item.grades[0].grade;
      }

      //角色下是否存在班级
      if (item.classes[0]) {
        //角色下班级

        this.classesByRole = item.classes;
        this.SET_CURRENT_CLASS(item.classes[0]);
        //改变默认班级
        this.current_class = item.classes[0].classNo;
      }

      //任课教师、考察科目教师角色下班级
      if (item.roleType == 106 || item.roleType == 113) {
        let currentRoleSub = this.teacherInfo.roleMap[item.roleType].classes.find(
          v => v.classNo == this.current_class
        );
        this.subjectByClass = currentRoleSub.subjects;
        this.currentSubject = currentRoleSub.subjects[0].subject;
        this.SET_CURRENT_SUBJECT(currentRoleSub.subjects[0]);
        this.SET_SUBJECT_LIST(currentRoleSub.subjects);
      }
      this.$store.dispatch("GetRoutes").then(v => {
        let parentRoute = v[0].path;

        if (v[0].children) {
          let toIndex = v[0].children[0].path;
          this.$router.push({
            path: `${parentRoute}/${toIndex}`,
            replace: true
          });
        } else {
          this.$router.push(parentRoute);
        }
      });

      //计算top高度并传参
      this.$nextTick(() => {
        const childHeight = this.$refs.topBar.offsetHeight;
        this.$emit("getHeight", childHeight);
      });

      let timer = setTimeout(() => {
        clearTimeout(timer);
        this.fullscreenLoading = false;
      }, 800);

      // });
    },
    //去掉子菜单角色名字段
    filterTitle(title) {
      let roleName = this.currentRole;
      if (title.includes("-")) {
        return title.substr(title.lastIndexOf("-") + 1);
      } else {
        return title.replace(roleName, "");
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.topBar {
  &-navi {
    width: 100%;
    background: #fff;
    box-shadow: 0px -1px 0px 0px rgba(0, 0, 0, 0.04) inset;
    height: 55px;
    display: flex;
    .top-menu {
      // width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .myMenu {
        display: flex;
        align-items: center;
        width: 100%;
        img {
          width: 135px;
        }
        .parentRoute {
          width: 100%;
          > span {
            cursor: pointer;
            margin-left: 30px;
          }
          .activeParent {
            color: #34beea;
          }
        }
        .menuList {
          display: flex;
        }
      }

      .right-menu {
        text-align: right;
        width: 240px;
        display: flex;
        align-items: center;
        height: 100%;

        &-currentRole {
          margin-right: 10px;
          // width: 80px;
          height: 22px;
          line-height: 22px;
          border-radius: 4px;
          text-align: center;
          color: #34beea;
          background: rgba(52, 190, 234, 0.16);
        }

        &:focus {
          outline: none;
        }

        .Topbar-dropdown {
          .Topbar-el-dropdown-link {
            cursor: pointer;
          }
        }
        .Topbar-identity {
          display: inline-block;
          color: #777777;
          line-height: 21px;
          margin-right: 10px;
          &:hover {
            // background-color: red;
            color: #34beea;
          }
        }
      }
    }
  }
  .childRoute {
    height: 54px;
    background-color: #fff;
    box-shadow: 0px 4px 4px 0px rgba(209, 209, 209, 0.25);
    margin-bottom: 20px;
    cursor: pointer;
    &-menus {
      display: flex;
      align-items: center;
      > div {
        // line-height: 54px;
        height: 54px;
        padding: 16px 36px;
      }
      .activeChild {
        background: #34beea;
        color: #fff;
      }
    }
  }
}

.Topbar-el-dropdown-menu {
  width: 270px;
  height: 220px;
  padding: 32px 0 0 24px;
  overflow: hidden;

  div {
    width: 100%;
    height: 32px;
    display: flex;
    align-items: center;

    span {
      margin-left: 32px;
    }
  }

  .Topbar-Group {
    span:nth-child(1) {
      margin: 0 20px 0 32px;
    }

    img {
      // margin-right: 2px;
    }
  }

  .Topbar-install {
    display: inline-block;
    width: 56px;
    height: 21px;
    color: #303133;
    line-height: 21px;
    margin: 18px 0 12px 75px;
    white-space: nowrap;

    &:hover {
      color: #e54747;
    }
  }

  .user-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 30px;
    height: 42px;
    user-select: none;

    > span,
    > a {
      margin: 0;
      padding: 0;
    }

    > span {
      margin-bottom: 10px;
      color: #333;
      cursor: pointer;

      &:active {
        opacity: 0.5;
      }
    }

    > a {
      color: #e54747;
    }
  }
}

.Topbar-el-dialog {
  margin-top: 200px;

  .el-dialog__header {
    .el-dialog__title {
      margin-top: 30px;
      font-size: 16px;
      color: #606266;
    }
  }

  .el-dialog__body {
    .roleActive {
      color: #34beea;
    }

    .Topbar-role {
      height: 21px;
      text-align: center;
      font-size: 12px;
      margin-bottom: 21px;
      cursor: pointer;

      &:hover {
        color: #34beea;
      }
    }
  }
}
</style>

一级路由循环渲染  currentIndex高亮   添加点击事件

<div class="parentRoute">
            <span
              :class="{ activeParent: currentIndex == index }"
              v-for="(item, index) in routeMenus"
              :key="index"
              @click="selectParentRoute(item, index)"
            >
              {{ filterTitle(item.meta.title) }}
              <!-- <i v-if="item.children" class="el-icon-arrow-down" /> -->
            </span>
          </div> 

二级路由  currentChildIndex高亮  添加点击事件

<div class="childRoute-menus container">

        <div

          :class="{ activeChild: currentChildIndex == index }"

          v-for="(item, index) in subMenus"

          :key="index"

          @click="selectChildRoute(item, index)"

        >

          {{ filterTitle(item.meta.title) }}

        </div>

      </div>

在data中定义变量:

         // 当前激活一级菜单的 index

      currentIndex: localStorage.getItem("parentPathIndex") || 0,

      // 二级菜单index

      currentChildIndex: localStorage.getItem("childPathIndex") || 0,

 

 在跳转页面(也就是学情概览页面)的methods里面新增一个方法

 findMore(name, path) {

      let parentIndex = this.routeMenus.findIndex(v => v.meta.title == name);

      let childIndex = this.routeMenus[parentIndex].children.findIndex(v => v.path == path);

      localStorage.setItem("parentPathIndex", parentIndex);

      localStorage.setItem("childPathIndex", childIndex);

      this.$router.push(path);

    },

在学情概览页面结构里面 点击更多的地方使用这个方法并传参: 

routeMenus

 

目标页面: 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1130453.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

dc9靶机攻略

dc9 扫描 扫描结果如图 nmap 目录扫描 指纹扫描 渗透 访问首页 该处发现搜索框&#xff0c;正常搜名字可以直接返回该用户的信息&#xff0c;怀疑sql注入&#xff0c;使用单引号注入&#xff0c;发现没反应&#xff0c;再使用一下万能注入语句1 or 11 使用sqlmap sqlmap -…

什么是蓝桥杯?什么是蓝桥STEMA考试?

第十五届蓝桥大赛赛事安排? STEMA考试11月(考试时间11月26日) STEMA考试1月(2024年1月) STEMA考试3月(2024年3月) 第十五届蓝桥杯省赛(2024年4月待定) 第十五届蓝桥杯国赛(2024年5月待定) 注:以上时间具体以组委会官方发布为准。 01.蓝桥杯 蓝桥杯全国软件和…

【每日一题】掷骰子等于目标和的方法数

文章目录 Tag题目来源题目解读解题思路方法一&#xff1a;动态规划 写在最后 Tag 【动态规划】【数组】 题目来源 1155. 掷骰子等于目标和的方法数 题目解读 你手里有 n 个一样的骰子&#xff0c;每个骰子都有 k 个面&#xff0c;分别标号 1 到 n。给定三个整数 n&#xff0…

部署基于efk+logstash+kafka构建日志收集平台并对nginx日志进行分析

文章目录 1.1 安装zookeeper集群1.2 安装kafka集群1.3 部署filebeat服务1.4 部署logstash1.5 部署es和kibana服务1.6 配置kibana ui界面1.7 对nginx进行日志分析 Filebeat采集日志kafka topic存起来日志->logstash去kafka获取日志&#xff0c;进行格式转换->elasticsearc…

【计算机网络笔记】网络应用进程通信

系列文章目录 什么是计算机网络&#xff1f; 什么是网络协议&#xff1f; 计算机网络的结构 数据交换之电路交换 数据交换之报文交换和分组交换 分组交换 vs 电路交换 计算机网络性能&#xff08;1&#xff09;——速率、带宽、延迟 计算机网络性能&#xff08;2&#xff09;…

【RocketMQ系列十四】RocketMQ中消息堆积如何处理

您好&#xff0c;我是码农飞哥&#xff08;wei158556&#xff09;&#xff0c;感谢您阅读本文&#xff0c;欢迎一键三连哦。 &#x1f4aa;&#x1f3fb; 1. Python基础专栏&#xff0c;基础知识一网打尽&#xff0c;9.9元买不了吃亏&#xff0c;买不了上当。 Python从入门到精…

Elasticsearch分词器-中文分词器ik

文章目录 使用standard analysis对英文进行分词使用standard analysis对中文进行分词安装插件对中文进行友好分词-ik中文分词器下载安装和配置IK分词器使用ik_smart分词器使用ik_max_word分词器 text analysis 使用standard analysis对英文进行分词 ES默认使用standard analys…

【Java】智慧医院绩效考核系统源码

医院绩效考核系统使用JAVA语言开发&#xff0c;采用B/S架构模式设计&#xff0c;后台使用MySql数据库进行管理的一整套计算机应用软件。系统和his系统进行对接&#xff0c;按照设定周期&#xff0c;从his系统获取医院科室和医生、护士、其他人员工作量&#xff0c;对没有录入信…

【MySQL架构篇】逻辑架构

逻辑架构 文章目录 逻辑架构1. 服务器处理客户端请求2. Connectors3. 第一层&#xff1a;连接层4. 第二层&#xff1a;服务层5. 第三层&#xff1a;存储引擎6. 存储层7. 小结 1. 服务器处理客户端请求 首先 MySQL 是典型的 C/S 架构&#xff0c;即 Client/Server 架构&#xf…

idea 基础设置

1、设置 IDEA 主题 2、自动导包和优化多余的包 3、同一个包下的类&#xff0c;超过指定个数的时候&#xff0c;导包合并为* 4、显示行号 &#xff0c; 方法和方法间的分隔符&#xff1a; 5、忽略大小写&#xff0c;进行提示 6、多个类不隐藏&#xff0c;多行显示 7、设置默认的…

2023高频前端面试题-CSS

1. CSS 选择器的优先级是怎么样的&#xff1f; CSS 选择器的优先级顺序&#xff1a; 内联样式 > ID选择器 > 类选择器 > 标签选择器 优先级的计算&#xff1a; 优先级是由 A、B、C、D 四个值来决定的&#xff0c;具体计算规则如下 A{如果存在内联样式则为 1&…

计算机网络-计算机网络体系结构-应用层

目录 一、网络应用模型 客户/服务器模型(Client/Server) P2P模型(Peer-to-peer) 二、域名解析系统(DNS) 域名 域名服务器 解析过程 三、文件传输协议(FTP) FTP控制原理 四、电子邮件 组成结构 协议 SMTP MIME POP3 IMAP 五、万维网和HTTP协议 概述 HTTP 报…

MySQL数据库---入门篇

文章目录 数据库介绍什么是数据库&#xff1f;数据库分类 MySQL的结构MySQL客户端和服务器MySQL服务器是如何组织数据的&#xff1f; 数据库操作显示当前数据库创建数据库使用数据库删除数据库 数据库中常用数据类型数值类型字符串类型日期类型 表的操作创建表查看表结构查看当…

Linux系统编程:线程

从进程到线程 为什么需要线程&#xff1f;这是因为进程本身存在一定问题&#xff1a; 首先是进程切换时&#xff0c;各类进程资源如寄存器CPU、包括虚拟地址和物理地址要进行映射等等进行上下文切换&#xff0c;这是非常消耗资源和时间的事情&#xff0c;并且实现进程间通信非…

死锁的发生原因和怎么避免

死锁 死锁&#xff0c;简单来说就是两个或者两个以上的线程在执行的过程中&#xff0c;争夺同一个共享资源造成的相互等待的现象。如果没有外部干预&#xff0c;线程会一直阻塞无法往下执行&#xff0c;这些一直处于相互等待资源的线程就称为死锁线程。 死锁产生原因 导致死…

使用强化学习训练 AI 去玩神奇宝贝

使用强化学习训练 AI 去玩神奇宝贝 这两天在逛 Youtube 的时候意外发现了一个非常有趣的视频&#xff0c;十天的时间已经获得了两百多万的点击&#xff1a; 现在已经 360w 点击了 视频的名称就和题目的名称一样&#xff1a;Training AI to Play Pokemon with Reinforcement Le…

Kaggle - LLM Science Exam(四):Platypus2-70B with Wikipedia RAG

文章目录 一、赛事概述1.1 OpenBookQA Dataset1.2 比赛背景1.3 评估方法和代码要求1.4 比赛数据集1.5 优秀notebook1.6 RAG 二、Platypus2-70B with Wikipedia RAG&#xff08;Version8&#xff09;2.1 离线安装依赖2.2 导入库并设置常量2.3设置辅助功能2.4 SentenceTransforme…

phpstorm+phpstudy+xdebug快速搭建php调试环境

1、安装phpstudy 让你的项目能正常跑起来&#xff0c;再来进行下一步 2、安装拓展 勾选需要用到的插件&#xff0c;配置好端口 再php.ini最下面复制如下配置&#xff0c;插件的地址按实际路径配置 [Xdebug] zend_extensionD:/phpstudy_pro/Extensions/php/php5.6.9nts/ext/p…

UG\NX二次开发 实现“适合窗口”的功能

文章作者:里海 来源网站:王牌飞行员_里海_里海NX二次开发3000例,里海BlockUI专栏,C\C++-CSDN博客 感谢粉丝订阅 感谢 shsjdj 订阅本专栏,非常感谢。 简介 实现“适合窗口”的功能 效果 代码1 #include "me.hpp"extern DllExport void ufusr(char* param, int* re…

java将list转为逗号隔开字符串,将逗号连接的字符串转成字符数组,​将逗号分隔的字符串转换为List​(Java逗号分隔-字符串与数组相互转换)

一、通过testList.stream().collect(Collectors.joining(",")) &#xff0c;通过流转换&#xff0c;将list转为逗号隔开字符串 List<String> testList new ArrayList<>(); testList.add("test1"); testList.add("test2"); testList…