| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <template>
- <div id="global-header-body">
- <el-backtop/>
- <img id="global-header-logo" alt="err" src="@/assets/seec-logo--full.png" @click="this.$router.push('/portal')">
- <el-menu :default-active="activeMenu" mode="horizontal" @select="handleMenuSelect">
- <el-menu-item index="1">首页</el-menu-item>
- <el-menu-item index="2">任务</el-menu-item>
- <el-submenu index="3">
- <template #title>{{ quickAccessTitle }}</template>
- <el-menu-item index="3-1">全部课程</el-menu-item>
- <el-menu-item index="3-2">全部测试</el-menu-item>
- </el-submenu>
- <el-menu-item index="4">个人中心</el-menu-item>
- <el-menu-item v-if="isTeacher" index="5">教师[临]</el-menu-item>
- <!-- todo @DQJ 导航栏可能还有变动-->
- <el-menu-item index="6">问题[?]</el-menu-item>
- </el-menu>
- <div id="global-header-icon">
- <div class="global-header-icon-content" @click="this.$router.push('/message')" style="position: relative">
- <sup v-if="unreadNum!==0" class="reminder">{{ unreadNum }}</sup>
- <svg height="32" viewBox="0 0 1024 1024" width="32" xmlns="http://www.w3.org/2000/svg">
- <path
- d="M849.6 713.4c8.4-0.4 16.7 1.8 23.8 6.4-28.9-18.5-46.4-50.4-46.3-84.8V436c0-145.9-105.7-267.6-246.9-297.5v-7.2c0-37.1-30.1-67.1-67.2-67.1h-0.1c-37.1 0-67.3 30.1-67.3 67.2v7C304.3 168.4 198.7 290 198.7 436v199.1c0 35.7-18.6 66.9-46.4 84.8 7-4.6 15.4-6.9 23.8-6.4-24.7-0.9-45.5 18.4-46.4 43.1-0.9 24.7 18.4 45.5 43.1 46.4h676.6c24.7 0.1 44.8-20 44.9-44.7 0.1-24.8-19.9-44.9-44.7-44.9zM513 959.8c62 0 112.2-50.2 112.2-111.9H400.7c0 61.7 50.2 111.9 112.3 111.9z"
- fill="#E8AA5B"></path>
- </svg>
- </div>
- <div class="global-header-icon-content" @click="this.$router.push('/home')">
- <ElPopover trigger="hover">
- <template #reference>
- <div v-if="isLogin" id="info-circle">
- <span>{{ name.substring(0, 1) }}</span>
- </div>
- <div v-else>
- <svg height="32" viewBox="0 0 1025 1024" width="32" xmlns="http://www.w3.org/2000/svg">
- <path
- d="M511.999723 331.913794m-117.748854 0a117.748854 117.748854 0 1 0 235.497708 0 117.748854 117.748854 0 1 0-235.497708 0Z"
- fill="#82BAD8"></path>
- <path
- d="M511.999723 0.000554A511.999723 511.999723 0 1 0 1025.10767 512.000277 512.276779 512.276779 0 0 0 511.999723 0.000554zM792.380524 779.636496a24.935051 24.935051 0 0 1-24.935052-24.935052
- 255.445749 255.445749 0 0 0-510.614442 0 24.935051 24.935051 0 0 1-49.870103 0 304.76174 304.76174 0 0 1 205.29859-288.138372 167.896013 167.896013 0 1 1 199.480412 0 304.76174 304.76174 0 0 1 205.575646 288.138372 24.935051 24.935051 0 0 1-24.935051 24.935052z"
- fill="#82BAD8"></path>
- </svg>
- </div>
- </template>
- <InfoCard/>
- </ElPopover>
- </div>
- </div>
- </div>
- </template>
- <script>
- import InfoCard from "@/components/InfoCard";
- export default {
- name: "GlobalHeader",
- components: {InfoCard},
- data() {
- return {
- quickAccessTitle: "快速访问",
- myUnReadAnnouncements: [],
- myUnReadMessages: [],
- menuIndex: [
- ["1", "/portal"],
- ["2", "/task"],
- ["3-1", "/course"],
- ["3-2", "/test"],
- ["4", "/home"],
- ["5", "/manage"],
- ["6", "/problem"],
- ]
- };
- },
- computed: {
- isLogin() {
- return this.$store.state.user.token !== undefined;
- },
- name() {
- return this.$store.state.user.name;
- },
- isTeacher() {
- return this.$store.getters.isTeacher;
- },
- activeMenu() {
- let out = "1";
- this.menuIndex.forEach(i => {
- if (i[1] === this.$route.path) {
- out = i[0];
- }
- });
- return out;
- },
- unreadNum() {
- console.log(this.myUnReadAnnouncements);
- console.log(this.myUnReadMessages);
- return this.myUnReadAnnouncements.length + this.myUnReadMessages.length > 99 ? "99+" : this.myUnReadAnnouncements.length + this.myUnReadMessages.length;
- },
- },
- watch:{
- isLogin(newData, oldData){
- if(newData){
- this.$apis.getUnreadAnnouncements()
- .then(res => {
- this.myUnReadAnnouncements = res.data.data;
- });
- }
- }
- },
- mounted() {
- if (this.isLogin) {
- this.$apis.getUnreadAnnouncements()
- .then(res => {
- this.myUnReadAnnouncements = res.data.data;
- });
- }
- },
- methods: {
- handleMenuSelect(key) {
- let target = "/portal";
- this.menuIndex.forEach(i => {
- if (i[0] === key) {
- target = i[1];
- }
- });
- this.$router.push(target);
- if (key === "3-1") {
- this.quickAccessTitle = "全部课程";
- } else if (key === "3-2") {
- this.quickAccessTitle = "全部测试";
- } else {
- this.quickAccessTitle = "快速访问";
- }
- },
- },
- };
- </script>
- <style scoped>
- #global-header-body {
- width: calc(100% - 2px);
- height: 48px;
- position: sticky;
- top: 0;
- z-index: 999;
- display: flex;
- justify-content: space-between;
- align-items: center;
- background: white;
- box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
- border: 1px solid #e4e7ed;
- }
- #global-header-logo {
- height: 32px;
- margin-left: 160px;
- cursor: pointer;
- }
- :deep(.el-menu--horizontal) {
- height: 48px;
- }
- :deep(.el-menu--horizontal>.el-submenu .el-submenu__title) {
- height: 48px;
- position: relative;
- bottom: 5px;
- }
- :deep(.el-menu--horizontal>.el-menu-item) {
- height: 48px;
- position: relative;
- bottom: 5px;
- }
- #global-header-icon {
- width: 120px;
- margin-right: 160px;
- display: flex;
- justify-content: space-around;
- }
- .global-header-icon-content {
- cursor: pointer;
- }
- #info-circle {
- height: 32px;
- width: 32px;
- display: flex;
- justify-content: center;
- align-items: center;
- border-radius: 50%;
- background: #619dc9;
- }
- #info-circle span {
- color: white;
- font-weight: bold;
- }
- .reminder {
- position: absolute;
- top: 0;
- right: 0;
- transform: translateY(-25%) translateX(35%);
- background-color: #f56c6c;
- border-radius: 10px;
- color: #fff;
- display: inline-block;
- font-size: 12px;
- height: 18px;
- line-height: 18px;
- padding: 0 6px;
- text-align: center;
- white-space: nowrap;
- border: 1px solid #fff;
- }
- </style>
|