feat: base

v3
veypi 4 weeks ago
parent 58f5d57b77
commit 713f352bc8

@ -39,7 +39,7 @@ export interface ListOpts {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<[models.App]>(`/app`, { json })
return webapi.Get<models.App[]>(`/app`, { json })
}
export interface AppUserGetOpts {
@ -81,7 +81,7 @@ export interface ResourceListQuery {
updated_at?: Date
}
export function ResourceList(app_id: string, query: ResourceListQuery) {
return webapi.Get<[models.Resource]>(`/app/${app_id}/resource`, { query })
return webapi.Get<models.Resource[]>(`/app/${app_id}/resource`, { query })
}
export interface ResourcePostOpts {

@ -10,18 +10,12 @@ import logic from '../logic'
export default v('voa-account', [
v('voa-account-header', [v('voa-ah-1', '我的账户'), v('voa-ah-2')]),
v('voa-account-body', [
// v('voa-ab-ico', [v('img', '', (d) => { d.setAttribute('src', cfg.user.icon) })]),
v('voa-ab-ico', [v({ typ: 'img', attrs: { 'src': () => `https://public.veypi.com/img/avatar/000${logic.user.id}.jpg`, test: () => logic.user.id } })]),
v('voa-ab-ico', [v({ typ: 'img', attrs: { 'src': () => `${logic.user.icon}` } })]),
v('voa-ab-info', [
v('voa-abi-1', [v('span', '昵称:'), v('span', () => logic.user.nickname)]),
v('voa-abi-2', [v('span', '账户:'), v('span', () => logic.user.username)]),
v('voa-abi-3', [v('span', '邮箱:'), v('span', () => logic.user.email)]),
v('voa-abi-4', [v('span', '手机:'), v('span', () => logic.user.phone)]),
v({
typ: 'input',
attrs: { 'type': 'number' },
vbind: [logic.user, 'id']
})
])
])
])

@ -7,9 +7,18 @@
import v from "./v2dom";
import logic from '../logic'
import api from "../api";
import proxy from "./proxy";
import * as typs from "../typs"
export default () => v({
export default () => {
let apps: typs.App[] = proxy.Watch([])
api.app.List({}).then(e => {
e[1]
apps.push(...e)
})
return v({
class: 'voa-apps',
children: [
v('voa-apps-header', [v('voa-apps-title', '我的应用')]),
@ -28,4 +37,5 @@ export default () => v({
})
])
]
})
})
}

@ -10,10 +10,9 @@ import v from './v2dom'
import logic from '../logic'
import bus from '../bus'
export default class {
slide: slide
slide?: slide
frame: HTMLElement
constructor() {
this.slide = new slide()
this.frame = v('voa', this.gen_avatar())
}
mount(root: Element) {
@ -23,8 +22,11 @@ export default class {
let frame_user = v({
class: 'voa-on',
vclass: [() => logic.ready ? 'voa-scale-in' : 'voa-scale-off'],
inner: `<img src="${logic.user.icon}" />`,
inner: () => `<img src="${logic.user.icon}" />`,
onclick: () => {
if (!this.slide) {
this.slide = new slide()
}
this.slide.show()
// logic.logout()
}

@ -38,6 +38,7 @@ export default class {
bus.emit('logout')
}
})
console.log(logic.user)
this.main = v({
class: 'voa-slide-main',
children: [

@ -48,6 +48,7 @@ export default <T>(opts: buildOpts<T> | string, inner?: string | computedFn | ch
let res = inner()
if (typeof res === 'string') {
dom.innerHTML = res
} else if (res === undefined) {
} else {
dom.innerHTML = ''
dom.appendChild(res)

@ -99,24 +99,22 @@ const logic = proxy.Watch({
oa_id: '',
app_id: '',
token: {
refresh: new Token('refresh'),
oa: new Token('oa'),
app: new Token('app'),
refresh: {} as Token,
oa: {} as Token,
app: {} as Token,
},
user: {
username: 'asd',
nickname: '',
email: '',
phone: '',
id: 1,
icon: 'https://public.veypi.com/img/avatar/0001.jpg'
},
user: {} as typs.User,
myapps: [
{ name: 'a' },
{ name: 'b' },
],
ready: false,
getDetailUser() {
api.user.Get(logic.token.oa.uid!).then((u) => {
Object.assign(logic.user, u)
})
},
init: () => {
return new Promise<Token>((resolve, reject) => {
api.info().then(e => {
@ -129,6 +127,7 @@ const logic = proxy.Watch({
logic.token.oa.update().then(e => { resolve(e.raw()) }).catch(() => reject)
})
)
logic.getDetailUser()
if (logic.app_id !== logic.oa_id) {
logic.token.app.update().then((e) => {
logic.ready = true
@ -176,4 +175,9 @@ bus.on('logout', () => {
logic.token.app.clear()
})
// load token from localStorage
logic.token.refresh = new Token('refresh')
logic.token.oa = new Token('oa')
logic.token.app = new Token('app')
export default logic

@ -9,7 +9,6 @@ import './assets/css/oaer.scss'
import bus from './bus'
import logic from './logic'
import ui from './components'
import * as typs from './typs'
import api from './api'
@ -17,6 +16,12 @@ export default new class {
private ui?: ui
constructor() {
}
local() {
return logic.user
}
access() {
return logic.token.app.access
}
init(host?: string, code?: string) {
if (host) {
logic.host = host
@ -24,17 +29,7 @@ export default new class {
if (code) {
logic.token.refresh.set(code)
}
return new Promise<typs.UserData>((resolve, reject) => {
logic.init().then((e) => {
api.user.Get(e.uid!).then((u) => {
resolve(Object.assign(u, { access: e.access! }))
}).catch((e) => {
reject(e)
})
}).catch((e) => {
reject(e)
})
})
return logic.init()
}
render_ui(domid = 'voa') {
if (!this.ui) {

Loading…
Cancel
Save