index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <header>
  3. <div class="left-box">
  4. <!-- 收缩按钮 -->
  5. <div class="menu-icon" @click="opendStateChange">
  6. <i class="iconfont" :class="isCollapse ? 'icon-caidanzhankai':'icon-caidanshouqi'" style="font-size:24px;"></i>
  7. </div>
  8. <Breadcrumb />
  9. </div>
  10. <div class="right-box">
  11. <!-- 快捷功能按钮 -->
  12. <div class="function-list">
  13. <div class="function-list-item hidden-sm-and-down">
  14. <Full-screen />
  15. </div>
  16. <div class="function-list-item"><SizeChange /></div>
  17. <div class="function-list-item hidden-sm-and-down"><Theme /></div>
  18. </div>
  19. <!-- 用户信息 -->
  20. <div class="user-info">
  21. <el-avatar src="https://i.loli.net/2017/08/21/599a521472424.jpg" style="margin-top:1px;" size="small"/>
  22. <el-dropdown>
  23. <div class="el-dropdown-link">
  24. <span>{{userInfo.nickName || '请登录'}}</span>
  25. <i class="iconfont icon-xialazhankai" style="font-size:14px;margin-left: 3px;"></i>
  26. </div>
  27. <template #dropdown>
  28. <el-dropdown-menu>
  29. <el-dropdown-item @click="loginOut">退出登录</el-dropdown-item>
  30. </el-dropdown-menu>
  31. </template>
  32. </el-dropdown>
  33. </div>
  34. </div>
  35. </header>
  36. </template>
  37. <script>
  38. import { defineComponent, computed, reactive } from 'vue'
  39. import { useStore } from 'vuex'
  40. import { useRouter, useRoute } from 'vue-router'
  41. import FullScreen from './functionList/fullscreen.vue'
  42. import SizeChange from './functionList/sizeChange.vue'
  43. import Theme from './functionList/theme.vue'
  44. import Breadcrumb from './Breadcrumb.vue'
  45. import { ElMessage } from 'element-plus'
  46. export default defineComponent({
  47. components: {
  48. FullScreen,
  49. Breadcrumb,
  50. SizeChange,
  51. Theme,
  52. },
  53. setup() {
  54. const store = useStore()
  55. const router = useRouter()
  56. const route = useRoute()
  57. const layer = reactive({
  58. show: false,
  59. showButton: true
  60. })
  61. const userInfo = computed(()=>store.state.user.userInfo)
  62. const isCollapse = computed(() => store.state.app.isCollapse)
  63. // isCollapse change to hide/show the sidebar
  64. const opendStateChange = () => {
  65. store.commit('app/isCollapseChange', !isCollapse.value)
  66. }
  67. // login out the system
  68. const loginOut = () => {
  69. store.dispatch('user/loginOut').then(() => {
  70. ElMessage.success({
  71. message: '退出登录成功',
  72. type: 'success',
  73. showClose: true,
  74. duration: 1000
  75. })
  76. router.push('/login')
  77. })
  78. }
  79. return {
  80. isCollapse,
  81. layer,
  82. opendStateChange,
  83. loginOut,
  84. userInfo,
  85. }
  86. }
  87. })
  88. </script>
  89. <style lang="scss" scoped>
  90. header {
  91. display: flex;
  92. justify-content: space-between;
  93. align-items: center;
  94. height: 60px;
  95. background-color: var(--system-header-background);
  96. padding-right: 22px;
  97. }
  98. .left-box {
  99. height: 100%;
  100. display: flex;
  101. align-items: center;
  102. border-left: 1px solid var(--system-header-border-color);
  103. .menu-icon {
  104. width: 60px;
  105. height: 100%;
  106. display: flex;
  107. align-items: center;
  108. justify-content: center;
  109. font-size: 25px;
  110. font-weight: 100;
  111. cursor: pointer;
  112. margin-right: 10px;
  113. &:hover {
  114. background-color: var(--system-header-item-hover-color);
  115. }
  116. i {
  117. color: var(--system-header-text-color);
  118. }
  119. }
  120. }
  121. .right-box {
  122. display: flex;
  123. justify-content: center;
  124. align-items: center;
  125. .function-list{
  126. display: flex;
  127. .function-list-item {
  128. width: 30px;
  129. display: flex;
  130. justify-content: center;
  131. align-items: center;
  132. :deep(i) {
  133. color: var(--system-header-text-color);
  134. }
  135. }
  136. }
  137. .user-info {
  138. margin-left: 20px;
  139. .el-dropdown-link {
  140. margin-top: 8px;
  141. margin-left: 5px;
  142. color: var(--system-header-breadcrumb-text-color);
  143. }
  144. }
  145. }
  146. </style>