You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

463 lines
12 KiB
Vue

4 years ago
<template>
<div class="center">
<div class="formcontainer">
<ul class="loginchange centerall">
<li :class="{ loginactive: loginway === 1 }" @click="loginway = 1">
用户名密码登录
</li>
<li :class="{ loginactive: loginway === 2 }" @click="loginway = 2">
手机验证码登录
</li>
</ul>
<div class="formbox">
<template v-if="loginway === 1">
<a-form
id="components-form-demo-normal-login"
:form="form"
class="login-form"
@submit="userhandleSubmit"
>
<a-form-item style="text-align: left">
<a-input
v-decorator="[
'tel',
{
rules: [
{
required: true,
message: '请输入用户名',
},
{
pattern: /^1[3456789]\d{9}$/,
message: '请输入正确手机号',
},
],
validateTrigger: 'submit',
},
]"
:maxLength="11"
placeholder="请输入用户名"
>
<i
slot="prefix"
class="iconfont icon-yonghuming"
style="font-size: 24px"
/>
</a-input>
</a-form-item>
<a-form-item style="text-align: left">
<a-input
v-decorator="[
'password',
{
rules: [
{
required: true,
message: '请输入密码',
},
],
validateTrigger: 'submit',
},
]"
type="password"
placeholder="请输入密码"
>
<i slot="prefix" class="iconfont icon-mima" />
</a-input>
</a-form-item>
<div class="autologin">
4 years ago
<span @click="isauto = !isauto" style="opacity: 0">
<i class="iconfont icon-xuanzhong" v-if="isauto"></i>
<i
class="iconfont icon-weixuanzhong"
v-else
style="color: #999"
></i>
4 years ago
<label for="register">下次自动登录</label></span
4 years ago
>
4 years ago
<router-link to="updatepsw" class="login-form-forgot" href=""
>忘记密码</router-link
>
4 years ago
</div>
<a-form-item>
<a-button
type="primary"
html-type="submit"
class="login-form-button"
>
登录
</a-button>
</a-form-item>
</a-form>
<!-- <div class="register">
<router-link to="/register">还没有账号立即注册</router-link>
</div> -->
</template>
<template v-if="loginway === 2">
<a-form
id="components-form-demo-normal-login"
:form="form1"
class="login-form"
@submit="phonehandleSubmit"
>
<a-form-item style="text-align: left">
<a-input
v-decorator="[
4 years ago
'tel',
4 years ago
{
rules: [
{ required: true, message: '请输入手机号' },
{
pattern: /^1[3456789]\d{9}$/,
message: '请输入正确手机号',
},
],
validateTrigger: 'submit',
},
]"
autocomplete="off"
:maxLength="11"
placeholder="请输入手机号"
>
<i
slot="prefix"
class="icon-shouji iconfont"
style="font-size: 24px"
/>
</a-input>
</a-form-item>
<a-form-item style="text-align: left">
<a-input
v-decorator="[
'code',
{
rules: [
{
required: true,
message: '请输入验证码',
},
],
validateTrigger: 'submit',
},
]"
type="text"
placeholder="请输入验证码"
>
<i slot="prefix" class="icon-duanxinyanzheng iconfont" />
<span class="getrulecode" slot="suffix"
><span
@click="getPhoneCode"
data-mark="getcode"
v-if="timedata.isfinish"
>获取验证码</span
><timmer :timedata="timedata" v-if="!timedata.isfinish"
/></span>
</a-input>
</a-form-item>
<div class="autologin">
4 years ago
<span @click="isauto = !isauto" style="opacity: 0">
<i class="iconfont icon-xuanzhong" v-if="isauto"></i>
<i
class="iconfont icon-weixuanzhong"
v-else
style="color: #999"
></i>
4 years ago
<label for="register">下次自动登录</label>
4 years ago
</span>
4 years ago
<router-link to="/updatepsw" class="login-form-forgot" href=""
>忘记密码</router-link
>
4 years ago
</div>
<a-form-item>
<a-button
type="primary"
html-type="submit"
class="login-form-button"
>
登录
</a-button>
</a-form-item>
</a-form>
<!-- <div class="register">
<router-link to="/register">还没有账号立即注册</router-link>
</div> -->
</template>
</div>
</div>
</div>
</template>
<script>
import { loginApi, getPhoneCodeApi } from "../../api/login";
import timmer from "./components/countback.vue";
export default {
4 years ago
inject: ["reload"],
4 years ago
// 组件名称
name: "",
// 局部注册的组件
components: {
timmer,
},
// 组件参数 接收来自父组件的数据
props: {},
// 组件状态值
data() {
return {
loginway: 1,
ischecked: false,
4 years ago
isauto: false, // 是否自动登录
4 years ago
form: this.$form.createForm(this),
form1: this.$form.createForm(this),
timedata: {
isfinish: true,
deadline: 60,
timmer: null,
},
};
},
// 计算属性
computed: {},
// 侦听器
watch: {},
// 生命周期钩子 注:没用到的钩子请自行删除
/**
* 组件实例创建完成属性已绑定但DOM还未生成$ el属性还不存在
*/
created() {},
/**
* el 被新创建的 vm.el 替换并挂载到实例上去之后调用该钩子
* 如果 root 实例挂载了一个文档内元素 mounted 被调用时 vm.el 也在文档内
*/
mounted() {},
// 组件方法
methods: {
userhandleSubmit(e) {
// 用户名登录提交
e.preventDefault();
let params;
this.form.validateFields(async (err, values) => {
console.log(values);
if (!err) {
params = { ...values, loginType: 0 };
console.log(params);
try {
const { data } = await loginApi(params);
console.log(data);
if (data.status !== 200) {
this.$message.warning(data.msg);
return;
}
localStorage.setItem("LOGIN_DATA", JSON.stringify(data.data));
this.$router.push("/list");
4 years ago
this.reload();
4 years ago
// this.$router.push("/list");
} catch (err) {
console.log(err);
}
} else {
console.log(err);
}
});
},
phonehandleSubmit(e) {
e.preventDefault();
let params;
this.form1.validateFields(async (err, values) => {
console.log(err);
if (!err) {
params = { ...values, loginType: 1 };
try {
4 years ago
const { data } = await loginApi(params);
4 years ago
console.log(data);
4 years ago
if (data.status !== 200) {
this.$message.warning(data.msg);
return;
}
localStorage.setItem("LOGIN_DATA", JSON.stringify(data.data));
this.$router.push("/list");
this.reload();
4 years ago
} catch (err) {
console.log(err);
}
} else {
console.log(err);
}
});
},
async getPhoneCode() {
const that = this;
4 years ago
this.form1.validateFields(["tel"], async (err, values) => {
4 years ago
console.log(values);
if (!err) {
that.timedata.isfinish = false;
try {
4 years ago
const { data } = await getPhoneCodeApi({ tel: values.tel });
4 years ago
console.log(data);
4 years ago
if (data.status !== 200) {
this.$message.warning(data.msg);
}
4 years ago
} catch (error) {
console.log(error);
}
} else {
console.log(err);
}
});
},
checked() {
console.log(this.ischecked);
},
},
};
</script>
<style scoped lang="less">
.center {
4 years ago
width: 240px;
margin: 0 auto;
4 years ago
overflow: hidden;
/deep/ .login-form {
background-color: #fff !important;
}
.centerall {
margin: 0 auto;
}
.loginchange {
display: flex;
width: 230px;
justify-content: space-between;
margin-top: 10px;
.loginactive {
color: #4d575e;
border-bottom: 1px solid #4d575e;
}
li {
padding: 0 0 4px 0;
4 years ago
margin-bottom: 50px;
4 years ago
font-size: 14px;
text-align: left;
color: #cccccc;
line-height: 22px;
cursor: pointer;
}
}
.formbox {
// /deep/ .ant-form-item {
// margin-bottom: 0px !important;
// padding-bottom: 20px !important;
// }
4 years ago
/deep/.ant-form-item {
margin-top: -10px;
/deep/ .ant-form-explain {
margin-top: -2px;
line-height: 20px;
min-height: 20px !important;
}
4 years ago
i {
font-size: 26px;
// margin: 0 8px 0 4px;
color: #4d575e;
}
.ant-input {
4 years ago
height: 32px;
4 years ago
text-indent: 15px;
4 years ago
// background-color: #f6f6f6;
// border: none;
padding: 0 0 0 23px !important;
border: 1px solid #dddddd;
4 years ago
&:hover {
border-color: #ff6a00;
}
&:focus {
box-shadow: none;
}
&::placeholder {
opacity: 0.4;
color: #4d575e;
font-size: 14px;
text-indent: 15px;
}
}
}
.login-form-button {
width: 100%;
height: 36px;
4 years ago
margin-top: 20px;
4 years ago
border-radius: 27px;
background-color: #ff6a00;
font-size: 16px;
border: none;
color: white;
}
.register {
display: flex;
justify-content: center;
font-size: 12px;
span {
color: #4d575e;
i {
vertical-align: middle;
margin-right: 10px;
}
}
a {
color: #353649;
}
}
.autologin {
display: flex;
justify-content: space-between;
4 years ago
font-size: 12px;
4 years ago
margin-top: -16px;
4 years ago
> span {
cursor: pointer;
4 years ago
line-height: 18px;
margin-top: 2px;
i {
color: #ff6a00;
font-size: 14px;
4 years ago
vertical-align: middle;
4 years ago
margin-right: 5px;
}
input {
margin-top: -3px;
vertical-align: bottom;
4 years ago
}
4 years ago
label {
transition: all 0.2s;
4 years ago
font-size: 12px;
&:hover {
color: #ff6a00;
}
4 years ago
}
}
a {
color: #4d575e;
}
}
.getrulecode {
4 years ago
// padding: 0 0 0 10px;
4 years ago
font-size: 12px;
4 years ago
width: 67px;
4 years ago
text-align: center;
border-left: 1px #cccccc solid;
4 years ago
line-height: 12px;
4 years ago
color: #4d575e;
span[data-mark="getcode"] {
4 years ago
padding: 0 0 0 5px;
4 years ago
cursor: pointer;
}
}
}
}
</style>