index.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { defineComponent } from 'vue'
  2. import { ElButton } from 'element-plus'
  3. import './index.css'
  4. import logo from './images/logo.png'
  5. import whileLogo from './images/whileLogo.png'
  6. import { state } from '@/state'
  7. import { RouterLink } from 'vue-router'
  8. import { getAuth, getUserType } from '@/helpers/utils'
  9. import loganInfo from './modals/loganInfo'
  10. export default defineComponent({
  11. name: 'col-header',
  12. components: {
  13. loganInfo
  14. },
  15. data() {
  16. return {
  17. navigator: [
  18. { name: '首页', href: '/home', current: false },
  19. { name: '谱库', href: '/musicLibrary', current: false },
  20. { name: '视频课', href: '/videoDetailList', current: false },
  21. // { name: '云教练', href: '#', current: false },
  22. // { name: '社区', href: '#', current: false },
  23. { name: '下载', href: '/downLoad', current: false }
  24. ],
  25. navPath: ['', '/musicLibrary', '', '', '/downLoad'],
  26. isTop: false,
  27. isdark: false,
  28. token: '',
  29. userType: '',
  30. isLogin: false,
  31. userInfo: {}
  32. }
  33. },
  34. mounted() {
  35. this.token = getAuth()
  36. this.userType = getUserType()
  37. if (this.userType && this.token) {
  38. this.isLogin = true
  39. // this.userInfo =
  40. }
  41. window.addEventListener('scroll', e => {
  42. //函数体
  43. let scrollTop =
  44. document.documentElement.scrollTop | document.body.scrollTop
  45. scrollTop > 70 ? (this.isTop = true) : (this.isTop = false)
  46. })
  47. },
  48. methods: {
  49. gotoMain() {
  50. this.$router.push({ path: '/' })
  51. }
  52. },
  53. watch: {
  54. $route(res: any) {
  55. // console.log(res)
  56. this.isdark = !!res.meta.isdark
  57. this.navigator.forEach((item: any) => {
  58. item.current = false
  59. })
  60. this.navigator.forEach((item: any) => {
  61. if (item.href === res.meta.highlightPath) {
  62. item.current = true
  63. // this.isdark = !!res.meta.isdark
  64. // console.log(this.isdark)
  65. }
  66. })
  67. }
  68. },
  69. render() {
  70. return (
  71. <>
  72. {/* <div class="wall h-[70px]"></div> */}
  73. <div
  74. class={[
  75. 'headerSection backdrop-blur-sm',
  76. this.isTop ? '' : 'top',
  77. this.isdark ? 'isdark' : ''
  78. ]}
  79. >
  80. <div class="flex items-center h-full">
  81. <div class="logoWrap" onClick={() => this.gotoMain()}>
  82. <img
  83. class="w-full"
  84. src={this.isdark || !this.isTop ? logo : whileLogo}
  85. alt=""
  86. />
  87. </div>
  88. </div>
  89. <div class={['rightWrap', 'flex', 'items-center']}>
  90. <div class="flex mr120">
  91. {this.navigator.map((item: any) => (
  92. <div
  93. // onClick={() => {
  94. // this.navigator.forEach((item: any) => {
  95. // item.current = false
  96. // })
  97. // item.current = true
  98. // }}
  99. >
  100. <RouterLink
  101. to={item.href}
  102. class={[
  103. item.current ? 'activeItem' : 'normalItem',
  104. 'itemCenter'
  105. ]}
  106. >
  107. {item.name}
  108. </RouterLink>
  109. </div>
  110. ))}
  111. </div>
  112. {!this.isLogin ? (
  113. <ElButton
  114. type="primary"
  115. class="logoBtn"
  116. round
  117. onClick={() => {
  118. state.loginPopupStatus = true
  119. }}
  120. >
  121. 登录注册
  122. </ElButton>
  123. ) : (
  124. <>
  125. <div>
  126. <loganInfo></loganInfo>
  127. </div>
  128. </>
  129. )}
  130. </div>
  131. </div>
  132. {this.isTop ? <div class="wall"></div> : ''}
  133. </>
  134. )
  135. }
  136. })