From 0f246f7e9ef91ea22d4b19ecbf5c655c9a46b6b2 Mon Sep 17 00:00:00 2001 From: vince Date: Wed, 10 Jul 2024 22:44:48 +0800 Subject: [PATCH] feat(project): support app custom loading template --- ...loading-antd.html => default-loading-antd.html} | 2 +- .../{loading.html => default-loading.html} | 4 ++-- .../src/plugins/inject-app-loading/index.ts | 14 ++++++++++---- .../@core/shared/cache/src/storage-manager.test.ts | 4 ++-- .../universal-ui/src/authentication/login.vue | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-) rename internal/vite-config/src/plugins/inject-app-loading/{loading-antd.html => default-loading-antd.html} (97%) rename internal/vite-config/src/plugins/inject-app-loading/{loading.html => default-loading.html} (94%) diff --git a/internal/vite-config/src/plugins/inject-app-loading/loading-antd.html b/internal/vite-config/src/plugins/inject-app-loading/default-loading-antd.html similarity index 97% rename from internal/vite-config/src/plugins/inject-app-loading/loading-antd.html rename to internal/vite-config/src/plugins/inject-app-loading/default-loading-antd.html index c770e313..2b8f645d 100644 --- a/internal/vite-config/src/plugins/inject-app-loading/loading-antd.html +++ b/internal/vite-config/src/plugins/inject-app-loading/default-loading-antd.html @@ -65,7 +65,7 @@ display: block; width: 20px; height: 20px; - background-color: #0065cc; + background-color: hsl(var(--primary, 210 100% 50%)); border-radius: 100%; opacity: 0.3; transform: scale(0.75); diff --git a/internal/vite-config/src/plugins/inject-app-loading/loading.html b/internal/vite-config/src/plugins/inject-app-loading/default-loading.html similarity index 94% rename from internal/vite-config/src/plugins/inject-app-loading/loading.html rename to internal/vite-config/src/plugins/inject-app-loading/default-loading.html index e93b24f6..9e27df78 100644 --- a/internal/vite-config/src/plugins/inject-app-loading/loading.html +++ b/internal/vite-config/src/plugins/inject-app-loading/default-loading.html @@ -56,7 +56,7 @@ width: 48px; height: 5px; content: ''; - background: hsl(var(--primary) / 50%); + background: hsl(var(--primary, 210 100% 50%) / 50%); border-radius: 50%; animation: shadow-ani 0.5s linear infinite; } @@ -68,7 +68,7 @@ width: 100%; height: 100%; content: ''; - background: hsl(var(--primary)); + background: hsl(var(--primary, 210 100% 50%)); border-radius: 4px; animation: jump-ani 0.5s linear infinite; } diff --git a/internal/vite-config/src/plugins/inject-app-loading/index.ts b/internal/vite-config/src/plugins/inject-app-loading/index.ts index 731caeac..8f881486 100644 --- a/internal/vite-config/src/plugins/inject-app-loading/index.ts +++ b/internal/vite-config/src/plugins/inject-app-loading/index.ts @@ -12,8 +12,9 @@ import { type PluginOption } from 'vite'; async function viteInjectAppLoadingPlugin( isBuild: boolean, env: Record = {}, + loadingTemplate = 'loading.html', ): Promise { - const loadingHtml = await getLoadingRawByHtmlTemplate(); + const loadingHtml = await getLoadingRawByHtmlTemplate(loadingTemplate); const envRaw = isBuild ? 'prod' : 'dev'; const cacheName = `'${env.VITE_APP_NAMESPACE}-${envRaw}-preferences-theme'`; @@ -47,10 +48,15 @@ async function viteInjectAppLoadingPlugin( /** * 用于获取loading的html模板 */ -async function getLoadingRawByHtmlTemplate() { +async function getLoadingRawByHtmlTemplate(loadingTemplate: string) { const __dirname = fileURLToPath(new URL('.', import.meta.url)); - const loadingPath = join(__dirname, './loading.html'); - if (!fs.existsSync(loadingPath)) { + const defaultLoadingPath = join(__dirname, './default-loading.html'); + // 支持在app内自定义loading模板,模版参考default-loading.html即可 + const appLoadingPath = join(process.cwd(), loadingTemplate); + let loadingPath = defaultLoadingPath; + + if (fs.existsSync(appLoadingPath)) { + loadingPath = appLoadingPath; return; } diff --git a/packages/@core/shared/cache/src/storage-manager.test.ts b/packages/@core/shared/cache/src/storage-manager.test.ts index b56d49e0..915af72f 100644 --- a/packages/@core/shared/cache/src/storage-manager.test.ts +++ b/packages/@core/shared/cache/src/storage-manager.test.ts @@ -3,12 +3,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { StorageManager } from './storage-manager'; describe('storageManager', () => { - let storageManager: StorageManager<{ age: number; name: string }>; + let storageManager: StorageManager; beforeEach(() => { vi.useFakeTimers(); localStorage.clear(); - storageManager = new StorageManager<{ age: number; name: string }>({ + storageManager = new StorageManager({ prefix: 'test_', }); }); diff --git a/packages/business/universal-ui/src/authentication/login.vue b/packages/business/universal-ui/src/authentication/login.vue index 42eaffc1..61d04f35 100644 --- a/packages/business/universal-ui/src/authentication/login.vue +++ b/packages/business/universal-ui/src/authentication/login.vue @@ -102,7 +102,7 @@ const emit = defineEmits<{ const router = useRouter(); -const REMEMBER_ME_KEY = 'REMEMBER_ME_USERNAME'; +const REMEMBER_ME_KEY = `REMEMBER_ME_USERNAME_${location.hostname}`; const localUsername = localStorage.getItem(REMEMBER_ME_KEY) || '';