提交 dbb3d133 编写于 作者: D DCloud_LXH

feat: input 添加 tel 属性、添加 text-content-type 属性

上级 53c644b1
import { extend } from '@vue/shared' import { extend, hyphenate } from '@vue/shared'
import { Ref, ref, computed } from 'vue' import { Ref, ref, computed } from 'vue'
import { defineBuiltInComponent } from '../../helpers/component' import { defineBuiltInComponent } from '../../helpers/component'
import { import {
...@@ -12,6 +12,10 @@ const props = /*#__PURE__*/ extend({}, fieldProps, { ...@@ -12,6 +12,10 @@ const props = /*#__PURE__*/ extend({}, fieldProps, {
type: String, type: String,
default: 'input-placeholder', default: 'input-placeholder',
}, },
textContentType: {
type: String,
default: '',
},
}) })
export default /*#__PURE__*/ defineBuiltInComponent({ export default /*#__PURE__*/ defineBuiltInComponent({
...@@ -19,7 +23,8 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -19,7 +23,8 @@ export default /*#__PURE__*/ defineBuiltInComponent({
props, props,
emits: ['confirm', ...fieldEmit], emits: ['confirm', ...fieldEmit],
setup(props, { emit }) { setup(props, { emit }) {
const INPUT_TYPES = ['text', 'number', 'idcard', 'digit', 'password'] const INPUT_TYPES = ['text', 'number', 'idcard', 'digit', 'password', 'tel']
const AUTOCOMPLETES = ['off', 'one-time-code']
const type = computed(() => { const type = computed(() => {
let type = '' let type = ''
switch (props.type) { switch (props.type) {
...@@ -41,6 +46,19 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -41,6 +46,19 @@ export default /*#__PURE__*/ defineBuiltInComponent({
} }
return props.password ? 'password' : type return props.password ? 'password' : type
}) })
const autocomplete = computed(() => {
const camelizeIndex = AUTOCOMPLETES.indexOf(props.textContentType)
const kebabCaseIndex = AUTOCOMPLETES.indexOf(
hyphenate(props.textContentType)
)
const index =
camelizeIndex !== -1
? camelizeIndex
: kebabCaseIndex !== -1
? kebabCaseIndex
: 0
return AUTOCOMPLETES[index]
})
let cache = ref('') let cache = ref('')
let resetCache: (() => void) | null let resetCache: (() => void) | null
...@@ -132,7 +150,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -132,7 +150,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
enterkeyhint={props.confirmType} enterkeyhint={props.confirmType}
pattern={props.type === 'number' ? '[0-9]*' : undefined} pattern={props.type === 'number' ? '[0-9]*' : undefined}
class="uni-input-input" class="uni-input-input"
autocomplete="off" autocomplete={autocomplete.value}
onKeyup={onKeyUpEnter} onKeyup={onKeyUpEnter}
/> />
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册