This commit is contained in:
Viet An
2026-06-11 17:25:44 +07:00
parent 069ea1002c
commit a1450c7bde
4 changed files with 75 additions and 3 deletions

View File

@@ -0,0 +1,64 @@
<script setup>
const store = useStore();
const elapsed = ref(0);
const ellipsis = ref("");
onMounted(() => {
const animateDots = setInterval(() => {
if (ellipsis.value.length < 3) ellipsis.value += ".";
else ellipsis.value = "";
}, 500);
const start = Date.now();
const timer = setInterval(() => {
if (store.ready) {
clearInterval(timer);
clearInterval(animateDots);
elapsed.value = 0;
} else {
const ms = Date.now() - start;
elapsed.value = Math.round(ms / 1000);
}
}, 100);
});
</script>
<template>
<div class="h-dvh">
<div
class="absolute is-flex is-gap-1.5 is-flex-direction-column is-justify-content-center is-align-items-center"
style="top: 40%; left: 50%; transform: translateX(-50%)"
>
<NuxtImg
src="/favicon.svg"
width="72"
height="72"
class="pulse"
/>
<p
v-if="elapsed > 2"
class="has-text-grey"
>
<span>Đang tải dữ liệu</span>
<span class="absolute">{{ ellipsis }}</span>
</p>
</div>
</div>
</template>
<style scoped>
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% {
opacity: 1;
}
50% {
opacity: 0.6;
}
100% {
opacity: 1;
}
}
</style>

View File

@@ -1,5 +1,6 @@
<template> <template>
<ClientOnly> <AppLoading v-if="!$store.ready" />
<ClientOnly v-else>
<TopMenu @changeTab="changeTab" /> <TopMenu @changeTab="changeTab" />
<div class="container"> <div class="container">
<div <div

View File

@@ -1,4 +1,5 @@
export default defineNuxtPlugin(async (nuxtApp) => { export default defineNuxtPlugin((nuxtApp) => {
const store = useStore();
const { $getapi, $readyapi } = nuxtApp; const { $getapi, $readyapi } = nuxtApp;
const connlist = $readyapi([ const connlist = $readyapi([
"common", "common",
@@ -18,5 +19,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
"colorscheme", "colorscheme",
]); ]);
const notReadyConns = connlist.filter((v) => !v.ready); const notReadyConns = connlist.filter((v) => !v.ready);
if (notReadyConns.length > 0) await $getapi(notReadyConns);
async function getReady() {
await $getapi(notReadyConns);
store.ready = true;
}
if (notReadyConns.length > 0) getReady();
}); });

View File

@@ -2,6 +2,7 @@ import { defineStore } from "pinia";
export const useStore = defineStore("maindev", { export const useStore = defineStore("maindev", {
state: () => ({ state: () => ({
ready: false,
viewport: undefined, viewport: undefined,
login: undefined, login: undefined,
token: undefined, token: undefined,