Skip to content

Commit

Permalink
add login box input filter
Browse files Browse the repository at this point in the history
  • Loading branch information
as6325400 committed Aug 30, 2024
1 parent c835109 commit 1d2fb1c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/pages/login/loginarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
inputmode="numeric"
required
v-model="inputs[index]"
@keydown="focusPre($event, index)"
@input="focusNext($event, index)" />
</div>
<button
Expand All @@ -41,6 +42,11 @@ import router from "@router/index.ts";
const inputs = ref(Array(6).fill(""));
// 定義一個方法來自動聚焦到下一個輸入框
const focusNext = (event, index) => {
const value = event.target.value;
if (!/^\d$/.test(value)) {
inputs.value[index] = "";
return;
}
if (
event.target.value.length === 1 &&
index < inputs.value.length - 1
Expand All @@ -49,8 +55,16 @@ const focusNext = (event, index) => {
}
};
const focusPre = (event, index) => {
if (event.key === "Backspace" && index > 0 && inputs.value[index] === "") {
inputs.value[index - 1] = "";
event.target.previousElementSibling.focus();
}
};
const apiSite = `${env.VITE_BACKEND_DEVICE}/`;
async function handleSubmit() {
const code = inputs.value.join("");
const res = await axios.post(`${apiSite}login`, { otp: code });
Expand Down

0 comments on commit 1d2fb1c

Please sign in to comment.