自动登录实现

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

@ -102,65 +102,6 @@ export default {
this.login(this.phoneNum, this.password); 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) { motion(e) {
Cookie.set('is_motion', e); Cookie.set('is_motion', e);
}, },

Loading…
Cancel
Save