feat: base

v3
veypi 4 weeks ago
parent 58f5d57b77
commit 713f352bc8

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

@ -10,18 +10,12 @@ import logic from '../logic'
export default v('voa-account', [ export default v('voa-account', [
v('voa-account-header', [v('voa-ah-1', '我的账户'), v('voa-ah-2')]), v('voa-account-header', [v('voa-ah-1', '我的账户'), v('voa-ah-2')]),
v('voa-account-body', [ 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': () => `${logic.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-info', [ v('voa-ab-info', [
v('voa-abi-1', [v('span', '昵称:'), v('span', () => logic.user.nickname)]), 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-2', [v('span', '账户:'), v('span', () => logic.user.username)]),
v('voa-abi-3', [v('span', '邮箱:'), v('span', () => logic.user.email)]), v('voa-abi-3', [v('span', '邮箱:'), v('span', () => logic.user.email)]),
v('voa-abi-4', [v('span', '手机:'), v('span', () => logic.user.phone)]), 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 v from "./v2dom";
import logic from '../logic' 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', class: 'voa-apps',
children: [ children: [
v('voa-apps-header', [v('voa-apps-title', '我的应用')]), 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 logic from '../logic'
import bus from '../bus' import bus from '../bus'
export default class { export default class {
slide: slide slide?: slide
frame: HTMLElement frame: HTMLElement
constructor() { constructor() {
this.slide = new slide()
this.frame = v('voa', this.gen_avatar()) this.frame = v('voa', this.gen_avatar())
} }
mount(root: Element) { mount(root: Element) {
@ -23,8 +22,11 @@ export default class {
let frame_user = v({ let frame_user = v({
class: 'voa-on', class: 'voa-on',
vclass: [() => logic.ready ? 'voa-scale-in' : 'voa-scale-off'], vclass: [() => logic.ready ? 'voa-scale-in' : 'voa-scale-off'],
inner: `<img src="${logic.user.icon}" />`, inner: () => `<img src="${logic.user.icon}" />`,
onclick: () => { onclick: () => {
if (!this.slide) {
this.slide = new slide()
}
this.slide.show() this.slide.show()
// logic.logout() // logic.logout()
} }

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

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

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

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

Loading…
Cancel
Save