Header.vue 4.2 KB

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