index.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { defineComponent, 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 IconCart from '../../images/icon-cart.png'
  6. import IconMore from '../../images/icon-more.png'
  7. import IconLocation from '../../images/icon-location.png'
  8. import IconOrder from '../../images/icon-order.png'
  9. import { Popover } from 'vant'
  10. import { postMessage } from '@/helpers/native-message'
  11. export default defineComponent({
  12. name: 'TheHomeHeader',
  13. emits: ['cart', 'more', 'search'],
  14. setup(props, { emit }) {
  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 popoverSlots = {
  32. reference: () => (
  33. <img class={styles.more} src={IconMore} onClick={() => emit('more')} />
  34. )
  35. }
  36. const popoverShow = ref(false)
  37. const actions = [
  38. { text: '我的订单', icon: IconLocation, url: '/goodsOrder' },
  39. { text: '我的地址', icon: IconOrder, url: '/' }
  40. ]
  41. return () => (
  42. <div class={styles.theHomeHeader}>
  43. <div style={{ height: navBarHeight.value + 'px' }}></div>
  44. <div class={styles.content}>
  45. <img class={styles.mall} src={IconMall} />
  46. <div class={styles.searchBox} onClick={() => emit('search')}>
  47. <img class={styles.iconSearch} src={IconSearch} />
  48. <span>搜索你喜欢的内容</span>
  49. </div>
  50. <img
  51. class={styles.cart}
  52. src={IconCart}
  53. onClick={() => emit('cart')}
  54. />
  55. <Popover
  56. placement="bottom-end"
  57. class={styles.popover}
  58. v-model:show={popoverShow.value}
  59. v-slots={popoverSlots}
  60. actions={actions}
  61. onSelect={action => emit('more', action)}
  62. ></Popover>
  63. </div>
  64. </div>
  65. )
  66. }
  67. })