index.vue
3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
<div class="container">
<div class="banner">
<div class="banner-inner"></div>
</div>
<div class="content">
<div class="content-inner">
<div class="login-form-wrapper">
<div class="login-form-title">海星试唱</div>
<div class="login-form-sub-title">厂牌管理后台</div>
<a-card :bordered="true" :hoverable="true" :style="{ width: '360px' }">
<a-tabs v-model:active-key="loginType" :justify-="true" :animation="true">
<a-tab-pane key="email" title="邮箱登录">
<EmailForm ref="emailRef" />
</a-tab-pane>
<a-tab-pane key="phone" title="手机登录">
<PhoneForm ref="phoneRef" />
</a-tab-pane>
</a-tabs>
<div class="login-form-actions">
<!-- <a-link>忘记密码</a-link>-->
<a-button type="primary" :long="true" :loading="loading" @click="onLogin()"> 登录</a-button>
</div>
</a-card>
</div>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import EmailForm from '@/views/login/components/email-form.vue';
import PhoneForm from '@/views/login/components/phone-form.vue';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { AttributeData } from '@/types/global';
import { setToken } from '@/utils/auth';
import { Message } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
import useProviderApi from '@/api/provider';
const { loading, setLoading } = useLoading(false);
const loginType = ref<'email' | 'phone'>('email');
const emailRef = ref<InstanceType<typeof EmailForm>>();
const phoneRef = ref<InstanceType<typeof PhoneForm>>();
const router = useRouter();
const onSubmit = (value: AttributeData) => {
setLoading(true);
useProviderApi
.login(loginType.value, value)
.then(({ data }) => {
const { access_token, refresh_token, nick_name } = data;
setToken(access_token, refresh_token);
Message.success(`欢迎回来,管理员:${nick_name}`);
const { path } = router.currentRoute.value.query;
router.replace((path as string) || '/dashboard');
})
.finally(() => setLoading(false));
};
const onLogin = () => {
// eslint-disable-next-line default-case
switch (loginType.value) {
case 'email':
emailRef.value?.onSubmit(onSubmit);
break;
case 'phone':
phoneRef.value?.onSubmit(onSubmit);
break;
}
};
</script>
<style lang="less" scoped>
.container {
display: flex;
height: 100vh;
.banner {
width: 550px;
}
.content {
position: relative;
display: flex;
flex: 1;
align-items: center;
justify-content: center;
padding-bottom: 40px;
.login-form-wrapper {
width: 320px;
}
.login-form-title {
color: var(--color-text-1);
font-weight: 500;
font-size: 30px;
line-height: 46px;
text-align: center;
}
.login-form-sub-title {
color: var(--color-text-3);
font-size: 16px;
line-height: 24px;
text-align: center;
margin-bottom: 16px;
}
.login-form-actions {
display: flex;
justify-content: right;
}
}
.footer {
position: absolute;
right: 0;
bottom: 0;
width: 100%;
}
}
.logo {
position: fixed;
top: 24px;
left: 22px;
z-index: 1;
display: inline-flex;
align-items: center;
&-text {
margin-right: 4px;
margin-left: 4px;
color: var(--color-fill-1);
font-size: 20px;
}
}
.banner {
display: flex;
align-items: center;
justify-content: center;
&-inner {
flex: 1;
height: 100%;
//background-image: url('/src/assets/images/bg.jpg');
background-image: url('https://spreadcdn.hikoon.com/default/bg.jpg');
background-size: cover;
}
}
</style>