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

355 lines
13 KiB

4 years ago
<template>
<div class="wrap">
<div class="login">
<div class="form">
3 years ago
<h6 class="title">欢迎使用请登录</h6>
4 years ago
<ul class="tab">
<li v-for="(item,index) in tabList" :key="index" :class="{active: form.distinguish == item.id}" @click="typeClick(item)">{{item.label}}</li>
</ul>
<el-form :model="form" :rules="rules" ref="login" label-width="0px">
4 years ago
<el-form-item prop="account">
4 years ago
<label class="account"></label>
4 years ago
<el-input v-model="form.account" :placeholder="form.distinguish == 1 ? '请输入账号' : '请输入手机号/邮箱'" @keyup.enter.native="submitForm"></el-input>
4 years ago
</el-form-item>
<el-form-item prop="password">
<label class="password"></label>
4 years ago
<el-input type="password" placeholder="请输入密码" v-model="form.password" @keyup.enter.native="submitForm"></el-input>
4 years ago
</el-form-item>
<el-form-item prop="code">
<label class="code"></label>
4 years ago
<el-input placeholder="请输入验证码" v-model="form.code" @keyup.enter.native="submitForm"></el-input>
4 years ago
<img @click="getVerImg" :src="verificationIMG" class="ver-img" alt="">
4 years ago
</el-form-item>
<el-button class="submit" type="primary" @click="submitForm">登录</el-button>
</el-form>
</div>
</div>
4 years ago
<el-dialog title="绑定手机号" :visible.sync="phoneVisible" :close-on-click-modal="false" width="576px">
<p class="tips">依据国家政策法规需绑定手机号进行网络实名才可登录使用本平台</p>
4 years ago
<el-form ref="form" label-width="60px">
<el-form-item label="手机号">
4 years ago
<el-input style="width: 394px;" placeholder="请输入手机号" v-model="phone" maxlength="11"></el-input>
4 years ago
</el-form-item>
<el-form-item label="验证码">
<div class="flex">
<el-input v-model="phoneCode" placeholder="请输入验证码" maxlength="6"></el-input>
<el-button style="margin-left: 10px" type="text" @click="sendPhoneCode" :disabled="phoneDisabled">{{phoneBtnText}}</el-button>
</div>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="phoneVisible = false"> </el-button>
<el-button size="small" type="primary" @click="phoneSubmit"> </el-button>
</span>
</el-dialog>
4 years ago
<div class="footer">
<div class="copyright">
<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20072679号</a>
</div>
</div>
4 years ago
</div>
</template>
<script>
import { mapMutations, mapActions } from 'vuex'
4 years ago
import vHead from '@/layouts/header'
4 years ago
import util from '@/libs/util'
4 years ago
import Setting from '@/setting'
4 years ago
import vFooter from '@/layouts/footer'
import axios from 'axios'
4 years ago
export default {
data: function() {
return {
4 years ago
tabList: [
{
id: '1',
3 years ago
label: '账号'
4 years ago
},{
id: '2',
3 years ago
label: '手机号/邮箱'
4 years ago
}
],
4 years ago
verificationIMG: '',
4 years ago
form: {
distinguish: '1',
3 years ago
account: '',
password: '',
4 years ago
random: '',
code: '',
type: 2, // 平台端区分:0->教师端 1->学生端 2->无端
platform: Setting.platformId, // 所属平台id(1.职站 2.数据平台 3.中台)
4 years ago
},
4 years ago
rules: {
account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
4 years ago
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
4 years ago
code: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
4 years ago
},
token: '',
4 years ago
phoneVisible: false,
phone: '',
phoneCode: '',
phoneDisabled: false,
phoneTimer: null,
phoneBtnText: '发送验证码'
4 years ago
};
},
4 years ago
components: {vHead,vFooter},
4 years ago
mounted(){
this.getVerImg()
},
4 years ago
methods: {
...mapMutations("user", [
'SET_CUSTOMERNAME', 'SET_CUSTOMER', 'SET_INFO'
]),
4 years ago
...mapActions('user', [
4 years ago
'login','setCustomer'
4 years ago
]),
4 years ago
typeClick(item){
this.form.account = ''
this.form.distinguish = item.id
this.$refs.login.clearValidate()
this.rules.account[0].message = item.id == 1 ? '请输入账号' : '请输入手机号/邮箱'
},
// 处理登录成功
setLogin() {
window.opener && window.opener.location.reload() // 刷新官网
util.local.set(Setting.tokenKey, this.token, Setting.tokenExpires)
// 查询是否是客户,如果是客户,则弹出选择端的页面去选择跳转到哪个端
this.$get(this.api.isClient).then(res => {
// 如果是客户
this.SET_CUSTOMER(res.customer)
const userName = res.customerName
userName && this.SET_INFO({
userName
})
}).catch(res => {})
// 查询schoolId
this.$post(this.api.getSchoolIdByToken).then(res => {
this.SET_INFO(res)
}).catch(res => {})
// 登录次数+1
this.$post(this.api.saveRecord,{
type: 3,
}).then(res => {}).catch(res => {})
// 查询是否有更新日志,如果返回了true,则直接跳转到日志页
this.$get(this.api.logNotification).then(res => {
const history = this.$route.query.redirect
const redirect = res.notification ?
'/log' :
history ?
decodeURIComponent(history) :
'/index'
util.successMsg('登录成功')
this.$router.replace(redirect)
}).catch(res => {})
},
4 years ago
submitForm() {
this.$refs.login.validate(valid => {
if (valid) {
this.$post(this.api.logins, this.form).then(res => {
// 如果没有绑定手机号
if (res && res.status == 30001) {
this.phoneVisible = true
this.getVerImg()
this.form.code = ''
} else {
this.token = res.data.token
this.setLogin()
}
}).catch(res => {})
4 years ago
}
})
},
4 years ago
getVerImg(){
4 years ago
this.form.random = Math.floor(Math.random()*999999999)
this.verificationIMG = this.api.verification+'?random='+`${this.form.random}`
},
phoneCountdown(){
let count = 60
if(!this.phoneTimer){
this.phoneDisabled = true
this.phoneTimer = setInterval(() => {
console.log('倒计时中')
if(count > 0){
count--
this.phoneBtnText = `${count}秒后重试`
}else{
this.phoneDisabled = false
clearInterval(this.phoneTimer)
this.phoneTimer = null
this.phoneBtnText = `发送验证码`
}
},1000)
}
},
sendPhoneCode(){
if(!this.phone) return util.warningMsg('请输入手机号')
if(!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg('请输入正确的手机号')
let data = {
phone: this.phone,
types: 2 // 邮箱:1,手机:2
4 years ago
}
this.$post(this.api.sendPhoneOrEmailCode,data).then(res => {
if(res.message.opener){
this.phoneCountdown()
this.phoneOpener = res.message.opener
}else{
util.errorMsg(res.message)
}
}).catch(res => {})
},
phoneSubmit(){
if(!this.phone) return util.warningMsg('请输入手机号')
if(!/^1[3456789]\d{9}$/.test(this.phone)) return util.warningMsg('请输入正确的手机号')
if(!this.phoneCode) return util.warningMsg('请输入验证码')
let data = {
phone: this.phone,
types: 2,
code: this.phoneCode,
opener: this.phoneOpener,
platform: Setting.platformId,
account: this.form.account
}
this.$post(this.api.bindPhoneOrEmail,data).then(res => {
util.successMsg('绑定成功')
this.form.phone = this.phone
this.phoneVisible = false
this.setLogin()
4 years ago
}).catch(res => {})
},
4 years ago
},
};
</script>
<style scoped lang="scss">
.wrap {
min-height: 100%;
background-color: #F3F6FA;
.login{
min-height: calc(100vh - 70px);
padding-top: calc((100vh - 611px) / 2);
background: url(../../../assets/img/shapes/shape1.png) (0 123px)/auto no-repeat,
url(../../../assets/img/shapes/shape2.png) (35px 238px)/auto no-repeat,
url(../../../assets/img/shapes/shape3.png) (0 485px)/auto no-repeat,
url(../../../assets/img/shapes/shape4.png) (right 50%)/auto no-repeat,
url(../../../assets/img/shapes/shape5.png) (right 80%)/auto no-repeat,
url(../../../assets/img/shapes/shape6.png) (right bottom)/auto no-repeat;
.form{
3 years ago
width: 436px;
padding: 38px 38px 60px;
margin: 0 auto 0;
border-radius: 6px;
background-color: #fff;
.title{
margin-bottom: 25px;
font-size: 26px;
color: #0B1D30;
letter-spacing: 4px;
}
.tab{
display: flex;
align-items: center;
margin-bottom: 24px;
border-bottom: 2px solid #E1E6F2;
li{
padding: 18px 0;
margin-bottom: -1px;
font-size: 18px;
color: #555;
cursor: pointer;
border-bottom: 4px solid transparent;
&:first-child{
margin-right: 50px;
}
&.active{
color: #006EFF;;
border-bottom-color: #006EFF;
4 years ago
}
}
}
.label{
margin-bottom: 10px;
color: #105CB2;
}
/deep/.el-form-item{
margin-bottom: 20px;
}
/deep/.el-input__inner{
position: relative;
height: 52px;
padding: 0 20px 0 34px;
line-height: 50px;
background-color: #FBFBFB;
border: 1px solid #E1E6F2;
border-radius: 4px !important;
}
.account,.password,.code{
z-index: 1;
position: absolute;
top: 17px;
left: 11px;
width: 18px;
height: 18px;
background: url(../../../assets/img/login/account.png) 0 0/100% 100% no-repeat;
}
.password{
top: 18px;
background-image: url(../../../assets/img/login/password.png);
}
.code{
top: 18px;
background-image: url(../../../assets/img/login/code.png);
}
.ver-img{
position: absolute;
top: 1px;
right: 1px;
}
/deep/.el-form-item__error{
top: 105%;
left: auto;
right: 0;
color: #FFA94E;
}
.submit{
width: 100%;
height: 48px;
margin-top: 30px;
line-height: 48px;
padding: 0;
font-size: 20px;
background-color: $main-color;
border-radius: 4px;
border: 0;
4 years ago
}
}
}
}
.copyright{
padding: 18px 0;
font-size: 12px;
text-align: center;
background-color: #F3F6FA;
a{
color:#B1B4B8;
font-size: 12px;
&:hover{
opacity: .8;
4 years ago
}
4 years ago
}
}
.tips {
margin: 0 0 10px 5px;
font-size: 14px;
text-align: center;
color: #666;
}
@media (max-height: 680px) {
.wrap .login {
padding: 40px 0;
3 years ago
}
}
4 years ago
</style>