diff --git a/oaer/lib/api/app.ts b/oaer/lib/api/app.ts index 4112338..82e7dfb 100644 --- a/oaer/lib/api/app.ts +++ b/oaer/lib/api/app.ts @@ -39,7 +39,7 @@ export interface ListOpts { name?: string } export function List(json: ListOpts) { - return webapi.Get<[models.App]>(`/app`, { json }) + return webapi.Get(`/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(`/app/${app_id}/resource`, { query }) } export interface ResourcePostOpts { diff --git a/oaer/lib/components/account.ts b/oaer/lib/components/account.ts index 322c469..81b2bea 100644 --- a/oaer/lib/components/account.ts +++ b/oaer/lib/components/account.ts @@ -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'] - }) ]) ]) ]) diff --git a/oaer/lib/components/app.ts b/oaer/lib/components/app.ts index 2016cfa..ffffeb9 100644 --- a/oaer/lib/components/app.ts +++ b/oaer/lib/components/app.ts @@ -7,25 +7,35 @@ import v from "./v2dom"; import logic from '../logic' +import api from "../api"; +import proxy from "./proxy"; +import * as typs from "../typs" -export default () => v({ - class: 'voa-apps', - children: [ - v('voa-apps-header', [v('voa-apps-title', '我的应用')]), - v('voa-apps-body', [ - [logic.myapps, - (data) => v('voa-app-box', [v('span', () => data.name)])], - v('div', '222'), - [logic.myapps, - (data) => v('voa-app-box', () => data.name)], - v({ - typ: 'div', inner: 'add', vbind: [logic.myapps[0], 'name'], - onclick: () => { - logic.myapps.splice(0, 1) - logic.myapps.push({ name: new Date().toLocaleString() }) - } - }) - ]) - ] -}) +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', '我的应用')]), + v('voa-apps-body', [ + [logic.myapps, + (data) => v('voa-app-box', [v('span', () => data.name)])], + v('div', '222'), + [logic.myapps, + (data) => v('voa-app-box', () => data.name)], + v({ + typ: 'div', inner: 'add', vbind: [logic.myapps[0], 'name'], + onclick: () => { + logic.myapps.splice(0, 1) + logic.myapps.push({ name: new Date().toLocaleString() }) + } + }) + ]) + ] + }) +} diff --git a/oaer/lib/components/index.ts b/oaer/lib/components/index.ts index b37bfed..5c2fefb 100644 --- a/oaer/lib/components/index.ts +++ b/oaer/lib/components/index.ts @@ -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: ``, + inner: () => ``, onclick: () => { + if (!this.slide) { + this.slide = new slide() + } this.slide.show() // logic.logout() } diff --git a/oaer/lib/components/slide.ts b/oaer/lib/components/slide.ts index 35a1fe6..cbd5122 100644 --- a/oaer/lib/components/slide.ts +++ b/oaer/lib/components/slide.ts @@ -38,6 +38,7 @@ export default class { bus.emit('logout') } }) + console.log(logic.user) this.main = v({ class: 'voa-slide-main', children: [ diff --git a/oaer/lib/components/v2dom.ts b/oaer/lib/components/v2dom.ts index e5d957c..76de34d 100644 --- a/oaer/lib/components/v2dom.ts +++ b/oaer/lib/components/v2dom.ts @@ -48,6 +48,7 @@ export default (opts: buildOpts | 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) diff --git a/oaer/lib/logic.ts b/oaer/lib/logic.ts index 5b732cc..21fe887 100644 --- a/oaer/lib/logic.ts +++ b/oaer/lib/logic.ts @@ -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((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 diff --git a/oaer/lib/main.ts b/oaer/lib/main.ts index 1836b00..1aa741e 100644 --- a/oaer/lib/main.ts +++ b/oaer/lib/main.ts @@ -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((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) {