dragbom.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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' | 'middle'
  17. });
  18. const initGuidePos = () => {
  19. const pageHeight =
  20. document.documentElement.clientHeight || document.body.clientHeight;
  21. const pageWidth =
  22. document.documentElement.clientWidth || document.body.clientWidth;
  23. const guideHeight =
  24. document.querySelector('.bom_guide')?.clientHeight || 0;
  25. const guideWidth = document.querySelector('.bom_guide')?.clientWidth || 0;
  26. const dragBBox = document
  27. .querySelector('.bom_drag')
  28. ?.getBoundingClientRect();
  29. const dragTop = dragBBox?.top || 0;
  30. const dragLeft = dragBBox?.left || 0;
  31. const dragRight = dragBBox?.right || 0;
  32. // console.log(dragTop, dragBBox, pageHeight, guideHeight);
  33. // 引导页出现在下边
  34. if (pageHeight - dragTop > guideHeight) {
  35. data.guidePos = 'bottom';
  36. } else {
  37. // 引导页出现在左边or右边
  38. if (dragLeft > guideWidth) {
  39. data.guidePos = 'left';
  40. } else if (pageWidth - dragRight > guideWidth) {
  41. data.guidePos = 'right';
  42. } else {
  43. data.guidePos = 'middle';
  44. }
  45. // data.guidePos = dragLeft > guideWidth ? 'left' : 'right';
  46. }
  47. data.guidePos = 'middle';
  48. // console.log(data.guidePos, '121212');
  49. };
  50. onMounted(() => {
  51. setTimeout(() => {
  52. initGuidePos();
  53. }, 0);
  54. });
  55. return () => (
  56. <>
  57. <div class={[styles.dragBom, 'bom_drag']}>
  58. <div class={[styles.box, 'bom_drag_point']}></div>
  59. <div class={[styles.box, 'bom_drag_point_right', styles.right]}></div>
  60. </div>
  61. {props.showGuide && (
  62. <div
  63. class={[
  64. styles.guide,
  65. data.guidePos === 'left' && styles.guideLeft,
  66. data.guidePos === 'right' && styles.guideRight,
  67. data.guidePos === 'middle' && styles.guidemiddle,
  68. 'bom_guide'
  69. ]}
  70. onClick={() => emit('guideDone')}>
  71. <div class={styles.guideBg}></div>
  72. <div
  73. class={styles.guideDone}
  74. onClick={e => {
  75. e.stopPropagation();
  76. emit('guideDone');
  77. }}></div>
  78. </div>
  79. )}
  80. </>
  81. );
  82. }
  83. });