feat(project): support app custom loading template

This commit is contained in:
vince 2024-07-10 22:44:48 +08:00
parent 8952e947bf
commit 0f246f7e9e
5 changed files with 16 additions and 10 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

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

View File

@ -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) || '';