|
@@ -29,29 +29,45 @@ export default {
|
|
|
this.$emit('success', this.userInfo)
|
|
|
} else {
|
|
|
// 未登录
|
|
|
- this.twitterAuth()
|
|
|
+ let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/)
|
|
|
+ if (isiOS) {
|
|
|
+ this.twitterIosAuth()
|
|
|
+ } else {
|
|
|
+ this.twitterAndroidAuth()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
},
|
|
|
- async twitterAuth() {
|
|
|
- let win;
|
|
|
- let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/);
|
|
|
- if (isiOS) {
|
|
|
- win = window.open();
|
|
|
- win.opener = null;
|
|
|
- }
|
|
|
- // post
|
|
|
+ async twitterIosAuth() {
|
|
|
+ let win = window.open();
|
|
|
+ win.opener = null;
|
|
|
+ postRequest(`/denet/user/twitterRequestToken`, {
|
|
|
+ params: {
|
|
|
+ oauthCallback: `${jumpUrl}authlogin`,
|
|
|
+ },
|
|
|
+ }).then(({ code, data }) => {
|
|
|
+ if (code == 0) {
|
|
|
+ win.location.href = getOauthUrl(data.authToken);
|
|
|
+ // timer
|
|
|
+ this.timer = setInterval(() => {
|
|
|
+ if (win && win.closed) {
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.twitterLogin(data);
|
|
|
+ }
|
|
|
+ }, 500);
|
|
|
+ } else {
|
|
|
+ this.$emit('error')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async twitterAndroidAuth() {
|
|
|
postRequest(`/denet/user/twitterRequestToken`, {
|
|
|
params: {
|
|
|
oauthCallback: `${jumpUrl}authlogin`,
|
|
|
},
|
|
|
}).then(({ code, data }) => {
|
|
|
if (code == 0) {
|
|
|
- if (isiOS) {
|
|
|
- win.location.href = getOauthUrl(data.authToken);
|
|
|
- } else {
|
|
|
- win = window.open(getOauthUrl(data.authToken));
|
|
|
- }
|
|
|
-
|
|
|
+ let win = window.open(getOauthUrl(data.authToken));
|
|
|
// timer
|
|
|
this.timer = setInterval(() => {
|
|
|
if (win && win.closed) {
|