Добавлен сервис уведомлений
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,19 +3,26 @@ import '../css/app.css';
|
|||||||
import { createApp, h } from 'vue'
|
import { createApp, h } from 'vue'
|
||||||
import { createInertiaApp } from '@inertiajs/vue3'
|
import { createInertiaApp } from '@inertiajs/vue3'
|
||||||
import {createPinia} from "pinia";
|
import {createPinia} from "pinia";
|
||||||
|
import {setupNaiveDiscreteApi} from "./Plugins/naiveUI.js";
|
||||||
|
|
||||||
createInertiaApp({
|
createInertiaApp({
|
||||||
id: 'kartoteka',
|
id: 'kartoteka',
|
||||||
resolve: name => {
|
resolve: name => {
|
||||||
const pages = import.meta.glob('./Pages/**/*.vue', { eager: true })
|
const pages = import.meta.glob('./Pages/**/*.vue', {eager: true})
|
||||||
return pages[`./Pages/${name}.vue`]
|
return pages[`./Pages/${name}.vue`]
|
||||||
},
|
},
|
||||||
setup({ el, App, props, plugin }) {
|
setup({el, App, props, plugin}) {
|
||||||
|
const vueApp = createApp({render: () => h(App, props)})
|
||||||
|
|
||||||
const pinia = createPinia()
|
const pinia = createPinia()
|
||||||
|
|
||||||
createApp({ render: () => h(App, props) })
|
vueApp.use(plugin)
|
||||||
.use(plugin)
|
vueApp.use(pinia)
|
||||||
.use(pinia)
|
|
||||||
.mount(el)
|
setupNaiveDiscreteApi(vueApp)
|
||||||
|
|
||||||
|
vueApp.mount(el)
|
||||||
},
|
},
|
||||||
|
}).then(r => {
|
||||||
|
console.log('Инициализация прошла успешно')
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user