This commit is contained in:
Megghy
2023-06-07 16:01:12 +08:00
parent 4b456d2ec4
commit 2e14596be6
7 changed files with 149 additions and 60 deletions

View File

@@ -1,12 +1,18 @@
/* eslint-disable indent */
import { APIRoot, PaginationResponse } from './api-models'
export async function QueryPostAPI<T>(url: string, body?: unknown): Promise<APIRoot<T>> {
export async function QueryPostAPI<T>(url: string, body?: unknown, headers?: any): Promise<APIRoot<T>> {
if (headers) {
headers['Content-Type'] = 'application/json'
}
else {
headers = {
'Content-Type': 'application/json',
}
}
const data = await fetch(url, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
headers: headers,
body: JSON.stringify(body),
}) // 不处理异常, 在页面处理
return (await data.json()) as APIRoot<T>