Skip to content

Commit dfc1688

Browse files
committed
refactor: 重构代码
1 parent 85f24d2 commit dfc1688

File tree

1 file changed

+11
-19
lines changed
  • src/BootstrapBlazor/wwwroot/modules

1 file changed

+11
-19
lines changed

src/BootstrapBlazor/wwwroot/modules/input.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
11
import EventHandler from "./event-handler.js"
22

33
export default {
4-
composition(id, invoke, callback) {
5-
const el = document.getElementById(id)
4+
composition(el, callback) {
65
if (el) {
7-
var isInputZh = false
6+
let isComposing = false
87
EventHandler.on(el, 'compositionstart', e => {
9-
isInputZh = true
10-
})
8+
isComposing = true;
9+
});
1110
EventHandler.on(el, 'compositionend', e => {
12-
isInputZh = false
13-
})
11+
isComposing = false;
12+
callback(el.value);
13+
});
1414
EventHandler.on(el, 'input', e => {
15-
if (isInputZh) {
16-
e.stopPropagation()
17-
e.preventDefault()
18-
const handler = setTimeout(() => {
19-
if (!isInputZh) {
20-
clearTimeout(handler)
21-
invoke.invokeMethodAsync(callback, el.value)
22-
}
23-
}, 15)
15+
if (!isComposing) {
16+
callback(el.value);
2417
}
25-
})
18+
});
2619
}
2720
},
2821

29-
dispose(id) {
30-
const el = document.getElementById(id)
22+
dispose(el) {
3123
if (el) {
3224
EventHandler.off(el, 'compositionstart')
3325
EventHandler.off(el, 'compositionend')

0 commit comments

Comments
 (0)