mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-06 03:57:54 +08:00
feat(projects): 添加全局消息提示msg、dialog、loadingbar、notification
This commit is contained in:
parent
54bf56a0c3
commit
eb328c3f46
21
src/App.vue
21
src/App.vue
@ -2,6 +2,7 @@
|
|||||||
// import { darkTheme } from 'naive-ui';
|
// import { darkTheme } from 'naive-ui';
|
||||||
import { zhCN, dateZhCN, GlobalThemeOverrides } from 'naive-ui';
|
import { zhCN, dateZhCN, GlobalThemeOverrides } from 'naive-ui';
|
||||||
import json from './theme.json';
|
import json from './theme.json';
|
||||||
|
// import NativeProvider from '@/components/NativeProvider.vue';
|
||||||
|
|
||||||
const locale = zhCN;
|
const locale = zhCN;
|
||||||
const dateLocale = dateZhCN;
|
const dateLocale = dateZhCN;
|
||||||
@ -10,17 +11,15 @@ const themeOverrides: GlobalThemeOverrides = {} || json;
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-loading-bar-provider>
|
<n-config-provider
|
||||||
<n-config-provider
|
class="wh-full"
|
||||||
class="wh-full"
|
:theme="null"
|
||||||
:theme="null"
|
:locale="locale"
|
||||||
:locale="locale"
|
:date-locale="dateLocale"
|
||||||
:date-locale="dateLocale"
|
:theme-overrides="themeOverrides"
|
||||||
:theme-overrides="themeOverrides"
|
>
|
||||||
>
|
<naive-provider><router-view /></naive-provider>
|
||||||
<router-view />
|
</n-config-provider>
|
||||||
</n-config-provider>
|
|
||||||
</n-loading-bar-provider>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
37
src/components/NaiveProvider.vue
Normal file
37
src/components/NaiveProvider.vue
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<template>
|
||||||
|
<n-loading-bar-provider>
|
||||||
|
<n-dialog-provider>
|
||||||
|
<n-notification-provider>
|
||||||
|
<n-message-provider>
|
||||||
|
<slot></slot>
|
||||||
|
<naive-provider-content />
|
||||||
|
</n-message-provider>
|
||||||
|
</n-notification-provider>
|
||||||
|
</n-dialog-provider>
|
||||||
|
</n-loading-bar-provider>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useLoadingBar, useDialog, useMessage, useNotification } from 'naive-ui';
|
||||||
|
import { defineComponent, h } from 'vue';
|
||||||
|
|
||||||
|
// 挂载naive组件的方法至window, 以便在路由钩子函数和请求函数里面调用
|
||||||
|
function registerNaiveTools() {
|
||||||
|
window.$loadingBar = useLoadingBar();
|
||||||
|
window.$dialog = useDialog();
|
||||||
|
window.$message = useMessage();
|
||||||
|
window.$notification = useNotification();
|
||||||
|
}
|
||||||
|
|
||||||
|
const NaiveProviderContent = defineComponent({
|
||||||
|
name: 'NaiveProviderContent',
|
||||||
|
setup() {
|
||||||
|
registerNaiveTools();
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
return h('div');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
@ -1,3 +1,2 @@
|
|||||||
export * from './user';
|
|
||||||
export * from './app';
|
export * from './app';
|
||||||
export * from './auth';
|
export * from './auth';
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import { defineStore } from 'pinia';
|
|
||||||
|
|
||||||
// useStore 可以是 useUser、useCart 之类的任何东西
|
|
||||||
// 第一个参数是应用程序中 store 的唯一 id
|
|
||||||
export const useStore = defineStore('user-store', {
|
|
||||||
// other options...
|
|
||||||
state: () => {
|
|
||||||
return {
|
|
||||||
name: '张三',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
6
src/types/global.d.ts
vendored
Normal file
6
src/types/global.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
interface Window {
|
||||||
|
$loadingBar?: import('naive-ui').LoadingBarApiInjection;
|
||||||
|
$dialog?: import('naive-ui').DialogApiInjection;
|
||||||
|
$message?: import('naive-ui').MessageApiInjection;
|
||||||
|
$notification?: import('naive-ui').NotificationApiInjection;
|
||||||
|
}
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useStore } from '@/store';
|
import { useAuthStore } from '@/store';
|
||||||
|
|
||||||
const userStore = useStore();
|
const userStore = useAuthStore();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div text-center c-red>I prove that you have made the jump test3.</div>
|
<div text-center c-red>I prove that you have made the jump test3.</div>
|
||||||
<n-button strong secondary type="success" @click="loadingBar.start()">loading-bar</n-button>
|
<n-button strong secondary type="success" @click="testMsg">testMsg</n-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useLoadingBar } from 'naive-ui';
|
const testMsg = () => {
|
||||||
const loadingBar = useLoadingBar();
|
window.$message.error('Once upon a time you dressed so fine');
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user