|
@@ -84,96 +84,17 @@
|
|
|
}
|
|
|
}).catch(err=> {this.$toast.clear();});
|
|
|
},
|
|
|
- bindIfNessary() {
|
|
|
- let href = window.location.href;
|
|
|
- var requestUrl = "";
|
|
|
- if (this.isCorpWX) {//优先检查企业微信环境
|
|
|
- requestUrl = "/wxcorp/bindCorpWeiXin";
|
|
|
- } else if (this.isWX) {
|
|
|
- requestUrl = "/wechat/bindWeiXin";
|
|
|
- }
|
|
|
-
|
|
|
- if (requestUrl.length > 0) {
|
|
|
- // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
|
|
|
- //会自动跳转到首页
|
|
|
- // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
|
|
|
-
|
|
|
- if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
|
|
|
- var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
|
|
|
- var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
|
|
|
-
|
|
|
- // var urlLeft = url.substring(0, jingPosit);//url左侧部分
|
|
|
- var urlRight = url.substring(jingPosit, url.length); //url右侧部分
|
|
|
- console.log('urlRight=' + urlRight);
|
|
|
- urlRight = urlRight.substring(0, urlRight.indexOf('#/'));
|
|
|
- // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
|
|
|
- alert(url);
|
|
|
- //获取code
|
|
|
- var code = urlRight.substring('?code='.length,urlRight.indexOf('&state='));
|
|
|
- var passUserId = urlRight.substring(urlRight.indexOf('&state=')+'&state='.length);
|
|
|
- if (passUserId == '0') {
|
|
|
- //自动登录的回调
|
|
|
- this.$axios.get('/wxcorp/corpWeiXinLogin', {params:{code:code}})
|
|
|
- .then(res => {
|
|
|
- if (res == null) {
|
|
|
-
|
|
|
- } else if(res.errcode != null) {
|
|
|
- //报错了
|
|
|
- console.log(res.errmsg);
|
|
|
- } else {
|
|
|
- //获取openId
|
|
|
- if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
|
|
|
- || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
|
|
|
- localStorage.userInfo = JSON.stringify(res.data);
|
|
|
- console.log('登录成功');
|
|
|
- this.user = res.data;
|
|
|
- window.location.href = '/#/index';
|
|
|
- }
|
|
|
- }
|
|
|
- }).catch(err=> {
|
|
|
- alert('err=' + err);
|
|
|
- });
|
|
|
- } else {
|
|
|
- //绑定微信账号的回调
|
|
|
- //调用后台接口,注册用户
|
|
|
- this.$axios.get(requestUrl, {params:{code:code, userId: passUserId}})
|
|
|
- .then(res => {
|
|
|
- console.log(res);
|
|
|
- if (res == null) {
|
|
|
- this.$toast.fail('绑定失败');
|
|
|
- } else if(res.errcode != null) {
|
|
|
- //报错了
|
|
|
- console.log(res.errmsg);
|
|
|
- } else {
|
|
|
- //获取openId
|
|
|
- if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
|
|
|
- || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
|
|
|
- // localStorage.userInfo = JSON.stringify(res.data);
|
|
|
- localStorage.setItem('userInfo', JSON.stringify(res.data))
|
|
|
- console.log('绑定成功');
|
|
|
- this.user = res.data;
|
|
|
- window.location.href = '/#/my/center';
|
|
|
- }
|
|
|
- }
|
|
|
- }).catch(err=> {
|
|
|
- alert('err=' + err);
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+
|
|
|
tryAutoLogin() {
|
|
|
- var appId = "wx749c84daac654e1e";//车间生产管家公众号
|
|
|
- var url = "http://mobworktime.ttkuaiban.com/api/wechat/loginByWXCode";//车间生产管家公众号授权回调页面
|
|
|
- if (this.isCorpWX) {
|
|
|
- appId = "ww4e237fd6abb635af"; //企业微信第三方的SUIT ID
|
|
|
- url = "http://worktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
|
|
|
- }
|
|
|
+ // var appId = "wx749c84daac654e1e";//车间生产管家公众号
|
|
|
+ // var url = "http://mobworktime.ttkuaiban.com/api/wechat/loginByWXCode";//车间生产管家公众号授权回调页面
|
|
|
+ // if (this.isCorpWX) {
|
|
|
+ // appId = "wwf11426cf618e1703"; //企业微信第三方的SUIT ID
|
|
|
+ // url = "http://worktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
|
|
|
+ // }
|
|
|
|
|
|
- // var appId = "ww4e237fd6abb635af";//企业微信第三方的SUIT ID
|
|
|
- // var url = "http://worktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
|
|
|
+ var appId = "wwf11426cf618e1703";//私有化部署的企业CORPID
|
|
|
+ var url = "http://devworkshop.ttkuaiban.com/api/corpInsideWXAuth";//授权回调页面
|
|
|
var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
|
|
|
window.location.href = weixinUrl;
|
|
|
},
|
|
@@ -272,22 +193,16 @@
|
|
|
} else {
|
|
|
console.log('判断企业微信是否授权',this.isCorpWX || this.isWX)
|
|
|
if (this.isCorpWX || this.isWX) {
|
|
|
- //判断企业微信,是否存在授权
|
|
|
- if (href.includes("com/?code")) {
|
|
|
- this.bindIfNessary();
|
|
|
- } else {
|
|
|
- if (href.indexOf('hasTriedAutoLogin') == -1) {
|
|
|
- this.tryAutoLogin();
|
|
|
- } else if (href.indexOf("userId") > 0) {
|
|
|
- //后台经过验证后,重定向过来带上了userId
|
|
|
- var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
|
|
|
- if (loginUserId.includes('#/')) {
|
|
|
- loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
|
|
|
- }
|
|
|
- this.loginByUserId(loginUserId);
|
|
|
+ if (href.indexOf('hasTriedAutoLogin') == -1) {
|
|
|
+ this.tryAutoLogin();
|
|
|
+ } else if (href.indexOf("userId") > 0) {
|
|
|
+ //后台经过验证后,重定向过来带上了userId
|
|
|
+ var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
|
|
|
+ if (loginUserId.includes('#/')) {
|
|
|
+ loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
|
|
|
}
|
|
|
+ this.loginByUserId(loginUserId);
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
//检查环境,如果是钉钉有$CORPID$
|
|
|
if(href.indexOf("corpid") > 0) {
|