update url

This commit is contained in:
2023-12-14 12:56:28 +08:00
parent 4ab1f6da4f
commit 82a0e72122
39 changed files with 299 additions and 350 deletions

View File

@@ -1,5 +1,5 @@
import { QueryGetAPI } from '@/api/query'
import { BASE_API, USER_API_URL } from '@/data/constants'
import { BASE_API, USER_API_URL, apiFail } from '@/data/constants'
import { APIRoot, UserInfo } from './api-models'
import { ref } from 'vue'
import { useRouteParams } from '@vueuse/router'
@@ -12,7 +12,13 @@ export async function useUser(id: string | undefined = undefined) {
id ??= route.params.id.toString()
if (id) {
if (!USERS.value[id]) {
const result = await GetInfo(id)
let result: APIRoot<UserInfo>
try {
result = await GetInfo(id)
} catch {
apiFail.value = true
result = await GetInfo(id)
}
if (result.code == 200) {
USERS.value[id] = result.data
}
@@ -24,7 +30,7 @@ export async function useUser(id: string | undefined = undefined) {
}
export async function useUserWithUId(id: number) {
if (!USERS.value[id.toString()]) {
const result = await QueryGetAPI<UserInfo>(`${USER_API_URL}info`, {
const result = await QueryGetAPI<UserInfo>(`${USER_API_URL()}info`, {
uId: id,
})
if (result.code == 200) {
@@ -35,7 +41,7 @@ export async function useUserWithUId(id: number) {
}
export async function GetInfo(id: string): Promise<APIRoot<UserInfo>> {
return QueryGetAPI<UserInfo>(`${USER_API_URL}info`, {
return QueryGetAPI<UserInfo>(`${USER_API_URL()}info`, {
id: id,
})
}