|
@ -45,13 +45,9 @@
|
|
|
<div class="form-group">
|
|
|
<input class="form-control" type="text" maxlength="11" v-model="mobile" placeholder="请输入手机号码">
|
|
|
</div>
|
|
|
<div class="form-group">
|
|
|
<input class="form-control" type="text" v-model="imgcaptcha" placeholder="请输入图形验证码">
|
|
|
<a class="getCaptcha" :class="{'disabled': countdown}" @click="getCaptcha">{{infoText}}</a>
|
|
|
</div>
|
|
|
<div class="form-group">
|
|
|
<input class="form-control" type="text" v-model="captcha" placeholder="请输入短信验证码">
|
|
|
<a class="getCaptcha" :class="{'disabled': countdown}" @click="getCaptcha">{{infoText}}</a>
|
|
|
<a class="getCaptcha" v-text="codeMsg" :class="{\'disabled bgc-909090\':codeMsg!==\'获取验证码\'}" @click="sendMsg">获取验证码</a>
|
|
|
</div>
|
|
|
<button type="submit" class="btn btn-theme block full-width m-b" @click="login">登 录</button>
|
|
|
<a type="button" class="btn btn-default block full-width m-b" @click="toggleRegister">注 册</a>
|
|
@ -68,39 +64,39 @@
|
|
|
return {
|
|
|
type: 1, //记录选择的登录方式,1-手机号登录,2-验证码登录
|
|
|
account: '362321199703137824',
|
|
|
mobile: '',
|
|
|
mobile: '17805985317',
|
|
|
password: '11111111',
|
|
|
imgcaptcha: '',
|
|
|
captcha: '',
|
|
|
infoText: '获取验证码',
|
|
|
countdown: false, //是否在倒计时
|
|
|
codeType: 1,
|
|
|
idCardNo: "350526199501142015",
|
|
|
rPassword: 'a123123',
|
|
|
confirmPassword: "a123123",
|
|
|
captcha:'',
|
|
|
idCardNo: "",
|
|
|
rPassword: '',
|
|
|
confirmPassword: "",
|
|
|
toggle: true,
|
|
|
registerFlag: false,
|
|
|
maxLength: 18,
|
|
|
codeMsg:"获取验证码",
|
|
|
spaceTime:60,//验证码间隔时间
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
changeType: function(val) {
|
|
|
this.type = val;
|
|
|
},
|
|
|
getCaptcha: function() {
|
|
|
//先校验手机号码是否正确
|
|
|
var isMobile = isMobilePhone(this.mobile);
|
|
|
if(!isMobile) {
|
|
|
alert('请输入正确的手机号码!');
|
|
|
return false;
|
|
|
getCode: function(num){
|
|
|
var vm=this;
|
|
|
if(num<0){
|
|
|
vm.codeMsg="获取验证码";
|
|
|
}else{
|
|
|
setTimeout(function(){
|
|
|
num--;
|
|
|
vm.codeMsg="("+num+"s)重新获取";
|
|
|
vm.getCode(num);
|
|
|
},1000)
|
|
|
}
|
|
|
setTimer(this);
|
|
|
//发送请求
|
|
|
// sendToGetCaptcha(this);
|
|
|
},
|
|
|
login: function() {
|
|
|
var vm = this
|
|
|
if(this.type == 1) {
|
|
|
if(vm.type == 1) {
|
|
|
if(!vm.account) {
|
|
|
console.log("账号不能为空!");
|
|
|
return false;
|
|
@ -141,15 +137,111 @@
|
|
|
console.log("手机号不能为空!");
|
|
|
return false;
|
|
|
}
|
|
|
if(!vm.imgcaptcha) {
|
|
|
console.log("图形验证码不能为空!");
|
|
|
var isMobile = isCardNo(vm.mobile,2);
|
|
|
if(!isMobile) {
|
|
|
alert('请输入正确的手机号码!');
|
|
|
return false;
|
|
|
}
|
|
|
if(!vm.captcha) {
|
|
|
console.log("手机验证码不能为空!");
|
|
|
return false;
|
|
|
}
|
|
|
vm.verifyCodeExpire(2);
|
|
|
}
|
|
|
},
|
|
|
sendMsg:function(){
|
|
|
var vm=this;
|
|
|
var isMobile = isCardNo(vm.mobile,2);
|
|
|
if(!isMobile) {
|
|
|
alert('请输入正确的手机号码!');
|
|
|
return false;
|
|
|
}
|
|
|
if(vm.codeMsg==="获取验证码"){
|
|
|
vm.codeMsg="正在获取验证码";
|
|
|
}
|
|
|
vm.verifyCodeExpire(1);
|
|
|
},
|
|
|
verifyCodeExpire:function(num){//num:1表示验证短信发送间隔问题,2表示时效性
|
|
|
var vm=this;
|
|
|
loginAPI.verifyCodeExpire({
|
|
|
client_id: httpRequest.client_id,
|
|
|
username: vm.mobile
|
|
|
}).then(function(res){
|
|
|
console.log(res)
|
|
|
if(num===1){
|
|
|
if(res.nextRequestTime<=0) vm.verifyCode();//获取验证码
|
|
|
else{
|
|
|
console.log(vm.codeMsg || (vm.spaceTime+"秒内只能获取一次验证码"));
|
|
|
vm.codeMsg=vm.spaceTime+"秒内只能获取一次验证码";
|
|
|
}
|
|
|
}
|
|
|
if(num===2){
|
|
|
if(res.expiresIn<=0){
|
|
|
alert("验证码已失效,请重新获取验证码!");
|
|
|
}else{
|
|
|
var data = {
|
|
|
// grant_type: httpRequest.grant_type,
|
|
|
client_id: httpRequest.client_id,
|
|
|
username: vm.mobile,
|
|
|
verify_code: vm.captcha
|
|
|
}
|
|
|
loginAPI.accessToken(data).then(function(oauthInfo) {
|
|
|
sessionStorage.setItem("oauthInfo", JSON.stringify(oauthInfo));
|
|
|
var data1 = {
|
|
|
userName: oauthInfo.user,
|
|
|
accessToken: "token=" + oauthInfo.accessToken
|
|
|
}
|
|
|
loginAPI.getUserInfo(data1).then(function(res) {
|
|
|
console.log("登录成功");
|
|
|
loginedList = [res.telephone]
|
|
|
sessionStorage.setItem("loginedList", JSON.stringify(loginedList));
|
|
|
sessionStorage.setItem("userAgent", JSON.stringify(res));
|
|
|
vm.getJueSeData(res);
|
|
|
}),
|
|
|
function error(xhr, type, errorThrown) {
|
|
|
if(type == "timeout" || type == "abort" || type == "error") {
|
|
|
console.log("账号或密码错误");
|
|
|
}
|
|
|
}
|
|
|
}).catch(function(e) {
|
|
|
console.error&&console.error(e);
|
|
|
console.log("服务器繁忙,请稍后再试")
|
|
|
})
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}).catch(function(err){
|
|
|
console.log(err)
|
|
|
alert("获取短信验证码失败")
|
|
|
vm.codeMsg="获取验证码";
|
|
|
verifyCodeFlag=false;
|
|
|
})
|
|
|
},
|
|
|
verifyCode :function(){
|
|
|
var vm=this;
|
|
|
if(vm.codeMsg!=="获取验证码"&&vm.codeMsg!=="正在获取验证码"){
|
|
|
console.log(vm.codeMsg || (vm.spaceTime+"秒内只能获取一次验证码"));
|
|
|
vm.codeMsg="正在获取验证码";
|
|
|
return ;
|
|
|
}
|
|
|
if(vm.codeMsg==="获取验证码"){
|
|
|
vm.codeMsg="正在获取验证码";
|
|
|
}
|
|
|
var data = {
|
|
|
username:vm.mobile,
|
|
|
client_id: httpRequest.client_id,
|
|
|
}
|
|
|
loginAPI.verifyCode(data).then(function(res) {
|
|
|
if(res.expiresIn==600) vm.getCode(vm.spaceTime);
|
|
|
else{
|
|
|
vm.codeMsg="获取验证码";
|
|
|
console.log(res.errorMsg);
|
|
|
}
|
|
|
|
|
|
}).catch(function(err) {
|
|
|
console.error(err);
|
|
|
vm.codeMsg="获取验证码";
|
|
|
})
|
|
|
},
|
|
|
getJueSeData: function(userAgent) {
|
|
|
var vm = this;
|
|
@ -159,7 +251,11 @@
|
|
|
}).then(function(data) {
|
|
|
sessionStorage.setItem("roleList", JSON.stringify(data.detailModelList)); //缓存角色列表
|
|
|
// location.href = "../../../home/html/home.html"//跳转到主页面
|
|
|
location.href = "../../../page/mine/html/personal-info.html"
|
|
|
if(history.length>=2){
|
|
|
history.back();
|
|
|
}else{
|
|
|
location.href = "../../../page/mine/html/personal-info.html"
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
|
|
@ -196,24 +292,6 @@
|
|
|
}
|
|
|
})
|
|
|
|
|
|
//验证码定时
|
|
|
function setTimer(vm) {
|
|
|
var seconds = 59;
|
|
|
vm.countdown = true;
|
|
|
timer = setInterval(function() {
|
|
|
if(seconds == 0) {
|
|
|
clearInterval(timer);
|
|
|
timer = null;
|
|
|
seconds = 59;
|
|
|
vm.infoText = "获取验证码";
|
|
|
vm.countdown = false;
|
|
|
return;
|
|
|
}
|
|
|
seconds--;
|
|
|
vm.infoText = seconds + "s后重新获取";
|
|
|
}, 1000)
|
|
|
}
|
|
|
|
|
|
function isCardNo(card, codeType) {
|
|
|
var isidcard = false
|
|
|
if(codeType == 1) { // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
|
|
@ -234,68 +312,4 @@
|
|
|
return isidcard
|
|
|
}
|
|
|
|
|
|
function sendToGetCaptcha(vm) {
|
|
|
var url = "common/captcha",
|
|
|
params = {
|
|
|
mobile: vm.mobile,
|
|
|
type: 5,
|
|
|
captchaToken: 5
|
|
|
};
|
|
|
httpRequest.post(url, {
|
|
|
data: params
|
|
|
}).then(function(res) {
|
|
|
if(res.status == 200) {
|
|
|
tip('发送成功', 'add');
|
|
|
} else {
|
|
|
tip('获取验证码失败');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function getPublicKey(vm) {
|
|
|
var url = "login/public_key";
|
|
|
httpRequest.post(url).then(function(res) {
|
|
|
if(res.status) {
|
|
|
var mod = res.data.modulus;
|
|
|
var exp = res.data.exponent;
|
|
|
key = RSAUtils.getKeyPair(exp, "", mod);
|
|
|
if(key) {
|
|
|
encryedPwd = RSAUtils.encryStr(key, vm.password);
|
|
|
login({
|
|
|
mobile: vm.mobile,
|
|
|
password: encryedPwd,
|
|
|
platform: 4
|
|
|
})
|
|
|
} else {
|
|
|
tip("获取数据失败")
|
|
|
$submit.removeAttr('disabled')
|
|
|
}
|
|
|
} else {
|
|
|
tip(res.msg);
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
function login(data) {
|
|
|
httpRequest.post('login/doctor', {
|
|
|
data: data
|
|
|
}).then(function(res) {
|
|
|
if(res.status == 200) {
|
|
|
var docInfo = res.data;
|
|
|
localoginlStorage.setItem(httpRequest.agentName, JSON.stringify({
|
|
|
id: docInfo.id,
|
|
|
uid: docInfo.uid,
|
|
|
token: docInfo.token,
|
|
|
imei: localStorage.getItem('WLYY_IMEI'),
|
|
|
platform: 4
|
|
|
}));
|
|
|
//将用户的角色信息单独存储在localstorage中
|
|
|
localStorage.setItem("userRole", JSON.stringify(docInfo.userRole));
|
|
|
window.location.href = "../home/html/index.html";
|
|
|
} else {
|
|
|
tip(res.msg);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
})()
|