提交 55c783e7 编写于 作者: X xiaoyucoding

feat: 处理 input number 类型部分输入法可以输入其它字符的情况

上级 52744ab3
#### image
|属性名|已完成|
|:-|:-|
|src|Y|
|mode|Y|
|lazy-load||
|@error|Y|
|@load|Y|
\ No newline at end of file
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
@input.stop="_onInput" @input.stop="_onInput"
@compositionstart="_onComposition" @compositionstart="_onComposition"
@compositionend="_onComposition" @compositionend="_onComposition"
@keyup.stop="_onKeyup"> @keyup.stop="_onKeyup"
>
<div <div
v-show="!(composing || inputValue.length)" v-show="!(composing || inputValue.length)"
ref="placeholder" ref="placeholder"
...@@ -31,6 +32,7 @@ import { ...@@ -31,6 +32,7 @@ import {
emitter emitter
} from 'uni-mixins' } from 'uni-mixins'
const TYPES = ['text', 'number', 'idcard', 'digit', 'password'] const TYPES = ['text', 'number', 'idcard', 'digit', 'password']
const NUMBER_TYPES = ['number', 'digit']
export default { export default {
name: 'Input', name: 'Input',
mixins: [emitter], mixins: [emitter],
...@@ -88,7 +90,8 @@ export default { ...@@ -88,7 +90,8 @@ export default {
return { return {
inputValue: this.value + '', inputValue: this.value + '',
composing: false, composing: false,
wrapperHeight: 0 wrapperHeight: 0,
cachedValue: ''
} }
}, },
computed: { computed: {
...@@ -124,13 +127,7 @@ export default { ...@@ -124,13 +127,7 @@ export default {
this.inputValue = value + '' this.inputValue = value + ''
}, },
inputValue (value) { inputValue (value) {
// if (value !== this.value) {
// this.$trigger('input', {}, {
// value: value,
// cursor: this.$refs.input.selectionEnd
// })
this.$emit('update:value', value) this.$emit('update:value', value)
// }
}, },
maxlength (value) { maxlength (value) {
const realValue = this.realValue.slice(0, value) const realValue = this.realValue.slice(0, value)
...@@ -194,11 +191,19 @@ export default { ...@@ -194,11 +191,19 @@ export default {
if (this.composing) { if (this.composing) {
return return
} }
const value = $event.target.value
this.inputValue = value // 处理部分输入法可以输入其它字符的情况
if (~NUMBER_TYPES.indexOf(this.type)) {
if (this.$refs.input.validity && !this.$refs.input.validity.valid) {
this.inputValue = this.cachedValue
$event.target.value = this.cachedValue
} else {
this.cachedValue = this.inputValue
}
}
this.$trigger('input', $event, { this.$trigger('input', $event, {
value: value value: this.inputValue
}) })
}, },
_onFocus ($event) { _onFocus ($event) {
...@@ -226,7 +231,6 @@ export default { ...@@ -226,7 +231,6 @@ export default {
this.composing = true this.composing = true
} else { } else {
this.composing = false this.composing = false
// TODO
} }
}, },
_resetFormData () { _resetFormData () {
...@@ -274,6 +278,7 @@ export default { ...@@ -274,6 +278,7 @@ export default {
text-overflow: inherit; text-overflow: inherit;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
z-index: 2; z-index: 2;
opacity: inherit;
} }
uni-input[hidden] { uni-input[hidden] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册