Skip to content

Commit 923a64a

Browse files
committed
✨ add loading
1 parent d80f787 commit 923a64a

24 files changed

+458
-95
lines changed

apps/web/.eslintrc-auto-import.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@
313313
"defineLoader": true,
314314
"definePage": true,
315315
"useI18n": true,
316-
"preferredDark": true
316+
"preferredDark": true,
317+
"eventListener": true,
318+
"user": true,
319+
"ElMessage": true,
320+
"loader": true
317321
}
318322
}

apps/web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"unocss-preset-grid": "^1.4.2",
4040
"vue": "^3.4.14",
4141
"vue-i18n": "^9.8.0",
42-
"vue-router": "^4.2.5"
42+
"vue-router": "^4.2.5",
43+
"vue-starport": "^0.4.0"
4344
},
4445
"devDependencies": {
4546
"@alova/adapter-axios": "^1.2.2",
@@ -57,8 +58,8 @@
5758
"@vitejs/plugin-vue": "^5.0.3",
5859
"@vue-macros/volar": "^0.18.10",
5960
"@vue/test-utils": "^2.4.3",
60-
"critters": "^0.0.20",
6161
"commitizen": "^4.3.0",
62+
"critters": "^0.0.20",
6263
"cypress": "^13.6.2",
6364
"cypress-vite": "^1.5.0",
6465
"cz-emoji": "1.3.2-canary.2",

apps/web/src/App.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
<script setup>
2+
import { StarportCarrier } from 'vue-starport'
3+
4+
const { PageIn, PageOut, checkLoading } = useStore('loader')
5+
6+
// 全局加载动画
7+
const router = useRouter()
8+
9+
onMounted(() => {
10+
checkLoading();
11+
router.beforeEach((to, from, next) => {
12+
PageIn(next);
13+
});
14+
router.afterEach((to, from) => {
15+
PageOut();
16+
});
17+
})
18+
</script>
19+
120
<template>
2-
<RouterView />
21+
<Loading/>
22+
<StarportCarrier>
23+
<RouterView />
24+
</StarportCarrier>
325
</template>

apps/web/src/api/methods/user.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

apps/web/src/api/methods/userApi.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 案例学习:https://alova.js.org/zh-CN/tutorial/best-practice/method-manage
2+
import http from '..'
3+
4+
interface LoginParams {
5+
username: string;
6+
password: string;
7+
}
8+
9+
export default {
10+
register: (username: string, password: string, confirmPassword: string) => {
11+
return http.post('/user/register', {
12+
username,
13+
password,
14+
confirmPassword,
15+
})
16+
},
17+
18+
Login: ({ username, password}: LoginParams) => {
19+
return http.post('/user/login', {
20+
username,
21+
password,
22+
})
23+
},
24+
}

apps/web/src/components/AuthBox.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import LogoJSON from '@/assets/lottie/logo.json'
1717
<h2 my-2 mt-8 font-bold text-5 color-green-500 text-center>
1818
<slot name="header"></slot>
1919
</h2>
20-
<div h-50>
20+
<div h-60 pb-5>
2121
<slot name="content"></slot>
2222
</div>
2323
</div>

apps/web/src/components/Loading.vue

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<template>
2+
<div id="loading">
3+
<svg viewBox='0 0 50 50'>
4+
<circle r='25' cx='25' cy='25'></circle>
5+
</svg>
6+
<p>LOADING</p>
7+
</div>
8+
</template>
9+
10+
<script>
11+
export default {
12+
// JIEJOE produce
13+
// b站主页:https://space.bilibili.com/3546390319860710
14+
name: "loading",
15+
methods: {
16+
in(next) {
17+
let conainer = document.getElementById("loading");
18+
conainer.classList.remove("loading_out");
19+
setTimeout(() => {
20+
next();
21+
this.$parent.check_loading();
22+
}, 1000);
23+
},
24+
out() {
25+
let conainer = document.getElementById("loading");
26+
conainer.classList.add("loading_out");
27+
},
28+
},
29+
};
30+
</script>
31+
32+
33+
<style>
34+
#loading {
35+
position: fixed;
36+
flex-direction: column;
37+
top: 0;
38+
left: 0;
39+
width: 100%;
40+
height: 100vh;
41+
background-color: #f7f7f7;
42+
z-index: 100000000;
43+
transition: 1s ease;
44+
}
45+
46+
#loading svg {
47+
width: 5rem;
48+
margin-bottom: 2rem;
49+
overflow: visible;
50+
transition: 0.3s ease;
51+
}
52+
53+
#loading svg circle {
54+
fill: none;
55+
stroke: #171717;
56+
stroke-width: 12;
57+
stroke-dasharray: 160;
58+
stroke-dashoffset: 160;
59+
transform-origin: center;
60+
animation: circle_rotate 3s ease-in infinite;
61+
}
62+
63+
@keyframes circle_rotate {
64+
0% {
65+
transform: rotate(0deg);
66+
stroke-dashoffset: 160;
67+
}
68+
69+
100% {
70+
transform: rotate(360deg);
71+
stroke-dashoffset: -160;
72+
}
73+
}
74+
75+
#loading p {
76+
font-family: sans-serif;
77+
font-size: 2rem;
78+
color: #171717;
79+
font-weight: 900;
80+
transition: 0.3s ease;
81+
}
82+
83+
.loading_out {
84+
transform: translateY(100%);
85+
}
86+
87+
.loading_out svg,
88+
.loading_out p {
89+
opacity: 0;
90+
}
91+
</style>

0 commit comments

Comments
 (0)