index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. userInfo: {}
  31. }
  32. },
  33. computed: {
  34. isLogin() {
  35. // const token = getAuth()
  36. // const userType = getUserType()
  37. if (state.user.data.userId) {
  38. return true
  39. }
  40. return false
  41. }
  42. },
  43. mounted() {
  44. window.addEventListener('scroll', e => {
  45. //函数体
  46. let scrollTop =
  47. document.documentElement.scrollTop | document.body.scrollTop
  48. scrollTop > 70 ? (this.isTop = true) : (this.isTop = false)
  49. })
  50. },
  51. methods: {
  52. gotoMain() {
  53. this.$router.push({ path: '/' })
  54. }
  55. },
  56. watch: {
  57. $route(res: any) {
  58. // console.log(res)
  59. this.isdark = !!res.meta.isdark
  60. this.navigator.forEach((item: any) => {
  61. item.current = false
  62. })
  63. this.navigator.forEach((item: any) => {
  64. if (item.href === res.meta.highlightPath) {
  65. item.current = true
  66. // this.isdark = !!res.meta.isdark
  67. // console.log(this.isdark)
  68. }
  69. })
  70. }
  71. },
  72. render() {
  73. return (
  74. <>
  75. {/* <div class="wall h-[70px]"></div> */}
  76. <div
  77. class={[
  78. 'headerSection backdrop-blur-sm',
  79. this.isTop ? '' : 'top',
  80. this.isdark ? 'isdark' : ''
  81. ]}
  82. >
  83. <div class="flex items-center h-full">
  84. <div class="logoWrap" onClick={() => this.gotoMain()}>
  85. {/* this.isdark || */}
  86. <img
  87. class="w-full"
  88. src={ !this.isTop ? logo : whileLogo}
  89. alt=""
  90. />
  91. </div>
  92. </div>
  93. <div class={['rightWrap', 'flex', 'items-center']}>
  94. <div class="flex mr120">
  95. {this.navigator.map((item: any) => (
  96. <div
  97. // onClick={() => {
  98. // this.navigator.forEach((item: any) => {
  99. // item.current = false
  100. // })
  101. // item.current = true
  102. // }}
  103. >
  104. <RouterLink
  105. to={item.href}
  106. class={[
  107. item.current ? 'activeItem' : 'normalItem',
  108. 'itemCenter'
  109. ]}
  110. >
  111. {item.name}
  112. </RouterLink>
  113. </div>
  114. ))}
  115. </div>
  116. {!this.isLogin ? (
  117. <ElButton
  118. type="primary"
  119. class="logoBtn"
  120. round
  121. onClick={() => {
  122. state.loginPopupStatus = true
  123. }}
  124. >
  125. 登录注册
  126. </ElButton>
  127. ) : (
  128. <>
  129. <div>
  130. <loganInfo></loganInfo>
  131. </div>
  132. </>
  133. )}
  134. </div>
  135. </div>
  136. {this.isTop ? <div class="wall"></div> : ''}
  137. </>
  138. )
  139. }
  140. })