feat(project): support app custom loading template
							parent
							
								
									8952e947bf
								
							
						
					
					
						commit
						0f246f7e9e
					
				|  | @ -65,7 +65,7 @@ | ||||||
|     display: block; |     display: block; | ||||||
|     width: 20px; |     width: 20px; | ||||||
|     height: 20px; |     height: 20px; | ||||||
|     background-color: #0065cc; |     background-color: hsl(var(--primary, 210 100% 50%)); | ||||||
|     border-radius: 100%; |     border-radius: 100%; | ||||||
|     opacity: 0.3; |     opacity: 0.3; | ||||||
|     transform: scale(0.75); |     transform: scale(0.75); | ||||||
|  | @ -56,7 +56,7 @@ | ||||||
|     width: 48px; |     width: 48px; | ||||||
|     height: 5px; |     height: 5px; | ||||||
|     content: ''; |     content: ''; | ||||||
|     background: hsl(var(--primary) / 50%); |     background: hsl(var(--primary, 210 100% 50%) / 50%); | ||||||
|     border-radius: 50%; |     border-radius: 50%; | ||||||
|     animation: shadow-ani 0.5s linear infinite; |     animation: shadow-ani 0.5s linear infinite; | ||||||
|   } |   } | ||||||
|  | @ -68,7 +68,7 @@ | ||||||
|     width: 100%; |     width: 100%; | ||||||
|     height: 100%; |     height: 100%; | ||||||
|     content: ''; |     content: ''; | ||||||
|     background: hsl(var(--primary)); |     background: hsl(var(--primary, 210 100% 50%)); | ||||||
|     border-radius: 4px; |     border-radius: 4px; | ||||||
|     animation: jump-ani 0.5s linear infinite; |     animation: jump-ani 0.5s linear infinite; | ||||||
|   } |   } | ||||||
|  | @ -12,8 +12,9 @@ import { type PluginOption } from 'vite'; | ||||||
| async function viteInjectAppLoadingPlugin( | async function viteInjectAppLoadingPlugin( | ||||||
|   isBuild: boolean, |   isBuild: boolean, | ||||||
|   env: Record<string, any> = {}, |   env: Record<string, any> = {}, | ||||||
|  |   loadingTemplate = 'loading.html', | ||||||
| ): Promise<PluginOption | undefined> { | ): Promise<PluginOption | undefined> { | ||||||
|   const loadingHtml = await getLoadingRawByHtmlTemplate(); |   const loadingHtml = await getLoadingRawByHtmlTemplate(loadingTemplate); | ||||||
|   const envRaw = isBuild ? 'prod' : 'dev'; |   const envRaw = isBuild ? 'prod' : 'dev'; | ||||||
|   const cacheName = `'${env.VITE_APP_NAMESPACE}-${envRaw}-preferences-theme'`; |   const cacheName = `'${env.VITE_APP_NAMESPACE}-${envRaw}-preferences-theme'`; | ||||||
| 
 | 
 | ||||||
|  | @ -47,10 +48,15 @@ async function viteInjectAppLoadingPlugin( | ||||||
| /** | /** | ||||||
|  * 用于获取loading的html模板 |  * 用于获取loading的html模板 | ||||||
|  */ |  */ | ||||||
| async function getLoadingRawByHtmlTemplate() { | async function getLoadingRawByHtmlTemplate(loadingTemplate: string) { | ||||||
|   const __dirname = fileURLToPath(new URL('.', import.meta.url)); |   const __dirname = fileURLToPath(new URL('.', import.meta.url)); | ||||||
|   const loadingPath = join(__dirname, './loading.html'); |   const defaultLoadingPath = join(__dirname, './default-loading.html'); | ||||||
|   if (!fs.existsSync(loadingPath)) { |   // 支持在app内自定义loading模板,模版参考default-loading.html即可
 | ||||||
|  |   const appLoadingPath = join(process.cwd(), loadingTemplate); | ||||||
|  |   let loadingPath = defaultLoadingPath; | ||||||
|  | 
 | ||||||
|  |   if (fs.existsSync(appLoadingPath)) { | ||||||
|  |     loadingPath = appLoadingPath; | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,12 +3,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||||||
| import { StorageManager } from './storage-manager'; | import { StorageManager } from './storage-manager'; | ||||||
| 
 | 
 | ||||||
| describe('storageManager', () => { | describe('storageManager', () => { | ||||||
|   let storageManager: StorageManager<{ age: number; name: string }>; |   let storageManager: StorageManager; | ||||||
| 
 | 
 | ||||||
|   beforeEach(() => { |   beforeEach(() => { | ||||||
|     vi.useFakeTimers(); |     vi.useFakeTimers(); | ||||||
|     localStorage.clear(); |     localStorage.clear(); | ||||||
|     storageManager = new StorageManager<{ age: number; name: string }>({ |     storageManager = new StorageManager({ | ||||||
|       prefix: 'test_', |       prefix: 'test_', | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|  | @ -102,7 +102,7 @@ const emit = defineEmits<{ | ||||||
| 
 | 
 | ||||||
| const router = useRouter(); | 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) || ''; | const localUsername = localStorage.getItem(REMEMBER_ME_KEY) || ''; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 vince
						vince