mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
pin code input supports pressing enter to confirm and pressing tab to switch to the next component
This commit is contained in:
@@ -33,6 +33,7 @@ const props = defineProps<{
|
|||||||
length: number;
|
length: number;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
autofocus?: boolean;
|
autofocus?: boolean;
|
||||||
|
autoConfirm?: boolean;
|
||||||
secure?: boolean;
|
secure?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
@@ -151,6 +152,14 @@ function onKeydown(index: number, event: KeyboardEvent): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index <= 0 && (event.shiftKey && event.key === 'Tab')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index >= props.length - 1 && (!event.shiftKey && event.key === 'Tab')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key === 'Enter' && finalPinCode.value.length === props.length) {
|
if (event.key === 'Enter' && finalPinCode.value.length === props.length) {
|
||||||
emit('pincode:confirm', finalPinCode.value);
|
emit('pincode:confirm', finalPinCode.value);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -204,7 +213,7 @@ function onKeydown(index: number, event: KeyboardEvent): void {
|
|||||||
setInputType(index);
|
setInputType(index);
|
||||||
setNextFocus(index);
|
setNextFocus(index);
|
||||||
|
|
||||||
if (finalPinCode.value.length === props.length) {
|
if (props.autoConfirm && finalPinCode.value.length === props.length) {
|
||||||
emit('pincode:confirm', finalPinCode.value);
|
emit('pincode:confirm', finalPinCode.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<p class="no-margin">{{ hint }}</p>
|
<p class="no-margin">{{ hint }}</p>
|
||||||
<f7-list class="no-margin">
|
<f7-list class="no-margin">
|
||||||
<f7-list-item class="list-item-pincode-input padding-vertical-half">
|
<f7-list-item class="list-item-pincode-input padding-vertical-half">
|
||||||
<pin-code-input :secure="true" :length="6" v-model="currentPinCode"/>
|
<pin-code-input :secure="true" :length="6" v-model="currentPinCode" @pincode:confirm="confirm"/>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
</f7-list>
|
</f7-list>
|
||||||
<f7-button large fill
|
<f7-button large fill
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<v-row>
|
<v-row>
|
||||||
<v-col cols="12">
|
<v-col cols="12">
|
||||||
<pin-code-input :disabled="verifyingByWebAuthn" :autofocus="true"
|
<pin-code-input :disabled="verifyingByWebAuthn" :autofocus="true"
|
||||||
:secure="true" :length="6"
|
:secure="true" :length="6" :auto-confirm="true"
|
||||||
v-model="pinCode" @pincode:confirm="unlockByPin" />
|
v-model="pinCode" @pincode:confirm="unlockByPin" />
|
||||||
</v-col>
|
</v-col>
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<v-row class="mb-3">
|
<v-row class="mb-3">
|
||||||
<v-col cols="12" md="12">
|
<v-col cols="12" md="12">
|
||||||
<div style="max-width: 428px">
|
<div style="max-width: 428px">
|
||||||
<pin-code-input :secure="true" :length="6" v-model="pinCode" />
|
<pin-code-input :secure="true" :length="6" v-model="pinCode" @pincode:confirm="confirm" />
|
||||||
</div>
|
</div>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -147,6 +147,13 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
confirm() {
|
||||||
|
if (this.isEnableApplicationLock) {
|
||||||
|
this.disable();
|
||||||
|
} else {
|
||||||
|
this.enable();
|
||||||
|
}
|
||||||
|
},
|
||||||
enable() {
|
enable() {
|
||||||
if (this.settingsStore.appSettings.applicationLock) {
|
if (this.settingsStore.appSettings.applicationLock) {
|
||||||
this.$refs.snackbar.showMessage('Application lock has been enabled');
|
this.$refs.snackbar.showMessage('Application lock has been enabled');
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
<f7-list-item class="list-item-pincode-input padding-horizontal margin-horizontal">
|
<f7-list-item class="list-item-pincode-input padding-horizontal margin-horizontal">
|
||||||
<pin-code-input :secure="true" :length="6" v-model="pinCode" @pincode:confirm="unlockByPin" />
|
<pin-code-input :secure="true" :length="6" :auto-confirm="true" v-model="pinCode" @pincode:confirm="unlockByPin" />
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
</f7-list>
|
</f7-list>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user