dragbom.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { defineComponent, computed, reactive, onMounted } from 'vue';
  2. import styles from './index.module.less';
  3. // 底部拖动区域
  4. export default defineComponent({
  5. name: 'dragBom',
  6. emits: ["guideDone"],
  7. props: {
  8. /** 是否显示引导 */
  9. showGuide: {
  10. type: Boolean,
  11. default: false,
  12. },
  13. },
  14. setup(props, { emit }) {
  15. const data = reactive({
  16. guidePos: "bottom" as "bottom" | "left" | "right",
  17. });
  18. const initGuidePos = () => {
  19. const pageHeight = document.documentElement.clientHeight || document.body.clientHeight;
  20. const pageWidth = document.documentElement.clientWidth || document.body.clientWidth;
  21. const guideHeight = document.querySelector('.bom_guide')?.clientHeight || 0;
  22. const guideWidth = document.querySelector('.bom_guide')?.clientWidth || 0;
  23. const dragBBox = document.querySelector('.bom_drag')?.getBoundingClientRect();
  24. const dragTop = dragBBox?.top || 0;
  25. const dragLeft = dragBBox?.left || 0;
  26. // 引导页出现在下边
  27. if (pageHeight - dragTop > guideHeight) {
  28. data.guidePos = "bottom"
  29. } else {
  30. // 引导页出现在左边or右边
  31. data.guidePos = dragLeft > guideWidth ? "left" : "right"
  32. }
  33. }
  34. onMounted(() => {
  35. setTimeout(() => {
  36. initGuidePos();
  37. }, 0);
  38. });
  39. return () => (
  40. <>
  41. <div class={[styles.dragbomBox,"dragbomBox"]}>
  42. <div class={[styles.dragBom, 'bom_drag']}>
  43. <div class={styles.box}></div>
  44. <div class={[styles.box, styles.right]}></div>
  45. </div>
  46. </div>
  47. {
  48. props.showGuide &&
  49. <div class={[styles.guide, data.guidePos === "left" && styles.guideLeft, data.guidePos === "right" && styles.guideRight, 'bom_guide']} onClick={() => emit("guideDone")}>
  50. <div class={styles.guideBg}></div>
  51. <div class={styles.guideDone} onClick={(e) => {e.stopPropagation();emit("guideDone")}}></div>
  52. </div>
  53. }
  54. </>
  55. );
  56. }
  57. });