mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: migrate NumberKeyboard component
This commit is contained in:
parent
bfe2e9843b
commit
a70d1187fb
@ -52,4 +52,5 @@ module.exports = [
|
|||||||
'radio',
|
'radio',
|
||||||
'radio-group',
|
'radio-group',
|
||||||
'datetime-picker',
|
'datetime-picker',
|
||||||
|
'number-keyboard',
|
||||||
];
|
];
|
||||||
|
@ -18,6 +18,8 @@ export default createComponent({
|
|||||||
loading: Boolean,
|
loading: Boolean,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['press'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
active: false,
|
active: false,
|
||||||
@ -57,7 +59,7 @@ export default createComponent({
|
|||||||
genContent() {
|
genContent() {
|
||||||
const isExtra = this.type === 'extra';
|
const isExtra = this.type === 'extra';
|
||||||
const isDelete = this.type === 'delete';
|
const isDelete = this.type === 'delete';
|
||||||
const text = this.slots('default') || this.text;
|
const text = this.$slots.default ? this.$slots.default() : this.text;
|
||||||
|
|
||||||
if (this.loading) {
|
if (this.loading) {
|
||||||
return <Loading class={bem('loading-icon')} />;
|
return <Loading class={bem('loading-icon')} />;
|
||||||
|
@ -14,7 +14,7 @@ Vue.use(NumberKeyboard);
|
|||||||
### Default Keyboard
|
### Default Keyboard
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell @touchstart.native.stop="show = true">
|
<van-cell @touchstart.stop="show = true">
|
||||||
Show Keyboard
|
Show Keyboard
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
@ -64,7 +64,7 @@ export default {
|
|||||||
Use `extra-key` prop to set the content of bottom left button
|
Use `extra-key` prop to set the content of bottom left button
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell plain type="primary" @touchstart.native.stop="show = true">
|
<van-cell plain type="primary" @touchstart.stop="show = true">
|
||||||
Show IdNumber Keyboard
|
Show IdNumber Keyboard
|
||||||
</van-cell>
|
</van-cell>
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ Use `extra-key` prop to set the content of bottom left button
|
|||||||
Use `title` prop to set keyboard title
|
Use `title` prop to set keyboard title
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell plain type="info" @touchstart.native.stop="show = true">
|
<van-cell plain type="info" @touchstart.stop="show = true">
|
||||||
Show Keyboard With Title
|
Show Keyboard With Title
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
@ -100,7 +100,7 @@ Use `title` prop to set keyboard title
|
|||||||
### Multiple ExtraKey
|
### Multiple ExtraKey
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell plain type="primary" @touchstart.native.stop="show = true">
|
<van-cell plain type="primary" @touchstart.stop="show = true">
|
||||||
Show Keyboard With Multiple ExtraKey
|
Show Keyboard With Multiple ExtraKey
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
@ -116,12 +116,7 @@ Use `title` prop to set keyboard title
|
|||||||
### Bind Value
|
### Bind Value
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-field
|
<van-field readonly clickable :value="value" @touchstart.stop="show = true" />
|
||||||
readonly
|
|
||||||
clickable
|
|
||||||
:value="value"
|
|
||||||
@touchstart.native.stop="show = true"
|
|
||||||
/>
|
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:show="show"
|
:show="show"
|
||||||
|
@ -20,7 +20,7 @@ Vue.use(NumberKeyboard);
|
|||||||
数字键盘提供了 `input`、`delete`、`blur` 事件,分别对应输入内容、删除内容和失去焦点的动作
|
数字键盘提供了 `input`、`delete`、`blur` 事件,分别对应输入内容、删除内容和失去焦点的动作
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell @touchstart.native.stop="show = true">
|
<van-cell @touchstart.stop="show = true">
|
||||||
弹出默认键盘
|
弹出默认键盘
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
@ -74,7 +74,7 @@ export default {
|
|||||||
通过 `extra-key` 属性可以设置左下角按键内容,比如需要输入身份证号时,可以将 `extra-key` 设置为 `X`
|
通过 `extra-key` 属性可以设置左下角按键内容,比如需要输入身份证号时,可以将 `extra-key` 设置为 `X`
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell plain type="primary" @touchstart.native.stop="show = true">
|
<van-cell plain type="primary" @touchstart.stop="show = true">
|
||||||
弹出身份证号键盘
|
弹出身份证号键盘
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
@ -92,7 +92,7 @@ export default {
|
|||||||
通过 `title` 属性可以设置键盘标题
|
通过 `title` 属性可以设置键盘标题
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell plain type="info" @touchstart.native.stop="show = true">
|
<van-cell plain type="info" @touchstart.stop="show = true">
|
||||||
弹出带标题的键盘
|
弹出带标题的键盘
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
@ -111,7 +111,7 @@ export default {
|
|||||||
当 theme 为 `custom` 时,支持以数组的形式配置两个 `extra-key`
|
当 theme 为 `custom` 时,支持以数组的形式配置两个 `extra-key`
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cell plain type="primary" @touchstart.native.stop="show = true">
|
<van-cell plain type="primary" @touchstart.stop="show = true">
|
||||||
弹出配置多个按键的键盘
|
弹出配置多个按键的键盘
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
@ -129,12 +129,7 @@ export default {
|
|||||||
可以通过 `v-model` 绑定键盘当前输入值
|
可以通过 `v-model` 绑定键盘当前输入值
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-field
|
<van-field readonly clickable :value="value" @touchstart.stop="show = true" />
|
||||||
readonly
|
|
||||||
clickable
|
|
||||||
:value="value"
|
|
||||||
@touchstart.native.stop="show = true"
|
|
||||||
/>
|
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:show="show"
|
:show="show"
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
<template>
|
<template>
|
||||||
<demo-section>
|
<demo-section>
|
||||||
<van-cell is-link @touchstart.native.stop="keyboard = 'default'">
|
<van-cell is-link @touchstart.stop="keyboard = 'default'">
|
||||||
{{ t('button1') }}
|
{{ t('button1') }}
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-cell is-link @touchstart.native.stop="keyboard = 'custom'">
|
<van-cell is-link @touchstart.stop="keyboard = 'custom'">
|
||||||
{{ t('button2') }}
|
{{ t('button2') }}
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-cell is-link @touchstart.native.stop="keyboard = 'extraKey'">
|
<van-cell is-link @touchstart.stop="keyboard = 'extraKey'">
|
||||||
{{ t('button3') }}
|
{{ t('button3') }}
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-cell is-link @touchstart.native.stop="keyboard = 'title'">
|
<van-cell is-link @touchstart.stop="keyboard = 'title'">
|
||||||
{{ t('button4') }}
|
{{ t('button4') }}
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-cell is-link @touchstart.native.stop="keyboard = 'multiExtraKey'">
|
<van-cell is-link @touchstart.stop="keyboard = 'multiExtraKey'">
|
||||||
{{ t('button5') }}
|
{{ t('button5') }}
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-field
|
<van-field
|
||||||
readonly
|
readonly
|
||||||
clickable
|
clickable
|
||||||
:value="value"
|
|
||||||
:label="t('bindValue')"
|
:label="t('bindValue')"
|
||||||
|
:model-value="value"
|
||||||
:placeholder="t('clickToInput')"
|
:placeholder="t('clickToInput')"
|
||||||
@touchstart.native.stop="keyboard = 'bindValue'"
|
@touchstart.stop="keyboard = 'bindValue'"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<van-number-keyboard
|
<van-number-keyboard
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Transition } from 'vue';
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import { stopPropagation } from '../utils/dom/event';
|
import { stopPropagation } from '../utils/dom/event';
|
||||||
import { PortalMixin } from '../mixins/portal';
|
import { PortalMixin } from '../mixins/portal';
|
||||||
@ -16,10 +17,6 @@ export default createComponent({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
||||||
model: {
|
|
||||||
event: 'update:value',
|
|
||||||
},
|
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
title: String,
|
title: String,
|
||||||
@ -31,7 +28,7 @@ export default createComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'default',
|
default: 'default',
|
||||||
},
|
},
|
||||||
value: {
|
modelValue: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
@ -61,6 +58,16 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: [
|
||||||
|
'show',
|
||||||
|
'hide',
|
||||||
|
'blur',
|
||||||
|
'input',
|
||||||
|
'close',
|
||||||
|
'delete',
|
||||||
|
'update:modelValue',
|
||||||
|
],
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
show(val) {
|
show(val) {
|
||||||
if (!this.transition) {
|
if (!this.transition) {
|
||||||
@ -141,22 +148,22 @@ export default createComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { value } = this;
|
const value = this.modelValue;
|
||||||
|
|
||||||
if (type === 'delete') {
|
if (type === 'delete') {
|
||||||
this.$emit('delete');
|
this.$emit('delete');
|
||||||
this.$emit('update:value', value.slice(0, value.length - 1));
|
this.$emit('update:modelValue', value.slice(0, value.length - 1));
|
||||||
} else if (type === 'close') {
|
} else if (type === 'close') {
|
||||||
this.onClose();
|
this.onClose();
|
||||||
} else if (value.length < this.maxlength) {
|
} else if (value.length < this.maxlength) {
|
||||||
this.$emit('input', text);
|
this.$emit('input', text);
|
||||||
this.$emit('update:value', value + text);
|
this.$emit('update:modelValue', value + text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
genTitle() {
|
genTitle() {
|
||||||
const { title, theme, closeButtonText } = this;
|
const { title, theme, closeButtonText } = this;
|
||||||
const titleLeft = this.slots('title-left');
|
const titleLeft = this.$slots['title-left'];
|
||||||
const showClose = closeButtonText && theme === 'default';
|
const showClose = closeButtonText && theme === 'default';
|
||||||
const showTitle = title || showClose || titleLeft;
|
const showTitle = title || showClose || titleLeft;
|
||||||
|
|
||||||
@ -178,19 +185,28 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
genKeys() {
|
genKeys() {
|
||||||
return this.keys.map((key) => (
|
return this.keys.map((key) => {
|
||||||
<Key
|
const slots = {};
|
||||||
key={key.text}
|
|
||||||
text={key.text}
|
if (key.type === 'delete') {
|
||||||
type={key.type}
|
slots.default = this.$slots.delete;
|
||||||
wider={key.wider}
|
}
|
||||||
color={key.color}
|
if (key.type === 'extra') {
|
||||||
onPress={this.onPress}
|
slots.default = this.$slots['extra-key'];
|
||||||
>
|
}
|
||||||
{key.type === 'delete' && this.slots('delete')}
|
|
||||||
{key.type === 'extra' && this.slots('extra-key')}
|
return (
|
||||||
</Key>
|
<Key
|
||||||
));
|
v-slots={slots}
|
||||||
|
key={key.text}
|
||||||
|
text={key.text}
|
||||||
|
type={key.type}
|
||||||
|
wider={key.wider}
|
||||||
|
color={key.color}
|
||||||
|
onPress={this.onPress}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
genSidebar() {
|
genSidebar() {
|
||||||
@ -199,13 +215,12 @@ export default createComponent({
|
|||||||
<div class={bem('sidebar')}>
|
<div class={bem('sidebar')}>
|
||||||
{this.showDeleteKey && (
|
{this.showDeleteKey && (
|
||||||
<Key
|
<Key
|
||||||
|
v-slots={{ delete: this.$slots.delete }}
|
||||||
large
|
large
|
||||||
text={this.deleteButtonText}
|
text={this.deleteButtonText}
|
||||||
type="delete"
|
type="delete"
|
||||||
onPress={this.onPress}
|
onPress={this.onPress}
|
||||||
>
|
/>
|
||||||
{this.slots('delete')}
|
|
||||||
</Key>
|
|
||||||
)}
|
)}
|
||||||
<Key
|
<Key
|
||||||
large
|
large
|
||||||
@ -225,7 +240,7 @@ export default createComponent({
|
|||||||
const Title = this.genTitle();
|
const Title = this.genTitle();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<transition name={this.transition ? 'van-slide-up' : ''}>
|
<Transition name={this.transition ? 'van-slide-up' : ''}>
|
||||||
<div
|
<div
|
||||||
vShow={this.show}
|
vShow={this.show}
|
||||||
style={{ zIndex: this.zIndex }}
|
style={{ zIndex: this.zIndex }}
|
||||||
@ -240,7 +255,7 @@ export default createComponent({
|
|||||||
{this.genSidebar()}
|
{this.genSidebar()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</Transition>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -135,10 +135,10 @@ module.exports = {
|
|||||||
// path: 'form',
|
// path: 'form',
|
||||||
// title: 'Form 表单',
|
// title: 'Form 表单',
|
||||||
// },
|
// },
|
||||||
// {
|
{
|
||||||
// path: 'number-keyboard',
|
path: 'number-keyboard',
|
||||||
// title: 'NumberKeyboard 数字键盘',
|
title: 'NumberKeyboard 数字键盘',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'password-input',
|
// path: 'password-input',
|
||||||
// title: 'PasswordInput 密码输入框',
|
// title: 'PasswordInput 密码输入框',
|
||||||
@ -469,10 +469,10 @@ module.exports = {
|
|||||||
// path: 'form',
|
// path: 'form',
|
||||||
// title: 'Form',
|
// title: 'Form',
|
||||||
// },
|
// },
|
||||||
// {
|
{
|
||||||
// path: 'number-keyboard',
|
path: 'number-keyboard',
|
||||||
// title: 'NumberKeyboard',
|
title: 'NumberKeyboard',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'password-input',
|
// path: 'password-input',
|
||||||
// title: 'PasswordInput',
|
// title: 'PasswordInput',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user