HeaderWrap.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <script setup>
  2. import { computed, ref } from 'vue'
  3. import { useLayoutState } from '../hooks/index'
  4. import { useRoute, useRouter } from 'vue-router'
  5. const { menuClose, menuCloseChange } = useLayoutState()
  6. const router=useRouter()
  7. const route=useRoute()
  8. const userName=computed(()=>{
  9. return localStorage.getItem('userName')
  10. })
  11. const breadcrumbArr=computed(()=>{
  12. const arr=route.matched
  13. let temarr=arr.map(item=>{
  14. return {title:item.meta.title}
  15. })
  16. if(arr[1]&&arr[1].meta.from){
  17. temarr.splice(1,0,{title:arr[1].meta.from,path:arr[1].meta.fromPath})
  18. }
  19. return temarr
  20. })
  21. function handleClickBreadcrumb(e){
  22. console.log(e);
  23. if(e.path){
  24. router.push(e.path)
  25. }else{
  26. window.location.reload();
  27. }
  28. // router.push()
  29. }
  30. function handleCommand (command) {
  31. console.log(command);
  32. if(command === 'resetpwd') {
  33. router.push('/system/resetPwd')
  34. } else {
  35. ElMessageBox.confirm(
  36. '确认退出吗?',
  37. '提示',
  38. { type: 'warning', }
  39. ).then(() => {
  40. localStorage.removeItem('token')
  41. localStorage.removeItem('userName')
  42. router.replace('/login')
  43. }).catch()
  44. }
  45. }
  46. </script>
  47. <template>
  48. <div class="flex header-wrap">
  49. <!-- <img src="@/assets/imgs/logo.png" alt="" class="logo-img"> -->
  50. <!-- 折叠按钮 -->
  51. <el-icon size="26px" v-if="menuClose" @click="menuCloseChange" color="#333333" style="margin-left: 100px;"
  52. ><i-ep-Expand
  53. /></el-icon>
  54. <el-icon size="26px" v-else @click="menuCloseChange" color="#333333" style="margin-left: 200px;"><i-ep-Fold /></el-icon>
  55. <!-- 面包屑 -->
  56. <el-breadcrumb separator="/" style="margin-left: 30px">
  57. <el-breadcrumb-item v-for="item,index in breadcrumbArr" :key="index" @click="handleClickBreadcrumb(item)">{{
  58. item.title
  59. }}</el-breadcrumb-item>
  60. </el-breadcrumb>
  61. <div class="content"></div>
  62. <!-- 通知 -->
  63. <el-dropdown placement="bottom" trigger="click" :width="100" @command="handleCommand">
  64. <div :class="['system-notice-box']">
  65. <!-- 哈喽 {{ userName }}, 欢迎您! -->
  66. <img src="@/assets/imgs/avatar.png" alt="">
  67. <div>{{ userName }}</div>
  68. </div>
  69. <template #dropdown>
  70. <el-dropdown-menu>
  71. <el-dropdown-item command="resetpwd">修改密码</el-dropdown-item>
  72. <el-dropdown-item command="logout">退出登录</el-dropdown-item>
  73. </el-dropdown-menu>
  74. </template>
  75. </el-dropdown>
  76. </div>
  77. </template>
  78. <style lang="scss" scoped>
  79. .header-wrap {
  80. position: fixed;
  81. left: 0px;
  82. top: 0;
  83. right: 0;
  84. height: 60px;
  85. z-index: 50;
  86. background-color: #fff;
  87. box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
  88. padding: 0 30px 0 0;
  89. align-items: center;
  90. .logo-img{
  91. width: 140px;
  92. display: block;
  93. margin-left: 20px;
  94. margin-right: 40px;
  95. }
  96. :deep(.el-breadcrumb__item){
  97. .el-breadcrumb__inner{
  98. color: #053CC9;
  99. }
  100. }
  101. .content {
  102. flex: 1;
  103. }
  104. .system-notice-box{
  105. display: flex;
  106. align-items: center;
  107. img {
  108. width: 28px;
  109. height: 28px;
  110. margin-right: 10px;
  111. }
  112. }
  113. }
  114. </style>