start-menu-button.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <script setup lang="ts">
  2. import { onMounted, ref } from 'vue'
  3. const menuBtnClientRect = ref<UniNamespace.GetMenuButtonBoundingClientRectRes>({
  4. width: 0,
  5. height: 0,
  6. top: 0,
  7. right: 0,
  8. bottom: 0,
  9. left: 0,
  10. })
  11. const startMenuBtnStyle = ref({
  12. width: '0px',
  13. height: '0px',
  14. left: '0px',
  15. top: '0px',
  16. })
  17. // 获取小程序胶囊距离
  18. onMounted(async () => {
  19. const { windowWidth } = await uni.getWindowInfo()
  20. // console.log(windowHeight, windowWidth)
  21. // #ifdef MP-WEIXIN
  22. menuBtnClientRect.value = await uni.getMenuButtonBoundingClientRect()
  23. // console.log(menuBtnClientRect.value)
  24. startMenuBtnStyle.value = {
  25. width: menuBtnClientRect.value.width + 'px',
  26. height: menuBtnClientRect.value.height + 'px',
  27. top: `${menuBtnClientRect.value.top}px`,
  28. left: `${windowWidth - menuBtnClientRect.value.right}px`,
  29. }
  30. // console.log(startMenuBtnStyle.value)
  31. // #endif
  32. })
  33. </script>
  34. <template>
  35. <div>
  36. <!-- <div :style="{ height: menuBtnClientRect.top + 'px' }"></div> -->
  37. <div
  38. class="fixed rounded-full flex items-center px-3 box-border bg-green z-1"
  39. :style="startMenuBtnStyle"
  40. >
  41. <slot></slot>
  42. </div>
  43. </div>
  44. </template>