|
@@ -5,11 +5,12 @@ export default {
|
|
|
if (localStorage.getItem("openid") != 'undefined' && localStorage.getItem("openid") != null) {
|
|
|
return;
|
|
|
}
|
|
|
- var code = this.getUrlParam("code");
|
|
|
+
|
|
|
+ var code = getUrlParam("code");
|
|
|
console.log(code, 'code====++++')
|
|
|
if (code == 'undefined' || code == null || code == "") {
|
|
|
// alert("参数异常,请返回首页重试");
|
|
|
- this.urlredirect();
|
|
|
+ urlredirect();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -20,27 +21,28 @@ export default {
|
|
|
localStorage.setItem("openid", res.openId);
|
|
|
localStorage.setItem("headimgurl", res.headimgurl);
|
|
|
} else {
|
|
|
- this.urlredirect();
|
|
|
+ urlredirect();
|
|
|
}
|
|
|
},
|
|
|
+}
|
|
|
|
|
|
- async urlredirect() {
|
|
|
- const res = await getWxConfig({})
|
|
|
- const href = window.location.href
|
|
|
- window.location.href =
|
|
|
- `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.wxConfig.appId}&redirect_uri=${encodeURIComponent(href)}` + `&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`;
|
|
|
- },
|
|
|
+async function urlredirect() {
|
|
|
+ const res = await getWxConfig({})
|
|
|
+ const href = window.location.href
|
|
|
+ window.location.href =
|
|
|
+ `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.wxConfig.appId}&redirect_uri=${encodeURIComponent(href)}` + `&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`;
|
|
|
+}
|
|
|
|
|
|
- getUrlParam(name) {
|
|
|
- var vars = [],
|
|
|
- hash;
|
|
|
- var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
|
|
- for (var i = 0; i < hashes.length; i++) {
|
|
|
- hash = hashes[i].split('=');
|
|
|
- vars.push(hash[0]);
|
|
|
- vars[hash[0]] = hash[1];
|
|
|
- }
|
|
|
- return decodeURIComponent(vars[name]);
|
|
|
+function getUrlParam(name) {
|
|
|
+ var vars = [],
|
|
|
+ hash;
|
|
|
+ var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
|
|
+ for (var i = 0; i < hashes.length; i++) {
|
|
|
+ hash = hashes[i].split('=');
|
|
|
+ vars.push(hash[0]);
|
|
|
+ vars[hash[0]] = hash[1];
|
|
|
}
|
|
|
+ return decodeURIComponent(vars[name]);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
-}
|