717 lines
20 KiB
717 lines
20 KiB
<template> |
|
<div class="wrap"> |
|
<div class="login"> |
|
<div class="form"> |
|
<h6 class="title">欢迎使用请登录</h6> |
|
<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="form" style="margin-top: 20px"> |
|
<!-- 账号 --> |
|
<div v-show="!verCodeLogin" class="items"> |
|
<el-form-item class="flex-1" prop="account"> |
|
<label class="label account"></label> |
|
<el-input v-model.trim="form.account" :placeholder="'请输入账号' + (!form.distinguish ? '/手机号' : '')" |
|
@keyup.enter.native="submit"></el-input> |
|
</el-form-item> |
|
</div> |
|
<template v-if="verCodeLogin"> |
|
<el-form-item prop="account"> |
|
<label class="label account"></label> |
|
<el-input v-model.trim="form.account" placeholder="请输入手机号/邮箱" @keyup.enter.native="submit"></el-input> |
|
</el-form-item> |
|
<el-form-item prop="code"> |
|
<label class="label code"></label> |
|
<div class="ver-code"> |
|
<el-input v-model="form.code" placeholder="请输入验证码" maxlength="6" |
|
@keyup.enter.native="submit"></el-input> |
|
<el-button type="text" @click="sendPhoneCodeLogin" :disabled="phoneDisabledLogin">{{ phoneBtnTextLogin |
|
}} |
|
</el-button> |
|
</div> |
|
</el-form-item> |
|
</template> |
|
<template v-else> |
|
<el-form-item prop="password"> |
|
<label class="password label"></label> |
|
<el-input type="password" placeholder="请输入密码" v-model.trim="form.password" @keyup.enter.native="submit"> |
|
</el-input> |
|
</el-form-item> |
|
<el-form-item prop="code"> |
|
<label class="label code"></label> |
|
<el-input placeholder="请输入验证码" v-model.trim="form.code" @keyup.enter.native="submit"> |
|
</el-input> |
|
<img @click="getVerImg" :src="verificationIMG" class="ver-img" alt=""> |
|
</el-form-item> |
|
</template> |
|
<div v-if="!form.distinguish" class="bottom"> |
|
<el-link :underline="false" type="primary" @click="switchType">{{ verCodeLogin ? '密码' : '验证码' }}登录</el-link> |
|
<!-- <el-link :underline="false" type="primary" @click="toAccount">没有账号,点击申请</el-link> --> |
|
</div> |
|
<el-button class="submit" type="primary" @click="submit">登录</el-button> |
|
</el-form> |
|
</div> |
|
</div> |
|
|
|
<el-dialog title="绑定手机号" :visible.sync="phoneVisible" :close-on-click-modal="false" width="576px"> |
|
<p class="tips">依据国家政策法规,需绑定手机号进行网络实名才可登录使用本平台</p> |
|
<el-form label-width="60px"> |
|
<el-form-item label="手机号"> |
|
<el-input placeholder="请输入手机号" v-model="phone" maxlength="11" @change="phoneChange"></el-input> |
|
</el-form-item> |
|
<el-form-item label="验证码"> |
|
<div class="ver-code"> |
|
<el-input v-model="phoneCode" placeholder="请输入验证码" maxlength="6"></el-input> |
|
<el-button style="top: 1px" type="text" @click="sendPhoneCode(1)" |
|
:disabled="binding === '' || 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> |
|
<el-dialog title="请选择您要登录的用户" :visible.sync="userVisible" :close-on-click-modal="false" custom-class="user-dia" |
|
width="500px"> |
|
<p class="tips">该手机号已绑定以下用户信息</p> |
|
<ul class="users"> |
|
<li :class="{ isEnable: !user.isEnable }" v-for="(user, i) in users" :key="i" @click="chooseUser(user)"> |
|
<span>{{ user.schoolName }},{{ user.userName }},{{ user.workNumber }}{{ user.isEnable ? '' : '(已禁用)' }}</span> |
|
<i class="el-icon-right"></i> |
|
</li> |
|
</ul> |
|
</el-dialog> |
|
<el-dialog :visible.sync="infoVisible" :close-on-click-modal="false" :show-close="false" custom-class="info-dia" |
|
width="400px"> |
|
<div class="info-header"> |
|
<i class="el-icon-warning"></i> |
|
提示 |
|
</div> |
|
<div class="info-wrap"> |
|
<p class="tips">该手机号已与以下用户绑定</p> |
|
<ul class="users"> |
|
<li v-for="(user, i) in infos" :key="i"> |
|
<span>{{ user.userName }}({{ user.schoolName }})</span> |
|
</li> |
|
</ul> |
|
<div class="info-footer"> |
|
<el-button size="small" type="primary" @click="bindPhone">是本人,继续绑定</el-button> |
|
<el-button class="unbind" size="small" @click="unbindPhone">不是本人,解绑以上用户并绑定新用户</el-button> |
|
</div> |
|
</div> |
|
</el-dialog> |
|
|
|
<div class="footer"> |
|
<div class="copyright"> |
|
<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20072679号</a> |
|
</div> |
|
</div> |
|
</div> |
|
</template> |
|
|
|
<script> |
|
const schoolIdKey = 'dataSchoolId' |
|
import { mapMutations, mapActions } from 'vuex' |
|
import vHead from '@/layouts/header' |
|
import util from '@/libs/util' |
|
import Setting from '@/setting' |
|
import vFooter from '@/layouts/footer' |
|
export default { |
|
data: function () { |
|
return { |
|
tabList: [ |
|
{ |
|
id: 0, |
|
label: '学生/老师登录' |
|
}, { |
|
id: 1, |
|
label: '学校管理员登录' |
|
} |
|
], |
|
verificationIMG: '', |
|
schoolList: [], |
|
form: { |
|
account: '', // 手机号验证码模式用这个字段 |
|
password: '', |
|
code: '', // 验证码 |
|
random: '', // 随机数 |
|
platform: Setting.platformId, |
|
distinguish: 0, |
|
}, |
|
rules: { |
|
account: [{ required: true, message: "请输入账号", trigger: "blur" }], |
|
password: [{ required: true, message: "请输入密码", trigger: "blur" }], |
|
code: [{ required: true, message: "请输入验证码", trigger: "blur" }] |
|
}, |
|
verCodeLogin: false, |
|
phoneDisabledLogin: false, |
|
phoneTimerLogin: null, |
|
phoneBtnTextLogin: '发送验证码', |
|
|
|
token: '', |
|
phoneVisible: false, |
|
phone: '', |
|
phoneCode: '', |
|
phoneDisabled: false, |
|
phoneTimer: null, |
|
phoneOpener: '', |
|
phoneBtnText: '发送验证码', |
|
userVisible: false, |
|
users: [], |
|
accountIds: [], |
|
binding: '', |
|
infoVisible: false, |
|
infos: [] |
|
}; |
|
}, |
|
components: { vHead, vFooter }, |
|
mounted () { |
|
this.getVerImg() |
|
}, |
|
methods: { |
|
...mapMutations("user", [ |
|
'SET_CUSTOMERNAME', 'SET_CUSTOMER', 'SET_INFO' |
|
]), |
|
...mapActions('user', [ |
|
'login', 'setCustomer' |
|
]), |
|
// 重置验证规则 |
|
handleRule () { |
|
this.rules.account[0].message = this.verCodeLogin ? |
|
'请输入手机号/邮箱' : |
|
this.form.distinguish ? '请输入账号' : '请输入账号/手机号' |
|
}, |
|
// 切换标签 |
|
typeClick (tab) { |
|
const { id } = tab |
|
const form = this.form |
|
// 切换了后,全部字段重置 |
|
this.form = { |
|
schoolId: form.schoolId, |
|
workNumber: '', |
|
account: '', |
|
password: '', |
|
code: '', |
|
random: form.random, |
|
distinguish: id, |
|
type: 2, |
|
platform: form.platform |
|
} |
|
if (id) this.verCodeLogin = false |
|
this.$refs.form.clearValidate() |
|
this.handleRule() |
|
}, |
|
// 选择用户回调 |
|
chooseUser (user) { |
|
user.isEnable && this.$post(`${this.api.getToken}?id=${user.id}`).then(({ data }) => { |
|
this.token = data.token |
|
this.setLogin() |
|
}).catch(res => { }) |
|
}, |
|
// 处理登录成功 |
|
setLogin () { |
|
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 |
|
}) |
|
window.opener && window.opener.location.reload() // 刷新官网 |
|
util.local.set(Setting.storeKey, this.$store.state) |
|
}).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 => { }) |
|
util.successMsg('登录成功') |
|
this.$router.replace('/index') |
|
}, |
|
submit () { |
|
this.$refs.form.validate(valid => { |
|
if (valid) { |
|
const form = JSON.parse(JSON.stringify(this.form)) |
|
if (this.verCodeLogin) form.distinguish = 2 |
|
this.$post(this.api.logins, form).then(({ status, data, message }) => { |
|
// 未绑定手机号,则弹框去绑定 |
|
if (status == 30001) { |
|
this.phoneVisible = true |
|
this.getVerImg() |
|
form.code = '' |
|
} else if (status == 200) { |
|
const accounts = data.userAccounts |
|
// 如果返回的是数组,则弹框给用户选择登录哪个用户,否则,直接登录 |
|
if (accounts instanceof Array) { |
|
this.users = accounts |
|
this.userVisible = true |
|
} else { |
|
this.token = data.token |
|
this.setLogin() |
|
} |
|
} else { |
|
form.code = '' |
|
util.errorMsg(message) |
|
} |
|
}).catch(res => { |
|
this.getVerImg() |
|
form.code = '' |
|
}) |
|
} |
|
}) |
|
}, |
|
getVerImg () { |
|
this.form.random = Math.floor(Math.random() * 999999999) |
|
this.verificationIMG = this.api.verification + '?random=' + `${this.form.random}` |
|
}, |
|
|
|
// 验证手机号 |
|
verifyPhone (phone) { |
|
if (!phone) { |
|
this.$message.error("请输入手机号") |
|
return false |
|
} |
|
if (!/^1[3456789]\d{9}$/.test(phone) && !/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(phone)) { |
|
this.$message.error("请输入正确的手机号/邮箱") |
|
return false |
|
} |
|
return true |
|
}, |
|
|
|
// 账号申请 |
|
switchType () { |
|
this.verCodeLogin = !this.verCodeLogin |
|
this.$refs.form.clearValidate() |
|
this.handleRule() |
|
}, |
|
// 账号申请 |
|
toAccount () { |
|
this.accountVisible = true |
|
}, |
|
|
|
// 验证码倒计时 |
|
phoneCountdownLogin () { |
|
let count = 60 |
|
if (!this.phoneTimerLogin) { |
|
this.phoneDisabledLogin = true |
|
this.phoneTimerLogin = setInterval(() => { |
|
if (count > 0) { |
|
count-- |
|
this.phoneBtnTextLogin = `${count}秒后重试` |
|
} else { |
|
this.phoneDisabledLogin = false |
|
clearInterval(this.phoneTimerLogin) |
|
this.phoneTimerLogin = null |
|
this.phoneBtnTextLogin = `发送验证码` |
|
} |
|
}, 1000) |
|
} |
|
}, |
|
// 发送验证码 |
|
sendPhoneCodeLogin () { |
|
const phone = this.form.account |
|
if (!this.verifyPhone(phone)) return false |
|
this.$post(`${this.api.sendPhoneVerificationCode}?phoneOrEmail=${phone}&loginOrBind=0&platform=${Setting.platformId}`).then(({ message }) => { |
|
util.successMsg(message) |
|
this.phoneCountdownLogin() |
|
}).catch(res => { }) |
|
}, |
|
// 继续绑定 |
|
bindPhone () { |
|
this.infoVisible = false |
|
this.binding = true |
|
this.sendPhoneCode(1) |
|
}, |
|
// 解除绑定 |
|
unbindPhone () { |
|
this.infoVisible = false |
|
this.binding = false |
|
this.sendPhoneCode(0) |
|
}, |
|
// 手机号失去焦点回调 |
|
phoneChange () { |
|
this.$post(`${this.api.getOtherAccountByPhone}?phone=${this.phone}&platform=${Setting.platformId}`).then(({ userAccounts }) => { |
|
const list = userAccounts |
|
if (list) { |
|
list.map(e => { |
|
const { userName } = e |
|
if (userName.length > 1) e.userName = userName[0] + '*' + userName.substring(2) |
|
}) |
|
this.infos = list |
|
this.accountIds = list.map(e => e.id) |
|
this.infoVisible = true |
|
} else { |
|
this.binding = true |
|
} |
|
}).catch(res => { }) |
|
}, |
|
|
|
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 (bind) { |
|
const { phone } = this |
|
if (!this.verifyPhone(phone)) return false |
|
// 不解绑发送验证码 |
|
if (bind) { |
|
this.$post(this.api.sendPhoneOrEmailCode, { |
|
platform: Setting.platformId, |
|
phone, |
|
types: 2 |
|
}).then(({ message }) => { |
|
if (message.opener) { |
|
this.phoneCountdown() |
|
this.phoneOpener = message.opener |
|
} else { |
|
util.errorMsg(message) |
|
} |
|
}).catch(res => { }) |
|
} else { |
|
this.$post(`${this.api.sendPhoneVerificationCode}?phoneOrEmail=${phone}&loginOrBind=1&platform=${Setting.platformId}`).then(({ message }) => { |
|
util.successMsg(message) |
|
this.phoneCountdown() |
|
}).catch(res => { }) |
|
} |
|
}, |
|
// 解绑 |
|
unbind () { |
|
const { password, platform, schoolId, type, workNumber } = this.form |
|
this.$post(this.api.unbindAccounts, { |
|
accountIds: this.accountIds, |
|
code: this.phoneCode, |
|
password, |
|
phone: this.phone, |
|
platform, |
|
schoolId, |
|
type, |
|
workNumber, |
|
}).then(({ data }) => { |
|
this.token = data.token |
|
this.setLogin() |
|
}).catch(res => { }) |
|
}, |
|
// 绑定手机号 |
|
phoneSubmit () { |
|
const { phone, phoneCode } = this |
|
if (!this.verifyPhone(phone)) return false |
|
if (!phoneCode) return util.warningMsg('请输入验证码') |
|
const { account, schoolId } = this.form |
|
if (this.binding) { |
|
this.$post(this.api.bindPhoneOrEmail, { |
|
mark: 2, |
|
phone, |
|
types: 2, |
|
code: phoneCode, |
|
opener: this.phoneOpener, |
|
platform: Setting.platformId, |
|
account, |
|
schoolId |
|
}).then(({ token }) => { |
|
this.token = token |
|
this.setLogin() |
|
}).catch(res => { }) |
|
} else { |
|
this.unbind() |
|
} |
|
} |
|
}, |
|
}; |
|
</script> |
|
|
|
<style scoped lang="scss"> |
|
.wrap { |
|
min-height: 100%; |
|
background-color: #f3f6fa; |
|
} |
|
|
|
.ver-code { |
|
position: relative; |
|
|
|
.el-button { |
|
position: absolute; |
|
top: 10px; |
|
right: 10px; |
|
} |
|
} |
|
|
|
.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; |
|
|
|
.tab { |
|
display: flex; |
|
justify-content: space-around; |
|
align-items: center; |
|
margin-bottom: 24px; |
|
border-bottom: 2px solid #e1e6f2; |
|
|
|
li { |
|
padding: 18px 0; |
|
margin-bottom: -1px; |
|
font-size: 16px; |
|
color: #555; |
|
cursor: pointer; |
|
border-bottom: 4px solid transparent; |
|
|
|
&:last-child { |
|
margin-right: 0; |
|
} |
|
|
|
&.active { |
|
color: $main-color; |
|
border-bottom-color: $main-color; |
|
} |
|
} |
|
} |
|
|
|
.items { |
|
display: flex; |
|
align-items: center; |
|
} |
|
|
|
.form { |
|
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; |
|
} |
|
} |
|
|
|
/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; |
|
} |
|
|
|
.bottom { |
|
display: flex; |
|
justify-content: space-between; |
|
} |
|
|
|
|
|
.el-select { |
|
width: 100%; |
|
} |
|
|
|
.label { |
|
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; |
|
} |
|
|
|
.school { |
|
background-image: url(../../../assets/img/login/school.png); |
|
} |
|
|
|
.workNumber { |
|
width: 17px; |
|
background-image: url(../../../assets/img/login/workNumber.png); |
|
} |
|
|
|
.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; |
|
} |
|
} |
|
|
|
.copyright { |
|
padding: 18px 0; |
|
font-size: 12px; |
|
text-align: center; |
|
background-color: #f3f6fa; |
|
|
|
a { |
|
color: #b1b4b8; |
|
font-size: 12px; |
|
|
|
&:hover { |
|
opacity: 0.8; |
|
} |
|
} |
|
} |
|
|
|
.tips { |
|
margin: 0 0 10px 5px; |
|
font-size: 14px; |
|
text-align: center; |
|
color: #666; |
|
} |
|
|
|
/deep/.user-dia { |
|
.tips { |
|
margin-bottom: 20px; |
|
text-align: center; |
|
color: #666; |
|
} |
|
|
|
.users { |
|
li { |
|
display: flex; |
|
justify-content: space-between; |
|
align-items: center; |
|
padding: 0 15px; |
|
margin-bottom: 10px; |
|
line-height: 40px; |
|
font-size: 14px; |
|
background-color: #ebeef5; |
|
cursor: pointer; |
|
|
|
&.isEnable { |
|
color: #c0c4cc; |
|
background-color: #f5f7fa; |
|
cursor: not-allowed; |
|
} |
|
|
|
&:last-child { |
|
margin-bottom: 0; |
|
} |
|
|
|
&:hover { |
|
background-color: #d3e0ff; |
|
} |
|
|
|
i { |
|
font-size: 16px; |
|
} |
|
} |
|
} |
|
} |
|
|
|
/deep/.info-dia { |
|
.el-dialog__header { |
|
border-bottom: 0; |
|
} |
|
|
|
.info-header { |
|
position: absolute; |
|
top: 20px; |
|
display: flex; |
|
align-items: center; |
|
font-size: 16px; |
|
color: #333; |
|
} |
|
|
|
.el-icon-warning { |
|
margin-right: 10px; |
|
color: #e6a23c; |
|
font-size: 24px; |
|
} |
|
|
|
.info-wrap { |
|
padding: 10px 33px; |
|
} |
|
|
|
.users { |
|
max-height: 125px; |
|
margin-top: 20px; |
|
overflow: auto; |
|
|
|
li { |
|
margin: 5px; |
|
font-size: 14px; |
|
color: #333; |
|
} |
|
} |
|
|
|
.info-footer { |
|
display: flex; |
|
justify-content: space-between; |
|
// align-items: center; |
|
margin-top: 20px; |
|
} |
|
|
|
.el-button { |
|
width: 142px; |
|
} |
|
|
|
.unbind { |
|
white-space: normal; |
|
line-height: 1.6; |
|
} |
|
} |
|
|
|
@media (max-height: 680px) { |
|
.wrap .login { |
|
padding: 40px 0; |
|
} |
|
} |
|
</style> |