Files
kartoteka/resources/js/Composables/useNotification.js
2025-12-29 17:08:26 +09:00

44 lines
1.1 KiB
JavaScript

import {h} from "vue";
import {NCode, NLog} from "naive-ui"
export function useNotification() {
const showNotification = (options) => {
if (window.$notification) {
return window.$notification.create(options)
}
return null
}
const success = () => {
}
const errorApi = (data, content = null, options = {}) => {
return showNotification(
{
title: 'Произошла ошибка',
description: data
? `Код: ${data.code}\nURL: ${data.response.config.url}\nМетод: ${data.response.config.method.toUpperCase()}`
: null,
content: () => {
return content ? content : h(
NLog,
{
rows: 4,
log: data.response.config.data,
}
)
},
meta: options.meta || new Date().toLocaleDateString(),
...options,
type: 'error'
}
)
}
return {
errorApi
}
}