From f56bef40d8cf8525e36c73993abafc14f2f8d548 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 5 Jan 2025 23:54:35 +0800 Subject: [PATCH] code refactor --- src/components/common/PinCodeInput.vue | 10 +++++----- src/components/desktop/ConfirmDialog.vue | 24 ++++++++++++------------ src/components/desktop/SnackBar.vue | 8 +++++++- src/components/mobile/MapSheet.vue | 6 ++++-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/components/common/PinCodeInput.vue b/src/components/common/PinCodeInput.vue index 8c70591d..d3240512 100644 --- a/src/components/common/PinCodeInput.vue +++ b/src/components/common/PinCodeInput.vue @@ -24,7 +24,7 @@ import { type Ref, ref, computed, watch, useTemplateRef } from 'vue'; interface PinCode { value: string; inputType: string; - inputTimer: number | null; + inputTimer: unknown | null; focused: boolean; } @@ -129,7 +129,7 @@ function setInputType(index: number): void { } function setFocus(index: number): void { - if (pinCodeInputs.value[index]) { + if (pinCodeInputs.value && pinCodeInputs.value[index]) { pinCodeInputs.value[index].focus(); pinCodeInputs.value[index].select(); } @@ -239,13 +239,13 @@ function onPaste(index: number, event: ClipboardEvent): void { event.preventDefault(); } -function onInput(index: number, event: InputEvent): void { - if (!event.target.value) { +function onInput(index: number, event: Event | { target: { value: string }, preventDefault: () => void }): void { + if (!event.target || !(event.target as { value: string }).value) { event.preventDefault(); return; } - autoFillText(index, event.target.value); + autoFillText(index, (event.target as { value: string }).value); event.preventDefault(); } diff --git a/src/components/desktop/ConfirmDialog.vue b/src/components/desktop/ConfirmDialog.vue index 319bc54c..b287fbf1 100644 --- a/src/components/desktop/ConfirmDialog.vue +++ b/src/components/desktop/ConfirmDialog.vue @@ -38,23 +38,23 @@ const titleContent: Ref = ref(props.title || tt('global.app.title')); const textContent: Ref = ref(props.text || ''); const finalColor: Ref = ref(props.color || 'primary'); -let resolveFunc: (value: T | PromiseLike) => void = null; -let rejectFunc: (reason?: unknown) => void = null; +let resolveFunc: ((value?: unknown) => void) | null = null; +let rejectFunc: ((reason?: unknown) => void) | null = null; -function open(title: string, text: string, options: Record) { +function open(titleOrText: string, textOrOptions: string | Record, options: Record) { showState.value = true; - if (isString(text)) { - titleContent.value = tt(title, options); - textContent.value = tt(text, options); - } else { - options = text; + if (isString(textOrOptions)) { // second parameter is text + titleContent.value = tt(titleOrText, options); + textContent.value = tt(textOrOptions, options); + } else { // second parameter is options + const actualOptions = textOrOptions as Record; titleContent.value = tt('global.app.title'); - textContent.value = tt(title, options); + textContent.value = tt(titleOrText, actualOptions); } - if (options && options.color) { - finalColor.value = options.color || 'primary'; + if (options && isString(options.color)) { + finalColor.value = (options.color as string) || 'primary'; } return new Promise((resolve, reject) => { @@ -81,7 +81,7 @@ function cancel(): void { emit('update:show', false); } -watch(() => showState, (newValue) => { +watch(showState, newValue => { emit('update:show', newValue); }); diff --git a/src/components/desktop/SnackBar.vue b/src/components/desktop/SnackBar.vue index 1da95b0f..385c0373 100644 --- a/src/components/desktop/SnackBar.vue +++ b/src/components/desktop/SnackBar.vue @@ -11,6 +11,7 @@