123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <template>
- <div class="page-header-box" style="line-height: 40px;position: relative;padding:0 12px">
- <el-row :gutter="24">
- <el-col :span="12" v-if="path=='/login'" class="layui-col-md6 layui-col-xs4 header-left">
- <img class="header-icon" src="../../assets/images/icon_tel2.png" />
- <span class="p-l-small">服务热线:400-1797-985</span>
- <img class="m-l header-icon" src="../../assets/images/icon_phone.png" />
- <span class="pos-r" id="app_download" @mouseover="app=true" @mouseleave="app=false">
- <a href="javascript:void(0);">APP下载</a>
- <div id="appQrcode" v-show="app">
- <img style="width:110px;height:110px;" src="../../assets/images/app.png" />
- <p style="width:110px;color:#000;font-size:12px;margin-top:5px;">扫描下载APP</p>
- </div>
- </span>
- </el-col>
- <el-col v-if="false" :span="12" class="layui-col-md6 layui-col-xs8" style="text-align:right;">
- 您好!名学金榜欢迎你,
- <a href="#" class="color-orange">请登录>></a>
- </el-col>
- <el-col :span="12" v-if="path!='/login'" class="layui-col-md6 layui-col-xs4 header-left">
- <span @click="to('/login')" style="margin-right:20px;cursor:pointer">首页</span>
- <span v-for="(item, index) in visibleMenus" :key="index" style="margin-right:20px;cursor:pointer" @click="handleClick(item)">{{item.meta.title}}</span>
- </el-col>
- <el-col v-if="userInfo" :span="12" class="layui-col-md6 layui-col-xs8" style="text-align:right;">
- 您好!
- <span style="color:#FFA400;">{{userInfo.nickName}}{{userInfo.userName}} [{{userInfo.provinceName}} {{userInfo.schoolName}}],</span>
- 欢迎登录名学金榜
- <el-dropdown v-if="roleList.length > 1" @command="handleRoleExchange">
- <span class="el-dropdown-link pointer">[{{currentRole.roleName}}]</span>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item disabled class="role-change-title">
- 角色切换
- <i class="el-icon-refresh"></i>
- </el-dropdown-item>
- <el-dropdown-item v-for="(r,i) in roleList" :key="i" :disabled="r==currentRole" :command="r.roleId" :divided="i==0">{{r.roleName}}</el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- <img style="height:16px;margin-left:5px;position:relative;bottom:-2px;" :src="userInfo.avatar||'https://www.mingxuejc.com/images/photo/4_2.png'" />
- <a @click="userTo">个人中心</a>
- <a style="padding-left:30px;color:#FB731F;" @click="logout">退出登录</a>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import auth from "@/utils/auth";
- import { mapGetters } from "vuex";
- import { changeRole } from "@/api/login.js";
- export default {
- data() {
- return {
- app: false,
- path: "",
- menuList: [],
- };
- },
- computed: {
- ...mapGetters(["currentUser", "currentRole", "roleList"]),
- userInfo() {
- if (!auth.getToken()) return null;
- return this.currentUser;
- },
- // 所有的路由信息
- routers() {
- return this.$store.state.permission.topbarRouters;
- },
- visibleMenus() {
- return this.menuList.filter((m) => !m.hidden);
- },
- },
- created() {
- this.path = this.$route.path;
- },
- mounted() {
- this.menuList = this.topMenus();
- },
- methods: {
- logout() {
- this.$confirm("确定注销并退出系统吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- this.$store.dispatch("LogOut").then(() => {
- this.$router.push({ path: "/login" });
- window.location.reload();
- });
- });
- },
- to(url) {
- this.$router.push({
- path: url,
- });
- },
- // 顶部显示菜单
- topMenus() {
- let topMenus = [];
- this.routers.map((menu) => {
- menu.level = 1;
- if (menu.hidden !== true) {
- // 兼容顶部栏一级菜单内部跳转
- if (menu.path === "/") {
- if (menu.children) {
- topMenus.push(menu.children[0]);
- }
- } else {
- topMenus.push(menu);
- }
- }
- });
- return topMenus;
- },
- userTo() {
- //跳转至个人中心
- this.menuList = this.topMenus();
- this.menuList.forEach((item) => {
- if (item.path == "/user") {
- this.handleClick(item);
- } else if ("index" == item.path) {
- this.$emit("userNavTo");
- }
- });
- },
- handleClick(data) {
- auth.setMenuTab(data);
- auth.setActiveMenu(data.path + "/" + data.children[0].path);
- let item = JSON.parse(JSON.stringify(data));
- let routes = []; //三级菜单
- let second = []; //二级
- let routesTo = [];
- if (item.children) {
- //有二级菜单
- item.children.forEach((item2) => {
- if (item2.children) {
- item2.children.forEach((item3) => {
- item3.path = item.path + "/" + item2.path + "/" + item3.path;
- });
- if (routes.length == 0 && item2.children.length) {
- //一级菜单下面第一个有3个菜单的二级菜单
- routes = item2.children;
- routesTo = item2.children;
- }
- } else {
- routesTo = item.children;
- }
- item2.path = item.path + "/" + item2.path;
- item2.level = 2;
- second.push(item2);
- });
- let fal = false;
- second.forEach((item) => {
- if (!fal && item.children && item.children.length > 0) {
- auth.setActiveMenu(item.path);
- fal = true;
- }
- });
- auth.setMenuTab(second);
- this.three = true;
- this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
- } else {
- //没有二级菜单
- this.$store.commit("SET_SIDEBAR_ROUTERS", []);
- this.$router.push({
- path: item.path,
- });
- }
- let path = this.gouAction(routesTo);
- if (path) {
- this.$router.push({
- path: path,
- });
- auth.setMenuListAction(path);
- } else {
- }
- auth.setMenuList(routes);
- },
- toPath(data, path, url) {
- data.forEach((item) => {
- if (!path && item.children && item.children.length > 0) {
- let ac = url ? url + "/" : "";
- path = this.toPath(item.children, path, ac + item.path);
- } else if (!path) {
- let ac = url ? url + "/" : "";
- path = ac + item.path;
- }
- });
- return path;
- },
- gouAction(data) {
- if (data && data.length > 0) {
- if (data[0].children && data[0].children.length > 0) {
- if (
- data[0].children[0].children &&
- data[0].children[0].children.length > 0
- ) {
- return data[0].children[0].children.path;
- } else {
- return data[0].path + "/" + data[0].children[0].path;
- }
- } else {
- return data[0].path;
- }
- } else {
- return "";
- }
- },
- handleRoleExchange(roleId) {
- changeRole(roleId).then((_) => {
- // IMPORTANT: 此处会触发GetInfo/GetRouters
- //window.location.reload();
- window.location.href = "/login";
- });
- },
- },
- };
- </script>
- <style scoped>
- .page-header-box > .layui-row {
- width: 1184px;
- margin: 0 auto;
- padding: 8px 0;
- font-size: 14px;
- }
- .page-header-box .header-icon {
- height: 16px;
- vertical-align: middle;
- }
- img {
- border: none;
- }
- .p-l-small {
- padding-left: 8px;
- }
- .page-header-box .header-left > span {
- display: inline-block;
- vertical-align: middle;
- }
- #appQrcode {
- background: #fff;
- border: 1px solid #cdcdcd;
- box-shadow: 0 0 8px #cdcdcd;
- border-radius: 3px;
- padding: 10px;
- position: absolute;
- left: 0;
- top: 40px;
- z-index: 9999;
- text-align: center;
- }
- .pos-r {
- position: relative;
- }
- .m-l {
- margin-left: 16px;
- }
- .color-orange {
- color: #47c6a2;
- }
- .role-change-title {
- color: #666666;
- font-size: 12px;
- font-weight: bold;
- }
- </style>
|