feat: error handing: alert -> dialog
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import PostScheme from './post/PostScheme.vue';
|
import PostScheme from './post/PostScheme.vue';
|
||||||
import AuthorScheme from "./author/AuthorScheme.vue";
|
import AuthorScheme from "./author/AuthorScheme.vue";
|
||||||
import MultiSelect from './components/selects/MultiSelect.vue';
|
import { Dialog } from 'primevue';
|
||||||
|
import { useErrorStore } from './stores/error.store';
|
||||||
|
|
||||||
|
const errorStore = useErrorStore()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<Dialog v-model:visible="errorStore.show" maximizable class="w-[400px] h-[400px]">
|
||||||
|
<template #header>
|
||||||
|
Ошибка
|
||||||
|
</template>
|
||||||
|
<h1 class="text-red-500 text-2xl">{{ errorStore.message }}</h1>
|
||||||
|
</Dialog>
|
||||||
<main class="w-screen h-screen">
|
<main class="w-screen h-screen">
|
||||||
<AuthorScheme></AuthorScheme>
|
<AuthorScheme></AuthorScheme>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import { Config } from 'primevue'
|
|||||||
import Aura from '@primevue/themes/aura'
|
import Aura from '@primevue/themes/aura'
|
||||||
import 'primeicons/primeicons.css'
|
import 'primeicons/primeicons.css'
|
||||||
import { ru } from 'primelocale/js/ru.js'
|
import { ru } from 'primelocale/js/ru.js'
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
|
|
||||||
createApp(App).use(Config, {
|
createApp(App).use(createPinia()).use(Config, {
|
||||||
theme: {
|
theme: {
|
||||||
preset: Aura,
|
preset: Aura,
|
||||||
},
|
},
|
||||||
|
|||||||
23
frontend/src/stores/error.store.ts
Normal file
23
frontend/src/stores/error.store.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
|
export interface ErrorState {
|
||||||
|
show: boolean
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useErrorStore = defineStore("error", {
|
||||||
|
state: (): ErrorState => ({
|
||||||
|
show: false,
|
||||||
|
message: ""
|
||||||
|
}),
|
||||||
|
actions: {
|
||||||
|
summon(message: string) {
|
||||||
|
this.show = true
|
||||||
|
this.message = message
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.show = false
|
||||||
|
this.message = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -9,10 +9,13 @@ import { toDate, toTimestamp } from '../utils/date/converters.util';
|
|||||||
import MultiSelect from '../components/selects/MultiSelect.vue';
|
import MultiSelect from '../components/selects/MultiSelect.vue';
|
||||||
import { alertWindow } from '../utils/js/alert.utils';
|
import { alertWindow } from '../utils/js/alert.utils';
|
||||||
import type { Validate } from '../types/validate.type';
|
import type { Validate } from '../types/validate.type';
|
||||||
|
import { useErrorStore } from '../stores/error.store';
|
||||||
|
|
||||||
const showCreate = defineModel<boolean>('show')
|
const showCreate = defineModel<boolean>('show')
|
||||||
const createItem = defineModel<T>('item')
|
const createItem = defineModel<T>('item')
|
||||||
|
|
||||||
|
const errorStore = useErrorStore()
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
scheme: Scheme<T>,
|
scheme: Scheme<T>,
|
||||||
getDefaults: () => Partial<T>,
|
getDefaults: () => Partial<T>,
|
||||||
@@ -36,7 +39,7 @@ async function handleSave() {
|
|||||||
const mode = props.updateMode ? 'update' : 'create';
|
const mode = props.updateMode ? 'update' : 'create';
|
||||||
const result = props.validate(createItem.value as T, mode);
|
const result = props.validate(createItem.value as T, mode);
|
||||||
if (result.status === 'error') {
|
if (result.status === 'error') {
|
||||||
alertWindow(result.message);
|
errorStore.summon(result.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -50,7 +53,7 @@ async function handleSave() {
|
|||||||
await emits('onSave', createItem.value as T);
|
await emits('onSave', createItem.value as T);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alertWindow(e.message);
|
errorStore.summon(e.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
props.load()
|
props.load()
|
||||||
@@ -98,7 +101,7 @@ async function handleSave() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<Button severity="success" class="mt-5" @click="handleSave">Сохранить</Button>
|
<Button class="mt-5" @click="handleSave">Сохранить</Button>
|
||||||
</template>
|
</template>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user