mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
nothing
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import { BASE_API } from '@/data/constants'
|
||||
import { ACCOUNT_API_URL, BASE_API } from '@/data/constants'
|
||||
import { APIRoot } from './api-models'
|
||||
import { QueryPostAPI } from '@/api/query'
|
||||
import { UserInfo } from '@/api/api-models'
|
||||
import { ref } from 'vue'
|
||||
import { useCookies } from '@vueuse/integrations/useCookies'
|
||||
|
||||
const ACCOUNT_URL = `${BASE_API}account/`
|
||||
export const ACCOUNT = ref<UserInfo>()
|
||||
|
||||
const cookies = useCookies()
|
||||
@@ -24,7 +23,7 @@ export function useAccount() {
|
||||
}
|
||||
|
||||
export async function Register(name: string, email: string, password: string, token: string): Promise<APIRoot<string>> {
|
||||
return QueryPostAPI<string>(`${ACCOUNT_URL}register`, {
|
||||
return QueryPostAPI<string>(`${ACCOUNT_API_URL}register`, {
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
@@ -33,11 +32,11 @@ export async function Register(name: string, email: string, password: string, to
|
||||
}
|
||||
|
||||
export async function Login(nameOrEmail: string, password: string): Promise<APIRoot<string>> {
|
||||
return QueryPostAPI<string>(`${ACCOUNT_URL}login`, {
|
||||
return QueryPostAPI<string>(`${ACCOUNT_API_URL}login`, {
|
||||
nameOrEmail,
|
||||
password,
|
||||
})
|
||||
}
|
||||
export async function Self(): Promise<APIRoot<UserInfo>> {
|
||||
return QueryPostAPI<UserInfo>(`${ACCOUNT_URL}self`)
|
||||
return QueryPostAPI<UserInfo>(`${ACCOUNT_API_URL}self`)
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { QueryGetAPI } from '@/api/query'
|
||||
import { BASE_API } from '@/data/constants'
|
||||
import { BASE_API, USER_API_URL } from '@/data/constants'
|
||||
import { APIRoot, UserInfo } from './api-models'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const ACCOUNT_URL = `${BASE_API}user/`
|
||||
export const USERS = ref<{ [uId: number]: UserInfo }>({})
|
||||
|
||||
export async function useUser(uId: number) {
|
||||
@@ -17,7 +16,7 @@ export async function useUser(uId: number) {
|
||||
}
|
||||
|
||||
export async function GetInfo(uId: number): Promise<APIRoot<UserInfo>> {
|
||||
return QueryGetAPI<UserInfo>(`${ACCOUNT_URL}info`, {
|
||||
return QueryGetAPI<UserInfo>(`${USER_API_URL}info`, {
|
||||
uId: uId,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user