This commit is contained in:
Megghy
2023-10-07 11:45:48 +08:00
parent f3c6afe4b6
commit e93cccd054
9 changed files with 551 additions and 305 deletions

View File

@@ -3,22 +3,23 @@ import { BASE_API, USER_API_URL } from '@/data/constants'
import { APIRoot, UserInfo } from './api-models'
import { ref } from 'vue'
import { useRouteParams } from '@vueuse/router'
import { useRoute } from 'vue-router'
export const USERS = ref<{ [uId: number]: UserInfo }>({})
export async function useUser() {
const uId = useRouteParams('id', '-1', { transform: Number }).value
if (uId) {
if (!USERS.value[uId]) {
const result = await GetInfo(uId)
export async function useUser(id: number | undefined = undefined) {
const route = useRoute()
id ??= Number(route.params.id)
if (id) {
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]
}
else {
console.error('指定uId: ' + uId + ' 无效');
return USERS.value[id]
} else {
console.error('指定id: ' + id + ' 无效')
}
}
export async function useUserWithUId(id: number) {