From b131100be8eaf0e247812fc32009ae77feb6b184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=9E=E5=AE=9D=E5=B1=B1?= <1253070437@qq.com> Date: Fri, 19 Jul 2024 01:44:47 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=89=8D=E7=AB=AF=E5=88=B7=E6=96=B0=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snowy-admin-web/index.html | 11 +----- snowy-admin-web/src/layout/index.vue | 3 ++ snowy-admin-web/src/router/index.js | 9 +++++ snowy-admin-web/src/router/systemRouter.js | 10 +++-- snowy-admin-web/src/store/global.js | 9 ++--- snowy-admin-web/src/utils/loading.js | 38 +++++++++++++++++++ .../src/views/auth/login/login.vue | 6 ++- 7 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 snowy-admin-web/src/utils/loading.js diff --git a/snowy-admin-web/index.html b/snowy-admin-web/index.html index 36f92e32..9b3a7ffb 100644 --- a/snowy-admin-web/index.html +++ b/snowy-admin-web/index.html @@ -12,6 +12,7 @@ .app-loading__logo {margin-bottom: 30px;} .app-loading__logo img {width: 90px;vertical-align: bottom;} .app-loading__title {font-size: 24px;color: #333;margin-top: 30px;} + .h-full { height: 100% } @keyframes loader { 0% { transform: rotate(0deg); @@ -28,15 +29,7 @@ We're sorry but Snowy2.0 doesn't work properly without JavaScript enabled. Please enable it to continue. -
-
- -
-
Snowy
-
-
+
diff --git a/snowy-admin-web/src/layout/index.vue b/snowy-admin-web/src/layout/index.vue index efac5950..e21a389e 100644 --- a/snowy-admin-web/src/layout/index.vue +++ b/snowy-admin-web/src/layout/index.vue @@ -81,6 +81,7 @@ import ClassicalMenu from '@/layout/menu/classicalMenu.vue' import DoubleRowMenu from '@/layout/menu/doubleRowMenu.vue' import TopMenu from '@/layout/menu/topMenu.vue' + import { NextLoading } from '@/utils/loading' const store = globalStore() const kStore = keepAliveStore() @@ -216,6 +217,8 @@ } showThis() onMounted(() => { + // 取消loading + NextLoading.done() onLayoutResize() window.addEventListener('resize', onLayoutResize) window.addEventListener('resize', getNav) diff --git a/snowy-admin-web/src/router/index.js b/snowy-admin-web/src/router/index.js index f92a0019..1823808e 100644 --- a/snowy-admin-web/src/router/index.js +++ b/snowy-admin-web/src/router/index.js @@ -20,6 +20,7 @@ import tool from '@/utils/tool' import { cloneDeep } from 'lodash-es' const modules = import.meta.glob('/src/views/**/**.vue') import { globalStore, searchStore } from '@/store' +import { NextLoading } from '@/utils/loading' // 进度条配置 NProgress.configure({ showSpinner: false, speed: 500 }) @@ -72,6 +73,12 @@ router.beforeEach(async (to, from, next) => { } const token = tool.data.get('TOKEN') + + // 页面刷新,加载loading + if (from.path === '/' && to.path !== '/login' && !window.nextLoading && token) { + NextLoading.start() + } + if (to.path === '/login') { // 当用户输入了login路由,将其跳转首页即可 if (token) { @@ -129,10 +136,12 @@ router.beforeEach(async (to, from, next) => { router.afterEach((to, from) => { afterEach(to, from) NProgress.done() + window.nextLoading && NextLoading.done() }) router.onError((error) => { NProgress.done() + window.nextLoading && NextLoading.done() notification.error({ message: '路由错误', description: error.message diff --git a/snowy-admin-web/src/router/systemRouter.js b/snowy-admin-web/src/router/systemRouter.js index b4afe2e1..15caf94f 100644 --- a/snowy-admin-web/src/router/systemRouter.js +++ b/snowy-admin-web/src/router/systemRouter.js @@ -12,25 +12,29 @@ import config from '@/config' import tool from '@/utils/tool' import routerUtil from '@/utils/routerUtil' +import Layout from '@/layout/index.vue' +import Login from '@/views/auth/login/login.vue' +import Findpwd from '@/views/auth/findPwd/index.vue' + // 系统路由 const routes = [ { name: 'layout', path: '/', - component: () => import('@/layout/index.vue'), + component: Layout, redirect: tool.data.get('MENU') ? routerUtil.getIndexMenu(tool.data.get('MENU')).path : config.DASHBOARD_URL, children: [] }, { path: '/login', - component: () => import('@/views/auth/login/login.vue'), + component: Login, meta: { title: '登录' } }, { path: '/findpwd', - component: () => import('@/views/auth/findPwd/index.vue'), + component: Findpwd, meta: { title: '找回密码' } diff --git a/snowy-admin-web/src/store/global.js b/snowy-admin-web/src/store/global.js index c23a2763..7337fcdc 100644 --- a/snowy-admin-web/src/store/global.js +++ b/snowy-admin-web/src/store/global.js @@ -77,17 +77,14 @@ export const globalStore = defineStore('global', () => { } const setTheme = (key) => { theme.value = key - const closeMessage = message.loading(`加载中...`) - changeColor(themeColor.value, key).then(closeMessage) + changeColor(themeColor.value, key).then() } const setThemeColor = (key) => { themeColor.value = key - const closeMessage = message.loading(`加载中...`) - changeColor(key, theme.value).then(closeMessage) + changeColor(key, theme.value).then() } const initTheme = () => { - const closeMessage = message.loading(`加载中...`) - changeColor(themeColor.value, theme.value).then(closeMessage) + changeColor(themeColor.value, theme.value).then() } const toggleConfig = (key) => { switch (key) { diff --git a/snowy-admin-web/src/utils/loading.js b/snowy-admin-web/src/utils/loading.js new file mode 100644 index 00000000..35ce380f --- /dev/null +++ b/snowy-admin-web/src/utils/loading.js @@ -0,0 +1,38 @@ +import { nextTick } from 'vue' + +/** + * 页面全局 Loading + * @method start 创建 loading + * @method done 移除 loading + */ +export const NextLoading = { + // 创建 loading + start: () => { + const el = document.querySelector('.admin-ui') + if (el) return + const bodys = document.body + const div = document.createElement('div') + div.setAttribute('class', 'admin-ui') + const htmls = ` +
+ +
+
Snowy
+
` + div.innerHTML = htmls + bodys.insertBefore(div, bodys.childNodes[0]) + window.nextLoading = true + }, + // 移除 loading + done: (time = 0) => { + nextTick(() => { + setTimeout(() => { + window.nextLoading = false + const el = document.querySelector('.admin-ui') + el?.parentNode?.removeChild(el) + }, time) + }) + } +} diff --git a/snowy-admin-web/src/views/auth/login/login.vue b/snowy-admin-web/src/views/auth/login/login.vue index 8ed37111..6340bd6f 100644 --- a/snowy-admin-web/src/views/auth/login/login.vue +++ b/snowy-admin-web/src/views/auth/login/login.vue @@ -99,7 +99,7 @@