提交 7b6aa552 编写于 作者: laizhilong's avatar laizhilong

授权成功后将信息存到本地localStorage

上级 3ce4a011
......@@ -27,6 +27,12 @@
success: function (data) {
// console.log(JSON.stringify(data));
if (data) {
if (data.openid) {
localStorage.setItem('openid', data.openid);
}
if (data.nickname) {
localStorage.setItem('nickname', data.nickname);
}
if (data.token) {
localStorage.setItem('token', data.token);
}
......
......@@ -27,6 +27,12 @@
success: function (data) {
// console.log(JSON.stringify(data));
if (data) {
if (data.openid) {
localStorage.setItem('openid', data.openid);
}
if (data.nickname) {
localStorage.setItem('nickname', data.nickname);
}
if (data.token) {
localStorage.setItem('token', data.token);
}
......
......@@ -27,6 +27,12 @@
success: function (data) {
// console.log(JSON.stringify(data));
if (data) {
if (data.openid) {
localStorage.setItem('openid', data.openid);
}
if (data.nickname) {
localStorage.setItem('nickname', data.nickname);
}
if (data.token) {
localStorage.setItem('token', data.token);
}
......
......@@ -156,8 +156,13 @@
this.goLogin();
}
else {
// 根据code获取钉钉用户信息
this.getDingtalkUserInfoByCode(this.code);
// 从local中获取该用户的openid和nickname
if (localStorage.getItem("openid")!="") {
this.openid = localStorage.getItem("openid");
}
if (localStorage.getItem("nickname")) {
this.nickname = localStorage.getItem("nickname");
}
}
}
......@@ -194,44 +199,7 @@
return null; //返回参数值
}
/**
* 根据code获取钉钉用户信息
*/
private getDingtalkUserInfoByCode(code: any) {
var param: any = {};
param.code = code;
const post: Promise<any> = this.$http.post('/uaa/getDingtalkUserInfoByCode', param, true);
post.then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
if (data && data.openid) {
this.openid = data.openid;
this.nickname = data.nickname;
} else {
this.$Message.error({
content: "获取钉钉用户信息失败,请重新授权",
duration: 3,
closable: true
});
}
}
}).catch((e: any) => {
const data = e.data;
if (data && data.message) {
this.$Message.error({
content: data.message,
duration: 3,
closable: true
});
} else {
this.$Message.error({
content: "获取钉钉用户信息失败,请重新授权",
duration: 3,
closable: true
});
}
});
}
/**
......
......@@ -154,15 +154,19 @@
if (!this.state) {
this.state = this.getUrlParam('state');
}
// alert("code:" + this.wechatCode + "\nstate:" + this.wechatState);
// 获取失败,回到登录页
if (!this.code || !this.state) {
this.$message.error("微信授权,获取code失败");
this.goLogin();
}
else {
// 根据code获取QQ用户信息
this.getQQUserInfoByCode(this.code);
// 从local中获取该用户的openid和nickname
if (localStorage.getItem("openid")!="") {
this.openid = localStorage.getItem("openid");
}
if (localStorage.getItem("nickname")) {
this.nickname = localStorage.getItem("nickname");
}
}
}
......@@ -198,45 +202,6 @@
return null; //返回参数值
}
/**
* 根据code获取微信用户信息
*/
private getQQUserInfoByCode(code: any) {
var param: any = {};
param.code = code;
const post: Promise<any> = this.$http.post('/uaa/getQQUserInfoByCode', param, true);
post.then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
if (data && data.openid) {
this.openid = data.openid;
this.nickname = data.nickname;
} else {
this.$Message.error({
content: "获取QQ用户信息失败,请重新授权",
duration: 3,
closable: true
});
}
}
}).catch((e: any) => {
const data = e.data;
if (data && data.message) {
this.$Message.error({
content: data.message,
duration: 3,
closable: true
});
} else {
this.$Message.error({
content: "获取QQ用户信息失败,请重新授权",
duration: 3,
closable: true
});
}
});
}
/**
* 注册处理
......
......@@ -158,8 +158,13 @@
this.goLogin();
}
else {
// 根据code获取微信用户信息
this.getWechatUserInfoByCode(this.code);
// 从local中获取该用户的openid和nickname
if (localStorage.getItem("openid")!="") {
this.openid = localStorage.getItem("openid");
}
if (localStorage.getItem("nickname")) {
this.nickname = localStorage.getItem("nickname");
}
}
}
......@@ -195,46 +200,6 @@
return null; //返回参数值
}
/**
* 根据code获取微信用户信息
*/
private getWechatUserInfoByCode(code: any) {
var param: any = {};
param.code = code;
const post: Promise<any> = this.$http.post('/uaa/getWechatUserInfoByCode', param, true);
post.then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
if (data && data.openid) {
this.openid = data.openid;
this.nickname = data.nickname;
} else {
this.$Message.error({
content: "获取微信用户信息失败,请重新授权",
duration: 3,
closable: true
});
}
}
}).catch((e: any) => {
const data = e.data;
if (data && data.message) {
this.$Message.error({
content: data.message,
duration: 3,
closable: true
});
} else {
this.$Message.error({
content: "获取微信用户信息失败,请重新授权",
duration: 3,
closable: true
});
}
});
}
/**
* 注册处理
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册