front/src/utils/keyboard.ts
zzh e2a3a8c10a
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m2s
feat: 仓租配置与日账单页,并同步工作台/H5/微信通知等前端改动
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-15 15:27:48 +08:00

23 lines
735 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 键盘 / IME 相关工具(Mac 拼音组字、跨端修饰键等)
*/
/** 中文等 IME 组字过程中:不应触发扫描回车 / 提交 */
export function isImeComposingEvent(e: unknown): boolean {
if (!e || typeof e !== 'object') return false
const ev = e as KeyboardEvent & { keyCode?: number }
if (ev.isComposing) return true
if (ev.key === 'Process') return true
// 旧浏览器 / 部分输入法仍用 229
if (typeof ev.keyCode === 'number' && ev.keyCode === 229) return true
return false
}
/** 包装无参回车处理:组字中直接忽略 */
export function withImeEnterGuard(fn: () => void | Promise<void>) {
return (e?: Event) => {
if (isImeComposingEvent(e)) return
void fn()
}
}