自动登录实现

master
unclekh 5 years ago
parent a970398378
commit 3a43e2e937
  1. 92
      src/pages/yyyflogin.vue
  2. 59
      src/views/login/signIn.vue

@ -9,7 +9,7 @@
import Cookie from '@/common/cookie';
import {FILE_URL} from '@/api/app';
import {signInYyyf} from '@/api/yyyf';
import {signUp,signIn} from '@/api/user';
import {signUp, signIn} from '@/api/user';
import {Loading} from 'element-ui';
export default {
@ -47,7 +47,7 @@
this.loading = Loading.service({
lock: true,
text: '初始化登录ing...',
background: 'rgba(204, 0, 0, 0.7)'
background: 'rgba(0,0,0,0.7)'
});
},
endLoading: function () { //使Element loading-close
@ -82,40 +82,80 @@
}
return params;
},
sign(params) {
signUp(params).then(res => {
// console.log(res.data)
if (res.data.code !== 200) {
this.$message.warning(res.data.msg);
}
});
},
login(num, pass) {
debugger;
signIn({
tel: num,
password: pass,
}).then(res => {
// console.log(res);
if (res.data.code === 200) {
//
// if( this.checked === true ){
// Cookie.set('phoneNum',num)
// Cookie.set('password',pass)
// }
this.loading = false;
//tokencookie
// Cookie.set('token', res.data.data.token);
localStorage.setItem('token', res.data.data.token);
//cookie
// Cookie.set('userData', res.data.data);
localStorage.setItem('userData', JSON.stringify(res.data.data));
// console.log(JSON.parse(localStorage.getItem('userData')));
// userIDcookie
// Cookie.set('userID', res.data.data.id);
localStorage.setItem('userID', res.data.data.id);
//
localStorage.setItem('invitationCode', res.data.data.invitationCode);
this.endLoading()
location.href = '/';
} else {
this.$message.warning(res.data.msg);
}
});
},
loginFromYyyf: function (params) {
signInYyyf(params).then(res1 => {
signInYyyf(params).then(res => {
debugger;
// console.log(res);
if (res1.data.code === 200) {
let status=res1.data.data.status;
if(status==1){
if (res.data.code === 200) {
let status = res.data.data.status;
if (status == 1) {
//tokencookie
// Cookie.set('token', res.data.data.token);
localStorage.setItem('yyyfToken', res1.data.data.yyyfUserToken);
localStorage.setItem('yyyfToken', res.data.data.yyyfUserToken);
let code=res1.data.data.code;
let code = res.data.data.code;
let tel = res.data.data.tel;
let password = res.data.data.password;
//
if(code!=undefined && code != ''){
signUp({
tel: res1.data.data.tel,
nickName: res1.data.data.nickName,
code: res1.data.data.code,
password: res1.data.data.password,
if (code != undefined && code != '') {
let signParams = {
tel: tel,
nickName: res.data.data.nickName,
code: res.data.data.code,
password: password,
internationalCode: null,
invitationCode: '',
}).then(res => {
// console.log(res.data)
if (res.data.code === 200) {
this.$router.replace('/signIn');
} else {
this.loading = false;
this.$message.warning(res.data.msg);
}
});
}
this.sign(signParams);
}
/*this.endLoading()
location.href = '/';*/
}else{
this.login(tel, password);
} else {
this.$message.warning({
message: res.data.data.msg,
onClose: function () {

@ -102,65 +102,6 @@ export default {
this.login(this.phoneNum, this.password);
}
},
login(num, pass) {
signIn({
tel: num,
password: pass,
}).then(res => {
// console.log(res);
if (res.data.code === 200) {
//
// if( this.checked === true ){
// Cookie.set('phoneNum',num)
// Cookie.set('password',pass)
// }
this.loading = false;
//tokencookie
// Cookie.set('token', res.data.data.token);
localStorage.setItem('token', res.data.data.token);
//cookie
// Cookie.set('userData', res.data.data);
localStorage.setItem('userData', JSON.stringify(res.data.data));
// console.log(JSON.parse(localStorage.getItem('userData')));
// userIDcookie
// Cookie.set('userID', res.data.data.id);
localStorage.setItem('userID', res.data.data.id);
//
localStorage.setItem('invitationCode', res.data.data.invitationCode);
getPayPassword().then(res => {
// console.log(res.data.data);
if (res.data.code === 200) {
// Cookie.set('is_pay', res.data.data);
localStorage.setItem('is_pay', res.data.data);
}
//
switch (this.backToUrl) {
case 'login':
window.location.href = '/personal';
break;
case '':
case 'footer':
window.location.href = '/';
break;
case undefined:
window.location.href = '/personal';
break;
default:
window.location.href = this.backToUrl;
break;
}
});
} else {
this.loading = false;
this.$message.warning(res.data.msg);
}
});
},
motion(e) {
Cookie.set('is_motion', e);
},

Loading…
Cancel
Save