login.js
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {createLinkButton} from "../utils/common";
import base from './base';
export default class {
constructor(obj) {
this.env = obj.env;
this.url = obj.loginUrl;
}
auth() {
base.getUser().then(({uid}) => {
if (!uid) {
let list = document.querySelectorAll('.auth');
if (list.length) {
list.forEach((value) => {
value.onclick = (event) => {
event.preventDefault();
this.goLogin();
}
});
return true;
}
}
});
}
goLogin() {
if (this.env === 'miniprogram') {
wx.miniProgram.switchTab({url: this.url});
} else if(this.env === 'app'){
let loginButton = document.getElementById('yosdk-login');
if (!loginButton) {
loginButton = createLinkButton(this.url, 'yosdk-login');
}
loginButton.click();
} else {
window.location.href = this.url;
}
return false;
}
}