Skip to content

Commit 3eb1c82

Browse files
author
likai
committed
fix: 修复windows触屏设备无法使用问题
1 parent 98d77fc commit 3eb1c82

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/lib/common-methods/DeviceTypeVerif.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ export function isPC(): boolean {
1717
}
1818
return flag;
1919
}
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+
}

src/lib/main-entrance/LoadCoreComponents.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { fixedData } from "@/lib/common-methods/FixedData";
2626
import { drawCutOutBox } from "@/lib/split-methods/DrawCutOutBox";
2727
import { zoomCutOutBoxPosition } from "@/lib/common-methods/ZoomCutOutBoxPosition";
2828
import { saveBorderArrInfo } from "@/lib/common-methods/SaveBorderArrInfo";
29-
import { isPC } from "@/lib/common-methods/DeviceTypeVerif";
29+
import { isPC, isTouchDevice } from "@/lib/common-methods/DeviceTypeVerif";
3030

3131
const registerForRightClickEvent = (
3232
container: HTMLElement,
@@ -941,8 +941,9 @@ const setScreenShotContainerEventListener = (
941941
containerFn.mouseMoveEvent
942942
);
943943
screenShotContainer?.addEventListener("mouseup", containerFn.mouseUpEvent);
944-
return;
945944
}
945+
// 设备不支持触摸事件则退出
946+
if (!isTouchDevice()) return;
946947
// 设置触摸监听
947948
screenShotContainer?.addEventListener(
948949
"touchstart",

0 commit comments

Comments
 (0)