Skip to content

Commit

Permalink
refactor(projects): refactor app-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jan 20, 2024
1 parent ada3f98 commit c3c143b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 53 deletions.
4 changes: 1 addition & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
<title>%VITE_APP_TITLE%</title>
</head>
<body>
<div id="app">
<div id="appLoading"></div>
</div>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
43 changes: 0 additions & 43 deletions src/components/common/app-loading.vue

This file was deleted.

9 changes: 2 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { createApp } from 'vue';
import './plugins/assets';
import { setupDayjs, setupIconifyOffline, setupNProgress } from './plugins';
import { setupDayjs, setupIconifyOffline, setupLoading, setupNProgress } from './plugins';
import { setupStore } from './store';
import { setupRouter } from './router';
import { setupI18n } from './locales';
import AppLoading from './components/common/app-loading.vue';
import App from './App.vue';

async function setupApp() {
const appLoading = createApp(AppLoading);

appLoading.mount('#appLoading');
setupLoading();

setupNProgress();

Expand All @@ -27,8 +24,6 @@ async function setupApp() {
setupI18n(app);

app.mount('#app');

appLoading.unmount();
}

setupApp();
1 change: 1 addition & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './loading';
export * from './nprogress';
export * from './iconify';
export * from './dayjs';
45 changes: 45 additions & 0 deletions src/plugins/loading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @unocss-include
import { getRgbOfColor } from '@sa/utils';
import { $t } from '@/locales';
import { localStg } from '@/utils/storage';
import systemLogo from '@/assets/svg-icon/logo.svg?raw';

export function setupLoading() {
const themeColor = localStg.get('themeColor') || '#646cff';

const { r, g, b } = getRgbOfColor(themeColor);

const primaryColor = `--primary-color: ${r} ${g} ${b}`;

const loadingClasses = [
'left-0 top-0',
'left-0 bottom-0 animate-delay-500',
'right-0 top-0 animate-delay-1000',
'right-0 bottom-0 animate-delay-1500'
];

const logoWithClass = systemLogo.replace('<svg', `<svg class="size-128px text-primary"`);

const dot = loadingClasses
.map(item => {
return `<div class="absolute w-16px h-16px bg-primary rounded-8px animate-pulse ${item}"></div>`;
})
.join('\n');

const loading = `
<div class="fixed-center flex-col" style="${primaryColor}">
${logoWithClass}
<div class="w-56px h-56px my-36px">
<div class="relative h-full animate-spin">
${dot}
</div>
</div>
<h2 class="text-28px font-500 text-#646464">${$t('system.title')}</h2>
</div>`;

const app = document.getElementById('app');

if (app) {
app.innerHTML = loading;
}
}

0 comments on commit c3c143b

Please sign in to comment.