|
@@ -10,15 +10,18 @@ defineOptions({
|
|
inheritAttrs: false,
|
|
inheritAttrs: false,
|
|
});
|
|
});
|
|
|
|
|
|
-const props = withDefaults(defineProps<PinInputProps>(), {
|
|
|
|
- btnLoading: false,
|
|
|
|
- codeLength: 6,
|
|
|
|
- handleSendCode: async () => {},
|
|
|
|
- maxTime: 60,
|
|
|
|
-});
|
|
|
|
|
|
+const {
|
|
|
|
+ codeLength = 6,
|
|
|
|
+ createText = async () => {},
|
|
|
|
+ disabled = false,
|
|
|
|
+ handleSendCode = async () => {},
|
|
|
|
+ loading = false,
|
|
|
|
+ maxTime = 60,
|
|
|
|
+} = defineProps<PinInputProps>();
|
|
|
|
|
|
const emit = defineEmits<{
|
|
const emit = defineEmits<{
|
|
complete: [];
|
|
complete: [];
|
|
|
|
+ sendError: [error: any];
|
|
}>();
|
|
}>();
|
|
|
|
|
|
const timer = ref<ReturnType<typeof setTimeout>>();
|
|
const timer = ref<ReturnType<typeof setTimeout>>();
|
|
@@ -30,11 +33,11 @@ const countdown = ref(0);
|
|
|
|
|
|
const btnText = computed(() => {
|
|
const btnText = computed(() => {
|
|
const countdownValue = countdown.value;
|
|
const countdownValue = countdown.value;
|
|
- return props.createText?.(countdownValue);
|
|
|
|
|
|
+ return createText?.(countdownValue);
|
|
});
|
|
});
|
|
|
|
|
|
const btnLoading = computed(() => {
|
|
const btnLoading = computed(() => {
|
|
- return props.loading || countdown.value > 0;
|
|
|
|
|
|
+ return loading || countdown.value > 0;
|
|
});
|
|
});
|
|
|
|
|
|
watch(
|
|
watch(
|
|
@@ -50,10 +53,16 @@ function handleComplete(e: string[]) {
|
|
}
|
|
}
|
|
|
|
|
|
async function handleSend(e: Event) {
|
|
async function handleSend(e: Event) {
|
|
- e?.preventDefault();
|
|
|
|
- await props.handleSendCode();
|
|
|
|
- countdown.value = props.maxTime;
|
|
|
|
- startCountdown();
|
|
|
|
|
|
+ try {
|
|
|
|
+ e?.preventDefault();
|
|
|
|
+ await handleSendCode();
|
|
|
|
+ countdown.value = maxTime;
|
|
|
|
+ startCountdown();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('Failed to send code:', error);
|
|
|
|
+ // Consider emitting an error event or showing a notification
|
|
|
|
+ emit('sendError', error);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
function startCountdown() {
|
|
function startCountdown() {
|
|
@@ -77,6 +86,7 @@ const id = useId();
|
|
<PinInput
|
|
<PinInput
|
|
:id="id"
|
|
:id="id"
|
|
v-model="inputValue"
|
|
v-model="inputValue"
|
|
|
|
+ :disabled="disabled"
|
|
class="flex w-full justify-between"
|
|
class="flex w-full justify-between"
|
|
otp
|
|
otp
|
|
placeholder="○"
|
|
placeholder="○"
|
|
@@ -92,6 +102,7 @@ const id = useId();
|
|
/>
|
|
/>
|
|
</PinInputGroup>
|
|
</PinInputGroup>
|
|
<VbenButton
|
|
<VbenButton
|
|
|
|
+ :disabled="disabled"
|
|
:loading="btnLoading"
|
|
:loading="btnLoading"
|
|
class="flex-grow"
|
|
class="flex-grow"
|
|
size="lg"
|
|
size="lg"
|