Header.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <!-- //根据平台不同传不同参 0后台(管理员)1老师 2学生 eduIdentity
  3. {{userInfo.eduIdentity}}
  4. 管理员 -->
  5. <div v-if="userInfo.eduIdentity == 2" class="fcbc">
  6. <div class="headerBtn">
  7. <a-menu v-model:selectedKeys="current" mode="horizontal">
  8. <a-menu-item key="student/resourceCenter">资源中心</a-menu-item>
  9. <a-menu-item key="student/courseCenter">课程中心</a-menu-item>
  10. <a-sub-menu key="myList">
  11. <template #title>我的</template>
  12. <a-menu-item key="student/paper/1">我的考试</a-menu-item>
  13. <a-menu-item key="student/homework">我的作业</a-menu-item>
  14. <a-menu-item key="student/paper/3">调查问卷</a-menu-item>
  15. <a-menu-item key="student/classCollect">课程收藏</a-menu-item>
  16. </a-sub-menu>
  17. </a-menu>
  18. </div>
  19. <div class="header-right">
  20. <a-dropdown v-if="userInfo">
  21. <div class="cur flc">
  22. <a-avatar :src="userInfo.avatar">
  23. <template #icon><UserOutlined /></template>
  24. </a-avatar>
  25. <div class="ml-2">{{ userInfo.name }}</div>
  26. </div>
  27. <template #overlay>
  28. <a-menu>
  29. <a-menu-item key="1" @click="jump('/userInfo')">个人中心</a-menu-item>
  30. <a-menu-item key="2" @click="jump('/forum')">论坛</a-menu-item>
  31. <a-menu-item key="3" @click="jump('/inSsiteMessage')">站内信</a-menu-item>
  32. <a-menu-item key="4" @click="jump('/classNotice')">课程公告</a-menu-item>
  33. <a-menu-item key="5" @click="jump('/learningFootprint')">学习足迹</a-menu-item>
  34. <a-menu-item key="6" @click="jump('/slogin')">登录</a-menu-item>
  35. <a-menu-item key="7" @click="jump('/passwordRetrieve')">密码找回</a-menu-item>
  36. <a-menu-item key="8" @click="outLogin()">退出登陆</a-menu-item>
  37. </a-menu>
  38. </template>
  39. </a-dropdown>
  40. <div class="flc" v-if="!userInfo">
  41. <UserOutlined :style="{ fontSize: '16px', color: '#00000083' }" />
  42. <div class="ml-2 cur" @click="jump('/slogin')">登录</div>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="line"></div>
  47. </template>
  48. <script setup>
  49. import { createVNode } from 'vue'
  50. import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
  51. import { Modal } from 'ant-design-vue'
  52. import loginApi from '@/api/auth/loginApi'
  53. import { message } from 'ant-design-vue'
  54. import { ref } from 'vue'
  55. import { useRouter, useRoute } from 'vue-router'
  56. import tool from '@/utils/tool'
  57. const router = useRouter()
  58. const route = useRoute()
  59. const current = ref([route.path.slice(1)]) // 默认选中“资源中心”
  60. const emit = defineEmits(['onChangeCurrent'])
  61. const userInfo = tool.data.get('USER_INFO')
  62. watch(
  63. () => current.value,
  64. (newVal, oldVal) => {
  65. if (newVal != oldVal) {
  66. emit('onChangeCurrent', newVal)
  67. }
  68. }
  69. )
  70. const jump = (url) => {
  71. router.push({
  72. path: url
  73. })
  74. }
  75. const outLogin = () => {
  76. Modal.confirm({
  77. title: '提示',
  78. content: '确认退出当前用户?',
  79. icon: createVNode(ExclamationCircleOutlined),
  80. maskClosable: false,
  81. onOk() {
  82. // 取得缓存中的token
  83. const token = tool.data.get('TOKEN')
  84. const param = {
  85. token: token
  86. }
  87. message.loading('退出中...', 1)
  88. loginApi
  89. .logout(param)
  90. .then(() => {
  91. // 清理掉个人的一些信息
  92. tool.data.remove('TOKEN')
  93. tool.data.remove('USER_INFO')
  94. tool.data.remove('MENU')
  95. tool.data.remove('PERMISSIONS')
  96. tool.cookie.remove('Token')
  97. router.replace({ path: '/slogin' })
  98. })
  99. .catch(() => {
  100. tool.data.clear()
  101. router.replace({ path: '/slogin' })
  102. location.reload()
  103. })
  104. },
  105. onCancel() {}
  106. })
  107. }
  108. </script>
  109. <style scoped lang="less">
  110. .header {
  111. display: flex;
  112. align-items: center;
  113. justify-content: space-between;
  114. padding: 0 50px;
  115. }
  116. .headerBtn {
  117. display: flex;
  118. padding-left: 10%;
  119. flex: 1;
  120. :deep(.ant-menu-horizontal) {
  121. line-height: 55px;
  122. }
  123. }
  124. .header-right {
  125. display: flex;
  126. align-items: center;
  127. margin-right: 20%;
  128. }
  129. .fcbc {
  130. display: flex;
  131. width: 100%;
  132. justify-content: space-between;
  133. align-items: center;
  134. background-color: #fff;
  135. }
  136. .flc {
  137. display: flex;
  138. align-items: center;
  139. }
  140. .cur {
  141. cursor: pointer;
  142. }
  143. .line {
  144. width: 100%;
  145. height: 0.25px;
  146. background-color: #00000013;
  147. }
  148. </style>