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 726abe4 commit b4f3dd2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 71 deletions.
4 changes: 1 addition & 3 deletions index.html
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>
28 changes: 11 additions & 17 deletions src/App.vue
Expand Up @@ -4,7 +4,6 @@ import { NConfigProvider, darkTheme } from 'naive-ui';
import { useAppStore } from './store/modules/app';
import { useThemeStore } from './store/modules/theme';
import { naiveDateLocales, naiveLocales } from './locales/naive';
import AppLoading from './components/common/app-loading.vue';
defineOptions({
name: 'App'
Expand All @@ -25,22 +24,17 @@ const naiveDateLocale = computed(() => {
</script>

<template>
<Suspense>
<NConfigProvider
:theme="naiveDarkTheme"
:theme-overrides="themeStore.naiveTheme"
:locale="naiveLocale"
:date-locale="naiveDateLocale"
class="h-full"
>
<AppProvider>
<RouterView class="bg-layout" />
</AppProvider>
</NConfigProvider>
<template #fallback>
<AppLoading />
</template>
</Suspense>
<NConfigProvider
:theme="naiveDarkTheme"
:theme-overrides="themeStore.naiveTheme"
:locale="naiveLocale"
:date-locale="naiveDateLocale"
class="h-full"
>
<AppProvider>
<RouterView class="bg-layout" />
</AppProvider>
</NConfigProvider>
</template>

<style scoped></style>
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
@@ -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
@@ -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
@@ -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;
}
}
1 change: 0 additions & 1 deletion src/typings/components.d.ts
Expand Up @@ -7,7 +7,6 @@ export {}

declare module 'vue' {
export interface GlobalComponents {
AppLoading: typeof import('./../components/common/app-loading.vue')['default']
AppProvider: typeof import('./../components/common/app-provider.vue')['default']
BetterScroll: typeof import('./../components/custom/better-scroll.vue')['default']
ButtonIcon: typeof import('./../components/custom/button-icon.vue')['default']
Expand Down

1 comment on commit b4f3dd2

@vercel
Copy link

@vercel vercel bot commented on b4f3dd2 Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

soybean-admin – ./

soybean-admin-git-main-soybeanjs.vercel.app
soybean-admin-soybeanjs.vercel.app
soybean-admin-eta.vercel.app

Please sign in to comment.