Skip to content

Commit

Permalink
feat: 添加等待提示
Browse files Browse the repository at this point in the history
  • Loading branch information
LSX-s-Software committed Aug 24, 2023
1 parent 2bcffc9 commit 46f40ec
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
53 changes: 53 additions & 0 deletions components/z-loading.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<div class="lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</template>

<style scoped lang="less">
.lds-ring {
display: inline-block;
position: relative;
width: 1em;
height: 1em;
div {
box-sizing: border-box;
display: block;
position: absolute;
top: 0.1em;
left: 0.1em;
width: 0.8em;
height: 0.8em;
margin: 0.1em;
border: 0.1em solid #fff;
border-radius: 50%;
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #fff transparent transparent transparent;
&:nth-child(1) {
animation-delay: -0.45s;
}
&:nth-child(2) {
animation-delay: -0.3s;
}
&:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes lds-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
}
}
</style>
10 changes: 9 additions & 1 deletion pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
<nuxt-link to="/reset">忘记密码?</nuxt-link>
</template>
</z-input>
<button>登录</button>
<button type="submit">
<z-loading v-if="isLoading" />
登录<template v-if="isLoading">中...</template>
</button>
</form>
<p class="action">
还没有账号?
Expand All @@ -58,6 +61,8 @@ const appLogo = ref(route.query['app-logo']?.toString() ?? '');
const isWxapp = route.query['wxapp']?.toString() === 'true';
const isLoading = ref(false);
interface LoginRes {
id: number;
username: string;
Expand All @@ -68,6 +73,8 @@ interface LoginRes {
}
function submit(e: Event) {
if (isLoading.value) return;
isLoading.value = true;
$fetch<ResBody<LoginRes>>('https://api.cas.ziqiang.net.cn/auth/users/', {
method: 'POST',
body: {
Expand Down Expand Up @@ -110,6 +117,7 @@ function submit(e: Event) {
}
})
.catch((err) => {
isLoading.value = false;
console.error(err);
MMessage.error(err.data.msg);
});
Expand Down
12 changes: 11 additions & 1 deletion pages/register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@
<Lock />
</template>
</z-input>
<button class="submit">注册</button>
<button type="submit" class="submit">
<z-loading v-if="isLoading" />
注册<template v-if="isLoading">中...</template>
</button>
</form>
<p class="action">
已有账号?
Expand Down Expand Up @@ -114,6 +117,8 @@ const confirmedPassword = ref('');
const router = useRouter();
const isLoading = ref(false);
interface RegisterRes {
id: number;
username: string;
Expand All @@ -130,6 +135,8 @@ interface RegisterRes {
}
function submit(e: Event) {
if (isLoading.value) return;
isLoading.value = true;
e.preventDefault();
$fetch<ResBody<RegisterRes>>('https://api.cas.ziqiang.net.cn/users/', {
method: 'POST',
Expand All @@ -148,6 +155,9 @@ function submit(e: Event) {
})
.catch((err) => {
MMessage.error(err.data?.msg);
})
.finally(() => {
isLoading.value = false;
});
}
Expand Down

0 comments on commit 46f40ec

Please sign in to comment.