Browse Source

feat(project): support app custom loading template

vince 8 months ago
parent
commit
0f246f7e9e

+ 1 - 1
internal/vite-config/src/plugins/inject-app-loading/loading-antd.html → 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);

+ 2 - 2
internal/vite-config/src/plugins/inject-app-loading/loading.html → 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;
   }

+ 10 - 4
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<string, any> = {},
+  loadingTemplate = 'loading.html',
 ): Promise<PluginOption | undefined> {
-  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;
   }
 

+ 2 - 2
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_',
     });
   });

+ 1 - 1
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) || '';