mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
nothing
This commit is contained in:
20
src/api/account.ts
Normal file
20
src/api/account.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import QueryAPI from '@/api/query'
|
||||
import { BASE_API } from '@/data/constants'
|
||||
import { APIRoot } from './api-models'
|
||||
|
||||
const ACCOUNT_URL = `${BASE_API}account/`
|
||||
|
||||
export async function Register(name: string, email: string, password: string): Promise<APIRoot<string>> {
|
||||
return QueryAPI<string>(`${ACCOUNT_URL}register`, {
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
})
|
||||
}
|
||||
|
||||
export async function Login(nameOrEmail: string, password: string): Promise<APIRoot<string>> {
|
||||
return QueryAPI<string>(`${ACCOUNT_URL}login`, {
|
||||
nameOrEmail,
|
||||
password,
|
||||
})
|
||||
}
|
||||
5
src/api/api-models.ts
Normal file
5
src/api/api-models.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface APIRoot<T> {
|
||||
code: number;
|
||||
message: string;
|
||||
data: T;
|
||||
}
|
||||
13
src/api/query.ts
Normal file
13
src/api/query.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/* eslint-disable indent */
|
||||
import { APIRoot } from './api-models';
|
||||
|
||||
export default async function QueryAPI<T>(url: string, body?: unknown): Promise<APIRoot<T>> {
|
||||
const data = await fetch(url,{
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
}); // 不处理异常, 在页面处理
|
||||
return await data.json() as APIRoot<T>;
|
||||
}
|
||||
Reference in New Issue
Block a user