You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oaer/lib/components/index.ts

54 lines
1.2 KiB
TypeScript

1 month ago
/*
* index.ts
* Copyright (C) 2024 veypi <i@veypi.com>
* 2024-10-22 17:51
* Distributed under terms of the GPL license.
*/
import slide from './slide'
4 weeks ago
import { v } from '../v2dom'
import logic from '../logic'
4 weeks ago
import bus from '../bus'
export default class {
4 weeks ago
slide?: slide
frame: HTMLElement
constructor() {
this.frame = v('voa', this.gen_avatar())
}
mount(root: Element) {
root.appendChild(this.frame)
1 month ago
}
gen_avatar() {
let frame_user = v({
class: 'voa-on',
vclass: [() => logic.ready ? 'voa-scale-in' : 'voa-scale-off'],
4 weeks ago
children: [() => `<img src="${logic.user.icon || logic.token.refresh.icon}" />`],
1 month ago
onclick: () => {
4 weeks ago
logic.getDetailUser()
4 weeks ago
if (!this.slide) {
this.slide = new slide()
}
this.slide.show()
// logic.logout()
1 month ago
}
})
let frame_login = v({
class: 'voa-off voa-hover-line-b',
vclass: [() => !logic.ready ? 'voa-scale-in' : 'voa-scale-off'],
4 weeks ago
children: ['登录'],
1 month ago
onclick: () => {
console.log('click login')
4 weeks ago
bus.emit('login')
1 month ago
}
})
return () => {
if (logic.ready) {
return frame_user
} else {
return frame_login
}
1 month ago
}
}
}