From ddf2fe3751d61641889fce1d7a949eb51aebd1b5 Mon Sep 17 00:00:00 2001 From: shenyifei Date: Wed, 24 Dec 2025 15:14:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(captcha):=20=E4=BF=AE=E5=A4=8D=E6=BB=91?= =?UTF-8?q?=E5=9D=97=E9=AA=8C=E8=AF=81=E7=A0=81=E5=9C=A8=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E7=AB=AF=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 兼容触摸事件和鼠标事件,支持移动端和桌面端 - 添加鼠标移动、鼠标抬起和鼠标离开事件处理 - 修复坐标获取逻辑,统一处理触摸和鼠标坐标 - 移除调试日志,优化控制台输出 - 添加环境判断,生产环境不加载vConsole --- packages/app-client/src/app.tsx | 6 ++++-- packages/app-client/src/components/captcha/index.jsx | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/app-client/src/app.tsx b/packages/app-client/src/app.tsx index ee9d74b..43ccc5a 100644 --- a/packages/app-client/src/app.tsx +++ b/packages/app-client/src/app.tsx @@ -69,8 +69,10 @@ function App({ children }: PropsWithChildren) { root.render(); // 初始化vConsole调试工具 - const VConsole = require("vconsole"); - new VConsole(); + if (process.env.NODE_ENV === "development") { + const VConsole = require("vconsole"); + new VConsole(); + } } }); diff --git a/packages/app-client/src/components/captcha/index.jsx b/packages/app-client/src/components/captcha/index.jsx index c824b9e..9a0a137 100644 --- a/packages/app-client/src/components/captcha/index.jsx +++ b/packages/app-client/src/components/captcha/index.jsx @@ -164,12 +164,13 @@ class Captcha extends Component { } }; - // 鼠标移动时的事件处理函数 + // 鼠标/触摸移动时的事件处理函数 move = (e) => { console.log(e, "滑动滑动"); if (this.state.status && !this.state.isEnd) { - console.log(e.touches[0].pageX); - let x = e.touches[0].pageX; // 获取鼠标/触摸点的X坐标 + // 兼容触摸事件和鼠标事件 + let x = e.touches ? e.touches[0].pageX : e.pageX; // 获取鼠标/触摸点的X坐标 + console.log(x); let bar_area_left = this.state.barAreaLeft; // 滑块区域左侧距离 let move_block_left = x - bar_area_left; // 计算移动块的左侧距离 console.log( @@ -355,7 +356,10 @@ class Captcha extends Component { onTouchStart={this.start} onMouseDown={this.start} onTouchMove={this.move} + onMouseMove={this.move} onTouchEnd={this.end} + onMouseUp={this.end} + onMouseLeave={this.end} style={{ width: barSize.height, height: barSize.height,