zhengyiming
17 小时以前 745f1e2ee7072731611391b89c5c0020783828bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * @Descripttion: useCalculate
 * @version:
 * @Author: wuchenguang1998
 * @Date: 2024-05-18 15:42:17
 * @LastEditors: wuchenguang1998
 * @LastEditTime: 2024-05-18 17:28:34
 */
 
export default function useCalculate() {
  const canvasEditor = inject('canvasEditor');
 
  // 获取画布的DOMRect对象
  const getCanvasBound = () => canvasEditor.canvas.getSelectionElement().getBoundingClientRect();
 
  // 判断拖拽结束的坐标是否在画布外
  const isOutsideCanvas = (x, y) => {
    const { left, right, top, bottom } = getCanvasBound();
    return x < left || x > right || y < top || y > bottom;
  };
 
  return {
    getCanvasBound,
    isOutsideCanvas,
  };
}