dragbom.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 =
  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. // 引导页出现在下边
  32. if (pageHeight - dragTop > guideHeight) {
  33. data.guidePos = 'bottom';
  34. } else {
  35. // 引导页出现在左边or右边
  36. data.guidePos = dragLeft > guideWidth ? 'left' : 'right';
  37. }
  38. };
  39. onMounted(() => {
  40. setTimeout(() => {
  41. initGuidePos();
  42. }, 0);
  43. });
  44. return () => (
  45. <>
  46. <div class={[styles.dragBom, 'bom_drag']}>
  47. <div class={[styles.box, 'bom_drag_point']}></div>
  48. <div class={[styles.box, 'bom_drag_point_right', styles.right]}></div>
  49. </div>
  50. {props.showGuide && (
  51. <div
  52. class={[
  53. styles.guide,
  54. data.guidePos === 'left' && styles.guideLeft,
  55. data.guidePos === 'right' && styles.guideRight,
  56. 'bom_guide'
  57. ]}
  58. onClick={() => emit('guideDone')}>
  59. <div class={styles.guideBg}></div>
  60. <div
  61. class={styles.guideDone}
  62. onClick={e => {
  63. e.stopPropagation();
  64. emit('guideDone');
  65. }}></div>
  66. </div>
  67. )}
  68. </>
  69. );
  70. }
  71. });