From 840dc080a0f6434c7479b2201bb2893ae58159cc Mon Sep 17 00:00:00 2001 From: Megghy Date: Tue, 26 Dec 2023 23:04:03 +0800 Subject: [PATCH] add loadingbar --- package.json | 1 + src/App.vue | 40 +++---- src/components/TempComponent.vue | 18 ++++ src/main.ts | 10 +- src/router/index.ts | 9 ++ src/store/useProviderStore.ts | 13 +++ src/views/AboutView.vue | 9 +- src/views/ManageLayout.vue | 156 ++++++++++++++-------------- src/views/manage/DashboardView.vue | 2 +- src/views/open_live/ReadDanmaku.vue | 6 +- vite.config.mts | 16 +-- yarn.lock | 22 +++- 12 files changed, 188 insertions(+), 114 deletions(-) create mode 100644 src/components/TempComponent.vue create mode 100644 src/store/useProviderStore.ts diff --git a/package.json b/package.json index 5a948f5..f384e86 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "html2canvas": "^1.4.1", "linqts": "^1.15.0", "mitt": "^3.0.1", + "pinia": "^2.1.7", "prettier": "^3.1.1", "qrcode.vue": "^3.4.1", "queue-typescript": "^1.0.1", diff --git a/src/App.vue b/src/App.vue index 6403fe9..df189a0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,36 +2,40 @@ - -
- - - - - - - -
- -
+ + + + + + + + + + + + + +
+ + diff --git a/src/main.ts b/src/main.ts index 93df9da..934870f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,13 +2,17 @@ import { QueryGetAPI } from '@/api/query' import { BASE_API, apiFail } from '@/data/constants' import EasySpeech from 'easy-speech' import { NText, createDiscreteApi } from 'naive-ui' +import { createPinia } from 'pinia' import { createApp, h } from 'vue' import App from './App.vue' import { GetSelfAccount, UpdateAccountLoop } from './api/account' import { GetNotifactions } from './data/notifactions' import router from './router' -createApp(App).use(router).mount('#app') +const pinia = createPinia() + +const app = createApp(App) +app.use(router).use(pinia).mount('#app') let currentVersion: string const { notification } = createDiscreteApi(['notification']) @@ -20,6 +24,9 @@ QueryGetAPI(BASE_API() + 'vtsuru/version') localStorage.setItem('Version', currentVersion) if (currentVersion && savedVersion && savedVersion !== currentVersion) { + setTimeout(() => { + location.reload() + }, 1000) //alert('发现新的版本更新, 请按 Ctrl+F5 强制刷新页面') notification.info({ title: '发现新的版本更新', @@ -27,7 +34,6 @@ QueryGetAPI(BASE_API() + 'vtsuru/version') duration: 5000, meta: () => h(NText, { depth: 3 }, () => currentVersion), }) - location.reload() } } }) diff --git a/src/router/index.ts b/src/router/index.ts index 398a8ab..6b7ee05 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,3 +1,4 @@ +import { useProviderStore } from '@/store/useProviderStore' import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router' import IndexView from '../views/IndexView.vue' @@ -355,5 +356,13 @@ const router = createRouter({ history: createWebHistory(process.env.BASE_URL), routes, }) +router.beforeEach((to, from, next) => { + useProviderStore().loadingBar?.start() + next() +}) +router.afterEach((to, from) => { + const loadingBar = useProviderStore().loadingBar + loadingBar?.finish() +}) export default router diff --git a/src/store/useProviderStore.ts b/src/store/useProviderStore.ts new file mode 100644 index 0000000..a68c1af --- /dev/null +++ b/src/store/useProviderStore.ts @@ -0,0 +1,13 @@ +import { defineStore } from 'pinia' +import { LoadingBarApi } from 'naive-ui' +import { ref } from 'vue' + +export const useProviderStore = defineStore('provider', () => { + const loadingBar = ref() + + function setLoadingBar(b: LoadingBarApi) { + loadingBar.value = b + } + + return { loadingBar, setLoadingBar } +}) \ No newline at end of file diff --git a/src/views/AboutView.vue b/src/views/AboutView.vue index 45a8801..85b3688 100644 --- a/src/views/AboutView.vue +++ b/src/views/AboutView.vue @@ -26,15 +26,12 @@ import { NButton, NCard, NDivider, NLayoutContent, NSpace, NText, NTimeline, NTi admin@vtsuru.live