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