Header.vue 5.0 KB

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