header.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="header">
  3. <div class="con">
  4. <div class="logo">
  5. <img :src="require('@/assets/images/icons/img_logo.png')" alt="" />
  6. </div>
  7. <ul class="tab">
  8. <li @click="handleItem(item)" :class="{active:active.id==item.id}" v-for="(item, i) in tab" :key="i">
  9. {{ item.name }}
  10. </li>
  11. </ul>
  12. <div class="user">
  13. <img title="回到个人中心" @click="backtoInfo" :src="userInfo.head||$thumb" alt="" />
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. active:{},
  23. tab: [
  24. {
  25. name: "全景作品",
  26. id: "works",
  27. path:{
  28. path:'/works'
  29. }
  30. },
  31. {
  32. name: "我的素材",
  33. id: "material",
  34. path:{
  35. path:'/'
  36. }
  37. }
  38. ],
  39. };
  40. },
  41. computed:{
  42. userInfo(){
  43. let info = {}
  44. try {
  45. info = JSON.parse(localStorage.getItem('info')) || {}
  46. } catch (e) {
  47. info= {}
  48. }
  49. return info
  50. }
  51. },
  52. watch:{
  53. '$route.meta':{
  54. deep:true,
  55. handler:function (newVal) {
  56. this.active = this.tab.find(item=>{
  57. return item.id == newVal.belong
  58. })
  59. }
  60. }
  61. },
  62. methods:{
  63. backtoInfo(){
  64. window.location.href = '/#/information'
  65. },
  66. handleItem(item){
  67. this.$router.push(item.path)
  68. }
  69. }
  70. };
  71. </script>
  72. <style lang="less" scoped>
  73. .header {
  74. width: 100%;
  75. background: #fff;
  76. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
  77. position: fixed;
  78. top: 0;
  79. left: 0;
  80. z-index: 999;
  81. .con {
  82. color: #000;
  83. max-width: 1280px;
  84. height: 70px;
  85. display: flex;
  86. align-items: center;
  87. margin: 0 auto;
  88. position: relative;
  89. padding: 0;
  90. .logo {
  91. font-size: 24px;
  92. font-weight: bold;
  93. width: 188px;
  94. >img{
  95. width: 100%;
  96. vertical-align: middle;
  97. }
  98. }
  99. .tab {
  100. display: flex;
  101. align-items: center;
  102. margin-left: 116px;
  103. > li {
  104. cursor: pointer;
  105. margin-right: 50px;
  106. text-align: left;
  107. font-size: 16px;
  108. color: #909090;
  109. &.active{
  110. color: #202020;
  111. font-weight: 600;
  112. }
  113. }
  114. }
  115. .user {
  116. position: absolute;
  117. right: 0;
  118. top: 50%;
  119. transform: translateY(-50%);
  120. border-radius: 50%;
  121. width: 32px;
  122. height: 32px;
  123. overflow: hidden;
  124. > img {
  125. cursor: pointer;
  126. height: 100%;
  127. position: absolute;
  128. top: 50%;
  129. transform: translate(-50%, -50%);
  130. left: 50%;
  131. }
  132. }
  133. }
  134. }
  135. </style>