index.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { defineComponent, nextTick, onMounted, ref } from 'vue'
  2. import styles from './index.module.less'
  3. import IconMall from '../../images/icon-mall.png'
  4. import IconSearch from '../../images/icon-search.png'
  5. import IconScan from '../../images/icon-scan.png'
  6. import IconMessage from '../../images/icon-message.png'
  7. import { postMessage } from '@/helpers/native-message'
  8. import TheHomeHeader from '@/views/shop-mall/components/TheHomeHeader'
  9. import { useRect } from '@vant/use'
  10. import ColSticky from '@/components/col-sticky'
  11. export default defineComponent({
  12. name: 'TheHomeHeader',
  13. emits: ['cart', 'more', 'search', 'headerDom'],
  14. setup(props, { emit, expose }) {
  15. const navBarHeight = ref(sessionStorage.getItem('navHeight'))
  16. const init = () => {
  17. // 设置是否显示导航栏 0 显示 1 不显示
  18. postMessage({ api: 'setBarStatus', content: { status: 0 } })
  19. if (navBarHeight.value) return
  20. postMessage({ api: 'getNavHeight' }, res => {
  21. const { content } = res as any
  22. const dpi = content.dpi || 2
  23. if (content.navHeight) {
  24. const navHeight = content.navHeight / dpi + ''
  25. sessionStorage.setItem('navHeight', navHeight)
  26. navBarHeight.value = navHeight
  27. }
  28. })
  29. }
  30. init()
  31. const homeHeaderDom = ref(null)
  32. onMounted(() => {
  33. nextTick(() => {
  34. setTimeout(() => {
  35. const { height } = useRect(homeHeaderDom as any)
  36. emit('headerDom', height)
  37. }, 300)
  38. })
  39. })
  40. return () => (
  41. <ColSticky position="top">
  42. <div class={styles.theHomeHeader} ref={homeHeaderDom}>
  43. <div
  44. style={{ height: navBarHeight.value + 'px', background: '#fff' }}
  45. ></div>
  46. <div class={styles.content}>
  47. <img class={styles.mall} src={IconMall} />
  48. <div class={styles.searchBox} onClick={() => emit('search')}>
  49. <img class={styles.iconSearch} src={IconSearch} />
  50. <span>搜索你喜欢的内容</span>
  51. </div>
  52. <img
  53. class={styles.cart}
  54. src={IconScan}
  55. onClick={() => emit('cart')}
  56. />
  57. <img
  58. class={styles.cart}
  59. src={IconMessage}
  60. onClick={() => emit('more')}
  61. />
  62. </div>
  63. </div>
  64. </ColSticky>
  65. )
  66. }
  67. })