File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -17,3 +17,21 @@ export function isPC(): boolean {
17
17
}
18
18
return flag ;
19
19
}
20
+
21
+ // 检测设备是否支持触摸
22
+ export function isTouchDevice ( ) : boolean {
23
+ // 检查navigator.maxTouchPoints
24
+ const maxTouchPoints =
25
+ "maxTouchPoints" in navigator && navigator . maxTouchPoints > 0 ;
26
+ // 检查旧版API navigator.msMaxTouchPoints
27
+ const msMaxTouchPoints =
28
+ "msMaxTouchPoints" in navigator && ( navigator as any ) . msMaxTouchPoints > 0 ;
29
+ // 检查触摸事件处理器
30
+ const touchEvent = "ontouchstart" in window ;
31
+ // 使用CSS媒体查询检查指针类型
32
+ const coarsePointer =
33
+ window . matchMedia && window . matchMedia ( "(pointer: coarse)" ) . matches ;
34
+
35
+ // 如果以上任何一种方法返回true,则设备支持触摸
36
+ return maxTouchPoints || msMaxTouchPoints || touchEvent || coarsePointer ;
37
+ }
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ import { fixedData } from "@/lib/common-methods/FixedData";
26
26
import { drawCutOutBox } from "@/lib/split-methods/DrawCutOutBox" ;
27
27
import { zoomCutOutBoxPosition } from "@/lib/common-methods/ZoomCutOutBoxPosition" ;
28
28
import { saveBorderArrInfo } from "@/lib/common-methods/SaveBorderArrInfo" ;
29
- import { isPC } from "@/lib/common-methods/DeviceTypeVerif" ;
29
+ import { isPC , isTouchDevice } from "@/lib/common-methods/DeviceTypeVerif" ;
30
30
31
31
const registerForRightClickEvent = (
32
32
container : HTMLElement ,
@@ -941,8 +941,9 @@ const setScreenShotContainerEventListener = (
941
941
containerFn . mouseMoveEvent
942
942
) ;
943
943
screenShotContainer ?. addEventListener ( "mouseup" , containerFn . mouseUpEvent ) ;
944
- return ;
945
944
}
945
+ // 设备不支持触摸事件则退出
946
+ if ( ! isTouchDevice ( ) ) return ;
946
947
// 设置触摸监听
947
948
screenShotContainer ?. addEventListener (
948
949
"touchstart" ,
You can’t perform that action at this time.
0 commit comments