auth-component.js
751 Bytes
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
export default {
name: 'AuthComponent',
props: {
tag: String,
requiredAuth: {
type: Boolean,
default: true
}
},
methods: {
async onClick(e) {
if (e.timeStamp - this._lastTime < 800) {
return;
}
this._lastTime = e.timeStamp;
if (this.requiredAuth) {
const user = await this.$sdk.getUser();
if (user && user.uid) {
this.$emit('click', {uid: user.uid});
} else {
this.$emit('cancel');
this.$sdk.goLogin();
}
} else {
return this.$emit('click');
}
}
},
render(h) {
return h(this.tag || 'div', {
on: {
click: this.onClick.bind(this)
}
}, this.$slots.default);
}
};