mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 07:27:33 +08:00
code refactor
This commit is contained in:
@@ -38,23 +38,23 @@ const titleContent: Ref<string> = ref(props.title || tt('global.app.title'));
|
||||
const textContent: Ref<string> = ref(props.text || '');
|
||||
const finalColor: Ref<string> = ref(props.color || 'primary');
|
||||
|
||||
let resolveFunc: (value: T | PromiseLike<T>) => 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<string, unknown>) {
|
||||
function open(titleOrText: string, textOrOptions: string | Record<string, unknown>, options: Record<string, unknown>) {
|
||||
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<string, unknown>;
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<script setup lang="ts">
|
||||
import { type Ref, ref, watch } from 'vue';
|
||||
|
||||
import { isObject } from '@/lib/common.ts';
|
||||
import { useI18n } from '@/lib/i18n.js';
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -29,7 +30,12 @@ function showMessage(message: string, options: Record<string, unknown>): void {
|
||||
|
||||
function showError(error: string | { message: string }): void {
|
||||
showState.value = true;
|
||||
messageContent.value = te(error.message || error);
|
||||
|
||||
if (isObject(error) && (error as { message: string }).message) {
|
||||
messageContent.value = te((error as { message: string }).message);
|
||||
} else {
|
||||
messageContent.value = te(error);
|
||||
}
|
||||
}
|
||||
|
||||
watch(showState, (newValue) => {
|
||||
|
||||
Reference in New Issue
Block a user