GlobalHeader.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div id="global-header-body">
  3. <el-backtop/>
  4. <img id="global-header-logo" alt="err" src="@/assets/seec-logo--full.png" @click="this.$router.push('/portal')">
  5. <el-menu :default-active="activeMenu" mode="horizontal" @select="handleMenuSelect">
  6. <el-menu-item index="1">首页</el-menu-item>
  7. <el-menu-item index="2">任务</el-menu-item>
  8. <el-submenu index="3">
  9. <template #title>{{ quickAccessTitle }}</template>
  10. <el-menu-item index="3-1">全部课程</el-menu-item>
  11. <el-menu-item index="3-2">全部测试</el-menu-item>
  12. </el-submenu>
  13. <el-menu-item index="4">个人中心</el-menu-item>
  14. <el-menu-item v-if="isTeacher" index="5">教师[临]</el-menu-item>
  15. <!-- todo @DQJ 导航栏可能还有变动-->
  16. <el-menu-item index="6">问题[?]</el-menu-item>
  17. </el-menu>
  18. <div id="global-header-icon">
  19. <div class="global-header-icon-content" @click="this.$router.push('/message')" style="position: relative">
  20. <sup v-if="unreadNum!==0" class="reminder">{{ unreadNum }}</sup>
  21. <svg height="32" viewBox="0 0 1024 1024" width="32" xmlns="http://www.w3.org/2000/svg">
  22. <path
  23. 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"
  24. fill="#E8AA5B"></path>
  25. </svg>
  26. </div>
  27. <div class="global-header-icon-content" @click="this.$router.push('/home')">
  28. <ElPopover trigger="hover">
  29. <template #reference>
  30. <div v-if="isLogin" id="info-circle">
  31. <span>{{ name.substring(0, 1) }}</span>
  32. </div>
  33. <div v-else>
  34. <svg height="32" viewBox="0 0 1025 1024" width="32" xmlns="http://www.w3.org/2000/svg">
  35. <path
  36. 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"
  37. fill="#82BAD8"></path>
  38. <path
  39. 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
  40. 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"
  41. fill="#82BAD8"></path>
  42. </svg>
  43. </div>
  44. </template>
  45. <InfoCard/>
  46. </ElPopover>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import InfoCard from "@/components/InfoCard";
  53. export default {
  54. name: "GlobalHeader",
  55. components: {InfoCard},
  56. data() {
  57. return {
  58. quickAccessTitle: "快速访问",
  59. myUnReadAnnouncements: [],
  60. myUnReadMessages: [],
  61. menuIndex: [
  62. ["1", "/portal"],
  63. ["2", "/task"],
  64. ["3-1", "/course"],
  65. ["3-2", "/test"],
  66. ["4", "/home"],
  67. ["5", "/manage"],
  68. ["6", "/problem"],
  69. ]
  70. };
  71. },
  72. computed: {
  73. isLogin() {
  74. return this.$store.state.user.token !== undefined;
  75. },
  76. name() {
  77. return this.$store.state.user.name;
  78. },
  79. isTeacher() {
  80. return this.$store.getters.isTeacher;
  81. },
  82. activeMenu() {
  83. let out = "1";
  84. this.menuIndex.forEach(i => {
  85. if (i[1] === this.$route.path) {
  86. out = i[0];
  87. }
  88. });
  89. return out;
  90. },
  91. unreadNum() {
  92. console.log(this.myUnReadAnnouncements);
  93. console.log(this.myUnReadMessages);
  94. return this.myUnReadAnnouncements.length + this.myUnReadMessages.length > 99 ? "99+" : this.myUnReadAnnouncements.length + this.myUnReadMessages.length;
  95. },
  96. },
  97. watch:{
  98. isLogin(newData, oldData){
  99. if(newData){
  100. this.$apis.getUnreadAnnouncements()
  101. .then(res => {
  102. this.myUnReadAnnouncements = res.data.data;
  103. });
  104. }
  105. }
  106. },
  107. mounted() {
  108. if (this.isLogin) {
  109. this.$apis.getUnreadAnnouncements()
  110. .then(res => {
  111. this.myUnReadAnnouncements = res.data.data;
  112. });
  113. }
  114. },
  115. methods: {
  116. handleMenuSelect(key) {
  117. let target = "/portal";
  118. this.menuIndex.forEach(i => {
  119. if (i[0] === key) {
  120. target = i[1];
  121. }
  122. });
  123. this.$router.push(target);
  124. if (key === "3-1") {
  125. this.quickAccessTitle = "全部课程";
  126. } else if (key === "3-2") {
  127. this.quickAccessTitle = "全部测试";
  128. } else {
  129. this.quickAccessTitle = "快速访问";
  130. }
  131. },
  132. },
  133. };
  134. </script>
  135. <style scoped>
  136. #global-header-body {
  137. width: calc(100% - 2px);
  138. height: 48px;
  139. position: sticky;
  140. top: 0;
  141. z-index: 999;
  142. display: flex;
  143. justify-content: space-between;
  144. align-items: center;
  145. background: white;
  146. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  147. border: 1px solid #e4e7ed;
  148. }
  149. #global-header-logo {
  150. height: 32px;
  151. margin-left: 160px;
  152. cursor: pointer;
  153. }
  154. :deep(.el-menu--horizontal) {
  155. height: 48px;
  156. }
  157. :deep(.el-menu--horizontal>.el-submenu .el-submenu__title) {
  158. height: 48px;
  159. position: relative;
  160. bottom: 5px;
  161. }
  162. :deep(.el-menu--horizontal>.el-menu-item) {
  163. height: 48px;
  164. position: relative;
  165. bottom: 5px;
  166. }
  167. #global-header-icon {
  168. width: 120px;
  169. margin-right: 160px;
  170. display: flex;
  171. justify-content: space-around;
  172. }
  173. .global-header-icon-content {
  174. cursor: pointer;
  175. }
  176. #info-circle {
  177. height: 32px;
  178. width: 32px;
  179. display: flex;
  180. justify-content: center;
  181. align-items: center;
  182. border-radius: 50%;
  183. background: #619dc9;
  184. }
  185. #info-circle span {
  186. color: white;
  187. font-weight: bold;
  188. }
  189. .reminder {
  190. position: absolute;
  191. top: 0;
  192. right: 0;
  193. transform: translateY(-25%) translateX(35%);
  194. background-color: #f56c6c;
  195. border-radius: 10px;
  196. color: #fff;
  197. display: inline-block;
  198. font-size: 12px;
  199. height: 18px;
  200. line-height: 18px;
  201. padding: 0 6px;
  202. text-align: center;
  203. white-space: nowrap;
  204. border: 1px solid #fff;
  205. }
  206. </style>