mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
update
This commit is contained in:
@@ -2,21 +2,37 @@ import { QueryGetAPI } from '@/api/query'
|
||||
import { BASE_API, USER_API_URL } from '@/data/constants'
|
||||
import { APIRoot, UserInfo } from './api-models'
|
||||
import { ref } from 'vue'
|
||||
import { useRouteParams } from '@vueuse/router'
|
||||
|
||||
export const USERS = ref<{ [uId: number]: UserInfo }>({})
|
||||
|
||||
export async function useUser(uId: number) {
|
||||
if (!USERS.value[uId]) {
|
||||
const result = await GetInfo(uId)
|
||||
export async function useUser() {
|
||||
const uId = useRouteParams('id', '-1', { transform: Number }).value
|
||||
if (uId) {
|
||||
if (!USERS.value[uId]) {
|
||||
const result = await GetInfo(uId)
|
||||
if (result.code == 200) {
|
||||
USERS.value[uId] = result.data
|
||||
}
|
||||
}
|
||||
return USERS.value[uId]
|
||||
}
|
||||
else {
|
||||
console.error('指定uId: ' + uId + ' 无效');
|
||||
}
|
||||
}
|
||||
export async function useUserWithUId(id: number) {
|
||||
if (!USERS.value[id]) {
|
||||
const result = await GetInfo(id)
|
||||
if (result.code == 200) {
|
||||
USERS.value[uId] = result.data
|
||||
USERS.value[id] = result.data
|
||||
}
|
||||
}
|
||||
return USERS.value[uId]
|
||||
return USERS.value[id]
|
||||
}
|
||||
|
||||
export async function GetInfo(uId: number): Promise<APIRoot<UserInfo>> {
|
||||
export async function GetInfo(id: number): Promise<APIRoot<UserInfo>> {
|
||||
return QueryGetAPI<UserInfo>(`${USER_API_URL}info`, {
|
||||
uId: uId,
|
||||
id: id,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user