login.vue
4.77 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<script setup lang="ts">
import { login, menuData } from "@/api/user/login";
// import * as store from "@/pinia/index";
import router from "@/router/index";
import { useLoginStore } from "@/pinia/login";
import { reactive, ref, getCurrentInstance, onMounted } from "vue";
import type { ElForm } from "element-plus";
import { UserFilled, Lock } from "@element-plus/icons-vue";
const {
appContext: {
config: { globalProperties },
},
} = getCurrentInstance();
interface Login {
userName: string;
password: string;
}
/**
* 登录表单数据
*/
const loginForm: Login = reactive({
userName: "",
password: "",
});
let loading = ref(false);
/**
* 登录框上面标题
*/
const title = ref(import.meta.env.VITE_APP_TITLE).value;
const ruleFormRef = ref<InstanceType<typeof ElForm>>();
/**
* 表单提交
*/
const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => {
loading.value = true;
if (!formEl) return;
formEl.validate((valid) => {
if (valid) {
login(loginForm)
.then((res) => {
if (res?.data) {
globalProperties.$message.success("登录成功");
// 登录成功返回的参数含义,到pinia/modules/login.ts中查看
// store.family.loginStore().setUserInfo(res?.data?.data);
useLoginStore()?.setUserInfo(res?.data?.data);
getMenu().then((res) => {
setTimeout(() => {
router.push({ path: "/" });
}, 1000);
});
}
})
.catch((error) => {
console.log(error);
})
.finally(() => {
loading.value = false;
});
} else {
loading.value = false;
console.log("error");
}
});
};
/**
* 获取权限菜单
*/
const getMenu = async () => {
try {
let res = await menuData();
// store.family.loginStore().setMenuList(res?.data?.data);
useLoginStore()?.setMenuList(res?.data?.data);
} catch (e) {
console.log(e);
}
};
onMounted(() => {
window.localStorage.setItem('isCnlive', false)
})
</script>
<template>
<div class="login-container">
<el-form
:inline="true"
:model="loginForm"
ref="ruleFormRef"
auto-complete="on"
label-position="left"
label-width="120px"
class="login-form"
>
<div class="title-container">
<h3 class="title">{{ title }}</h3>
</div>
<el-row>
<el-form-item prop="userName" style="width: 100%">
<el-input
v-model.trim="loginForm.userName"
placeholder="请填写用户名"
maxlength="15"
:validate-event="false"
tabindex="1"
type="text"
auto-complete="off"
clearable
:prefix-icon="UserFilled"
style="width: 448px"
/>
</el-form-item>
</el-row>
<el-form-item prop="password" style="width: 100%">
<el-input
v-model.trim="loginForm.password"
placeholder="请填写密码"
:validate-event="false"
maxlength="15"
tabindex="2"
:show-password="true"
clearable
type="password"
auto-complete="off"
:prefix-icon="Lock"
@keyup.enter.native="submitForm(ruleFormRef)"
>
</el-input>
</el-form-item>
<el-form-item style="width: 100%">
<el-button
type="primary"
@click.prevent="submitForm(ruleFormRef)"
style="width: 100%"
:loading="loading"
>登录</el-button
>
</el-form-item>
</el-form>
</div>
</template>
<style lang="scss">
$bg: #283443;
$dark_gray: #889aa4;
$light_gray: #fff;
$cursor: #fff;
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
.login-container .el-input input {
color: $cursor;
}
}
.login {
&-container {
min-height: 100%;
text-align: center;
background-color: $bg;
.el-input {
input {
background: transparent;
border: 0px;
-webkit-appearance: none;
border-radius: 0px;
color: $light_gray;
height: 47px;
caret-color: $cursor;
&:-webkit-autofill {
box-shadow: 0 0 0px 1000px $bg inset !important;
-webkit-text-fill-color: $cursor !important;
}
}
}
.el-form-item {
border: 1px solid rgba(255, 255, 255, 0.1);
background: rgba(0, 0, 0, 0.1);
border-radius: 5px;
color: #454545;
}
}
&-form {
position: relative;
width: 520px;
max-width: 100%;
padding: 160px 35px 0;
margin: 0 auto;
overflow: hidden;
}
}
.title-container {
position: relative;
.title {
font-size: 26px;
color: $light_gray;
margin: 0px auto 40px auto;
text-align: center;
font-weight: bold;
}
}
</style>