header.vue 3.1 KB

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