This commit is contained in:
2023-10-16 11:27:37 +08:00
parent 826f99350c
commit b5b55dc3b2
29 changed files with 951 additions and 319 deletions

View File

@@ -1,18 +1,19 @@
/* eslint-disable indent */
import { useLocalStorage } from '@vueuse/core'
import { APIRoot, PaginationResponse } from './api-models'
import { Cookies20Regular } from '@vicons/fluent'
const cookie = useLocalStorage('JWT_Token', '')
export async function QueryPostAPI<T>(url: string, body?: unknown, headers?: [string, string][]): Promise<APIRoot<T>> {
headers ??= []
headers?.push(['Authorization', `Bearer ${cookie.value}`])
if (cookie.value) headers?.push(['Authorization', `Bearer ${cookie.value}`])
headers?.push(['Content-Type', 'application/json'])
const data = await fetch(url, {
method: 'post',
headers: headers,
body: JSON.stringify(body),
body: typeof body === 'string' ? body : JSON.stringify(body),
}) // 不处理异常, 在页面处理
return (await data.json()) as APIRoot<T>
}