Добавлен сервис уведомлений
This commit is contained in:
30
resources/js/Composables/useNotification.js
Normal file
30
resources/js/Composables/useNotification.js
Normal file
@@ -0,0 +1,30 @@
|
||||
export function useNotification() {
|
||||
const showNotification = (options) => {
|
||||
if (window.$notification) {
|
||||
return window.$notification.create(options)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const success = () => {
|
||||
|
||||
}
|
||||
|
||||
const errorApi = (content = '', options = {}) => {
|
||||
return showNotification(
|
||||
{
|
||||
title: 'Произошла ошибка',
|
||||
description: 'При обращении к API серверу',
|
||||
content,
|
||||
meta: options.meta || new Date().toLocaleDateString(),
|
||||
...options,
|
||||
type: 'error'
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
errorApi
|
||||
}
|
||||
}
|
||||
22
resources/js/Plugins/naiveUI.js
Normal file
22
resources/js/Plugins/naiveUI.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import {createDiscreteApi, darkTheme, lightTheme} from "naive-ui";
|
||||
|
||||
export function setupNaiveDiscreteApi(app) {
|
||||
const {message, notification, dialog, loadingBar} = createDiscreteApi(
|
||||
['message', 'dialog', 'notification', 'loadingBar'],
|
||||
{
|
||||
configProviderProps: {
|
||||
theme: window.matchMedia('(prefers-color-scheme: dark)').matches ? darkTheme : lightTheme
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
window.$notification = notification
|
||||
window.$message = message
|
||||
window.$dialog = dialog
|
||||
window.$loadingBar = loadingBar
|
||||
|
||||
app.config.globalProperties.$notification = notification
|
||||
app.config.globalProperties.$message = message
|
||||
app.config.globalProperties.$dialog = dialog
|
||||
app.config.globalProperties.$loadingBar = loadingBar
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import '../css/app.css';
|
||||
import { createApp, h } from 'vue'
|
||||
import { createInertiaApp } from '@inertiajs/vue3'
|
||||
import {createPinia} from "pinia";
|
||||
import {setupNaiveDiscreteApi} from "./Plugins/naiveUI.js";
|
||||
|
||||
createInertiaApp({
|
||||
id: 'kartoteka',
|
||||
@@ -11,11 +12,17 @@ createInertiaApp({
|
||||
return pages[`./Pages/${name}.vue`]
|
||||
},
|
||||
setup({el, App, props, plugin}) {
|
||||
const vueApp = createApp({render: () => h(App, props)})
|
||||
|
||||
const pinia = createPinia()
|
||||
|
||||
createApp({ render: () => h(App, props) })
|
||||
.use(plugin)
|
||||
.use(pinia)
|
||||
.mount(el)
|
||||
vueApp.use(plugin)
|
||||
vueApp.use(pinia)
|
||||
|
||||
setupNaiveDiscreteApi(vueApp)
|
||||
|
||||
vueApp.mount(el)
|
||||
},
|
||||
}).then(r => {
|
||||
console.log('Инициализация прошла успешно')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user