fix frontend
This commit is contained in:
43
frontend/src/composables/useNotification.ts
Normal file
43
frontend/src/composables/useNotification.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { ref, readonly } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
type NotificationType = 'success' | 'error'
|
||||
|
||||
interface Notification {
|
||||
show: boolean
|
||||
type: NotificationType
|
||||
message: string
|
||||
}
|
||||
|
||||
const notification = ref<Notification>({
|
||||
show: false,
|
||||
type: 'success',
|
||||
message: ''
|
||||
})
|
||||
|
||||
let timeoutId: number | null = null
|
||||
|
||||
export function useNotification() {
|
||||
const { t } = useI18n()
|
||||
|
||||
const showNotification = (messageKey: string, type: NotificationType = 'success', params?: Record<string, any>) => {
|
||||
const message = params ? t(messageKey, params) : t(messageKey)
|
||||
|
||||
// Очищаем предыдущий таймер, чтобы уведомление не закрылось раньше времени
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId)
|
||||
timeoutId = null
|
||||
}
|
||||
|
||||
notification.value = { show: true, type, message }
|
||||
timeoutId = window.setTimeout(() => {
|
||||
notification.value.show = false
|
||||
timeoutId = null
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
return {
|
||||
notification: readonly(notification),
|
||||
showNotification
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user