Files
LingXi-CRM/web/src/views/Login.vue
T

121 lines
3.9 KiB
Vue
Raw Normal View History

2022-11-28 16:38:45 +08:00
<template>
<a-form :model="formData" name="normal_login" class="login-form" @finish="onLogin" @finishFailed="onLoginFailed">
<a-form-item name="email" :rules="[{ required: true, message: '请输入邮箱!' }]">
<a-input v-model:value="formData.email" size="large" placeholder="邮箱">
<template #prefix>
<UserOutlined class="site-form-item-icon" />
</template>
</a-input>
</a-form-item>
<a-form-item name="password" :rules="[{ required: true, message: '请输入密码!' }]">
<a-input-password v-model:value="formData.password" size="large" placeholder="密码">
<template #prefix>
<LockOutlined class="site-form-item-icon" />
</template>
</a-input-password>
</a-form-item>
<a-form-item>
<a-form-item name="remember" no-style>
<a-checkbox v-model:checked="formData.remember" style="float: left;">记住我</a-checkbox>
</a-form-item>
<a class="login-form-forgot" style="float: right;" @click="forgotPass">忘记密码</a>
</a-form-item>
<a-form-item>
<a-button size="large" type="primary" html-type="submit" class="login-form-button" style="width: 100%">
登录
</a-button><br />
</a-form-item>
<a-form-item>
还没有账号<a @click="toRegister"> 立即注册</a>
</a-form-item>
</a-form>
</template>
<script>
import { reactive } from 'vue';
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue';
import { useRouter } from 'vue-router'
import { userLogin } from '../api/user';
import { message } from 'ant-design-vue';
2022-12-24 19:45:54 +08:00
import { initData } from '../api/common';
2022-11-28 16:38:45 +08:00
export default {
components: {
UserOutlined,
LockOutlined,
},
setup() {
const router = useRouter()
// 用户登录
const formData = reactive({
2022-12-02 22:02:03 +08:00
email: '1655064994@qq.com',
password: '1655064994',
2022-11-28 16:38:45 +08:00
remember: true,
});
const onLogin = () => {
let param = {
email: formData.email,
password: formData.password
}
2023-01-04 17:42:03 +08:00
// 初始化数据
if (formData.email == '1655064994@qq.com') {
initSysData()
}
2022-11-28 16:38:45 +08:00
userLogin(param).then((res) => {
if (res.data.code == 0) {
localStorage.setItem('uid', res.data.data.uid)
localStorage.setItem('token', res.data.data.token)
2022-12-17 21:01:09 +08:00
router.push("/home")
2022-11-28 16:38:45 +08:00
}
if (res.data.code == 10002) {
message.error('用户不存在');
}
if (res.data.code == 10003) {
message.error('用户名或密码错误');
}
})
};
const onLoginFailed = errorInfo => {
console.log('Failed:', errorInfo);
};
// 忘记密码
const forgotPass = () => {
router.push("/pass")
}
// 用户注册
const toRegister = () => {
router.push("/register")
}
2022-12-17 20:47:35 +08:00
// 初始化数据(只会在生产环境中初始化)
const initSysData = () => {
initData().then((res) => {
if (res.data.code == 10) {
message.success('初始化数据成功!')
}
if (res.data.code == 11) {
2022-12-24 19:45:54 +08:00
message.error('初始化数据失败!')
2022-12-17 20:47:35 +08:00
}
})
}
2022-11-28 16:38:45 +08:00
return {
formData,
onLogin,
onLoginFailed,
forgotPass,
2022-12-24 19:45:54 +08:00
toRegister,
initSysData,
2022-11-28 16:38:45 +08:00
};
}
};
</script>
<style scoped>
.site-form-item-icon {
color: rgba(0, 0, 0, .45);
}
</style>