GlobalHeader.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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="toPortal">
  5. <el-menu :default-active="activeMenu" mode="horizontal" @select="handleMenuSelect" id="menu">
  6. <el-menu-item index="1">
  7. 首页
  8. </el-menu-item>
  9. <el-menu-item v-if="isStudent" index="2">
  10. 任务
  11. </el-menu-item>
  12. <el-menu-item index="3">
  13. 课程
  14. </el-menu-item>
  15. <el-menu-item index="4">
  16. 项目
  17. </el-menu-item>
  18. <el-menu-item index="5">
  19. 测试
  20. </el-menu-item>
  21. <el-menu-item v-if="isTeacher" index="7">
  22. 管理
  23. </el-menu-item>
  24. <el-menu-item index="6">
  25. 个人中心
  26. </el-menu-item>
  27. </el-menu>
  28. <div id="global-header-icon">
  29. <el-tooltip content="前往通知页" placement="bottom" effect="light" :show-after="1000">
  30. <div class="global-header-icon-content" @click="toMessage" style="position: relative">
  31. <sup v-if="unreadNum !== '0'" class="reminder">
  32. {{ unreadNum }}
  33. </sup>
  34. <svg height="32" viewBox="0 0 1024 1024" width="32" xmlns="http://www.w3.org/2000/svg">
  35. <path
  36. 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"
  37. fill="#E8AA5B"></path>
  38. </svg>
  39. </div>
  40. </el-tooltip>
  41. <el-tooltip content="前往个人中心页" placement="right" effect="light" :show-after="1000">
  42. <div class="global-header-icon-content" @click="toHome">
  43. <ElPopover trigger="hover">
  44. <template #reference>
  45. <div v-if="isLogin" id="info-circle">
  46. <span>
  47. {{ singleName }}
  48. </span>
  49. </div>
  50. <div v-else>
  51. <svg height="32" viewBox="0 0 1025 1024" width="32" xmlns="http://www.w3.org/2000/svg">
  52. <path
  53. 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"
  54. fill="#82BAD8"></path>
  55. <path
  56. 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
  57. 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"
  58. fill="#82BAD8"></path>
  59. </svg>
  60. </div>
  61. </template>
  62. <InfoCard/>
  63. </ElPopover>
  64. </div>
  65. </el-tooltip>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. import InfoCard from "@/components/InfoCard";
  71. export default {
  72. name: "GlobalHeader",
  73. components: { InfoCard },
  74. data() {
  75. return {
  76. menuIndex: [
  77. ["1", "Portal"],
  78. ["2", "Task"],
  79. ["3", "Course"],
  80. ["4", "Project"],
  81. ["5", "Test"],
  82. ["6", "Home"],
  83. ["7", "Manage"],
  84. ["8", "Problem"],
  85. ["9", "CourseDetail"],
  86. ]
  87. };
  88. },
  89. computed: {
  90. isLogin() {
  91. return this.$store.getters.isLogin;
  92. },
  93. name() {
  94. return this.$store.state.user.name || "无名氏";
  95. },
  96. singleName() {
  97. return this.name.substring(0, 1);
  98. },
  99. isTeacher() {
  100. return this.$store.getters.isTeacher;
  101. },
  102. isStudent() {
  103. return this.$store.getters.isStudent;
  104. },
  105. activeMenu() {
  106. let out = "1";
  107. this.menuIndex.forEach(i => {
  108. if (i[1] === this.$route.name) {
  109. out = i[0];
  110. }
  111. });
  112. return out;
  113. },
  114. unReadMessages() {
  115. return this.$store.getters.unReadMessages;
  116. },
  117. unReadAnnouncements() {
  118. return this.$store.getters.unReadAnnouncements;
  119. },
  120. unReadInvitations(){
  121. return this.$store.getters.unReadInvitations;
  122. },
  123. unreadNum() {
  124. const x = this.unReadAnnouncements === undefined ? 0 : this.unReadAnnouncements.length;
  125. const y = this.unReadMessages === undefined ? 0 : this.unReadMessages.length;
  126. const z = this.unReadInvitations === undefined ? 0 : this.unReadInvitations.length;
  127. return x + y + z> 99 ? "99+" : x + y + z + "";
  128. },
  129. },
  130. watch: {
  131. isLogin(newData) {
  132. if (newData) {
  133. this.$store.dispatch("fetchMessages", this);
  134. }
  135. },
  136. $route() {
  137. if (this.isLogin) {
  138. this.$store.dispatch("fetchMessages", this);
  139. }
  140. }
  141. },
  142. created() {
  143. if (this.isLogin) {
  144. this.$store.dispatch("fetchMessages", this);
  145. }
  146. },
  147. methods: {
  148. toPortal() {
  149. this.$router.push("/portal");
  150. },
  151. toHome() {
  152. this.$router.push("/home");
  153. },
  154. toMessage() {
  155. this.$router.push("/message");
  156. },
  157. handleMenuSelect(key) {
  158. let target = "/portal";
  159. this.menuIndex.forEach(i => {
  160. if (i[0] === key) {
  161. target = i[1];
  162. }
  163. });
  164. this.$router.push({ name: target });
  165. },
  166. },
  167. };
  168. </script>
  169. <style scoped>
  170. #global-header-body {
  171. width: calc(100% - 2px);
  172. height: 48px;
  173. position: sticky;
  174. top: 0;
  175. z-index: 999;
  176. display: flex;
  177. justify-content: space-between;
  178. align-items: center;
  179. background: white;
  180. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  181. border: 1px solid #e4e7ed;
  182. }
  183. #global-header-logo {
  184. height: 32px;
  185. margin-left: 150px;
  186. cursor: pointer;
  187. }
  188. :deep(.el-menu--horizontal) {
  189. height: 48px;
  190. }
  191. :deep(.el-menu--horizontal>.el-submenu .el-submenu__title) {
  192. height: 48px;
  193. position: relative;
  194. bottom: 5px;
  195. }
  196. :deep(.el-menu--horizontal>.el-menu-item) {
  197. height: 48px;
  198. position: relative;
  199. bottom: 5px;
  200. }
  201. #menu li{
  202. color: black;
  203. border-bottom: none;
  204. }
  205. #global-header-icon {
  206. width: 120px;
  207. margin-right: 150px;
  208. display: flex;
  209. justify-content: space-around;
  210. }
  211. .global-header-icon-content {
  212. cursor: pointer;
  213. }
  214. #info-circle {
  215. height: 32px;
  216. width: 32px;
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. border-radius: 50%;
  221. background: #619dc9;
  222. }
  223. #info-circle span {
  224. color: white;
  225. font-weight: bold;
  226. }
  227. .reminder {
  228. position: absolute;
  229. top: 0;
  230. right: 0;
  231. transform: translateY(-25%) translateX(35%);
  232. background-color: #f56c6c;
  233. border-radius: 10px;
  234. color: #fff;
  235. display: inline-block;
  236. font-size: 12px;
  237. height: 18px;
  238. line-height: 18px;
  239. padding: 0 6px;
  240. text-align: center;
  241. white-space: nowrap;
  242. border: 1px solid #fff;
  243. }
  244. </style>