From 11521b4b1c379bab7a103d2c395994334c525f43 Mon Sep 17 00:00:00 2001 From: veypi Date: Thu, 7 Nov 2024 17:38:49 +0800 Subject: [PATCH] feat: user --- oaweb/composables/api/token.ts | 6 ++- oaweb/composables/api/webapi.ts | 5 +- oaweb/pages/login.vue | 53 ++++++++++++-------- oaweb/pages/user.vue | 85 +++++++++++++++++++++++++++++++-- 4 files changed, 123 insertions(+), 26 deletions(-) diff --git a/oaweb/composables/api/token.ts b/oaweb/composables/api/token.ts index 9c6c632..4c56b14 100644 --- a/oaweb/composables/api/token.ts +++ b/oaweb/composables/api/token.ts @@ -15,14 +15,15 @@ export function TokenSalt(json: TokenSaltOpts) { return webapi.Post<{ id: string, salt: string }>(`/token/salt`, { json }) } export interface PostOpts { - user_id: string + refresh?: string + typ?: 'app' | 'ufs' + user_id?: string salt?: string code?: string app_id?: string expired_at?: Date over_perm?: string device?: string - refresh?: string } // keep @@ -48,6 +49,7 @@ export function Delete(token_id: string) { export interface ListOpts { user_id: string app_id: string + limit: number } export function List(json: ListOpts) { return webapi.Get(`/token`, { json }) diff --git a/oaweb/composables/api/webapi.ts b/oaweb/composables/api/webapi.ts index a68a6a2..d0e5a8e 100644 --- a/oaweb/composables/api/webapi.ts +++ b/oaweb/composables/api/webapi.ts @@ -149,7 +149,10 @@ interface data { function transData(d: data) { - let opts = { params: d.query, data: {}, headers: {} as any } + let opts = { headers: {} } as any + if (d.query) { + opts.params = d.query + } if (d.form) { opts.data = d.form opts.headers['content-type'] = 'application/x-www-form-urlencoded' diff --git a/oaweb/pages/login.vue b/oaweb/pages/login.vue index 61b2ffc..30f444b 100644 --- a/oaweb/pages/login.vue +++ b/oaweb/pages/login.vue @@ -147,9 +147,33 @@ definePageMeta({ const route = useRoute() const isValid = ref(oaer.isValid()) +const uuid = ref(route.query.uuid as string) const app = ref({} as models.App) const app_perm = ref<{ [key: string]: [boolean, string, number] }>({ 'fs': [true, '/', 4], 'app': [true, '', 1], 'user': [true, '', 1] }) +const auto_redirect = () => { + if (isValid.value) { + if (uuid.value) { + api.app.Get(uuid.value).then(e => { + app.value = e + console.log(oaer.local()) + api.token.List({ limit: 1, app_id: uuid.value, user_id: oaer.local().id }).then(e => { + console.log(e) + }) + }).catch(e => { + if (e.code === 40401) { + msg.Warn('参数错误: 该应用不存在') + uuid.value = '' + redirect() + return + } + console.warn(e) + }) + } else { + redirect() + } + } +} let data = ref({ username: '', @@ -204,7 +228,9 @@ const signin = () => { salt.toString() }).then(e => { oaer.init('', '', e).then(() => { - redirect("") + isValid.value = true + auto_redirect() + // redirect("") }).catch((e) => { console.warn(e) msg.Warn('登录失败:' + (e?.err || e)) @@ -254,10 +280,9 @@ function redirect(url?: string) { if (route.query.redirect) { url = route.query.redirect as string } - let uuid = route.query.uuid as string - if (uuid) { - oaer.api().app.Get(uuid as string).then((app) => { - if (uuid === oaer.logic().oa_id) { + if (uuid.value) { + api.app.Get(uuid.value).then((app) => { + if (uuid.value === oaer.logic().oa_id) { oaer.goto(url || app.init_url || '/') } else { let perm = [] @@ -271,9 +296,9 @@ function redirect(url?: string) { }) } } - oaer.api().token.Post({ + api.token.Post({ refresh: oaer.logic().token.refresh.raw(), - app_id: uuid, + app_id: uuid.value, over_perm: JSON.stringify(perm) }).then(e => { url = url || app.init_url @@ -295,19 +320,7 @@ function redirect(url?: string) { } onMounted(() => { - let uuid = route.query.uuid as string - if (isValid.value && uuid) { - oaer.api().app.Get(uuid).then(e => { - app.value = e - }).catch(e => { - if (e.code === 40401) { - msg.Warn('参数错误: 该应用不存在') - return - } - console.warn(e) - }) - - } + auto_redirect() }) diff --git a/oaweb/pages/user.vue b/oaweb/pages/user.vue index d10eda8..ebd41b8 100644 --- a/oaweb/pages/user.vue +++ b/oaweb/pages/user.vue @@ -1,4 +1,4 @@ - -