From 9057d3e8ad09f5cb302e41d81f4cf2b9986485cb Mon Sep 17 00:00:00 2001 From: brusnitsyn Date: Fri, 19 Dec 2025 09:19:41 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=20=D1=83=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/Composables/useNotification.js | 30 +++++++++++++++++++++ resources/js/Plugins/naiveUI.js | 22 +++++++++++++++ resources/js/app.js | 19 ++++++++----- 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 resources/js/Composables/useNotification.js create mode 100644 resources/js/Plugins/naiveUI.js diff --git a/resources/js/Composables/useNotification.js b/resources/js/Composables/useNotification.js new file mode 100644 index 0000000..51a27c4 --- /dev/null +++ b/resources/js/Composables/useNotification.js @@ -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 + } +} diff --git a/resources/js/Plugins/naiveUI.js b/resources/js/Plugins/naiveUI.js new file mode 100644 index 0000000..b580b2a --- /dev/null +++ b/resources/js/Plugins/naiveUI.js @@ -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 +} diff --git a/resources/js/app.js b/resources/js/app.js index 1c5dc74..d09c8d4 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -3,19 +3,26 @@ 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', 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`] }, - setup({ el, App, props, plugin }) { + 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('Инициализация прошла успешно') })