diff --git a/src/api/user/index.ts b/src/api/user/index.ts index 624c9fb4..43c2d904 100644 --- a/src/api/user/index.ts +++ b/src/api/user/index.ts @@ -1,6 +1,7 @@ -import { fetchGet } from '@/utils/request' +import { fetchGet, fetchPut } from '@/utils/request' import * as User from './types/user' +// 获取单个用户信息 export async function getUserByUidApi( uid: number ): Promise { @@ -12,3 +13,10 @@ export async function getUserByUidApi( // 返回获取的用户数据 return response } + +// 更新用户 bio +export async function updateUserBioApi(request: User.UserUpdateBioRequestData) { + const url = `/user/${request.uid}/bio` + const response = await fetchPut(url, request) + return response +} diff --git a/src/api/user/types/user.ts b/src/api/user/types/user.ts index 6560256f..b43cfade 100644 --- a/src/api/user/types/user.ts +++ b/src/api/user/types/user.ts @@ -2,7 +2,7 @@ export interface UserInfo { uid: number name: string avatar: string - roles: string + roles: number status: number time: number moemoepoint: number @@ -17,4 +17,11 @@ export interface UserInfo { comment: number[] } +export interface UserUpdateBioRequestData { + uid: number + bio: string +} + export type UserInfoResponseData = KUNGalgameResponseData + +export type UserUpdateBioResponseData = KUNGalgameResponseData<{}> diff --git a/src/store/modules/kungalgamer.ts b/src/store/modules/kungalgamer.ts index 96961366..fdcb4c32 100644 --- a/src/store/modules/kungalgamer.ts +++ b/src/store/modules/kungalgamer.ts @@ -16,9 +16,13 @@ import { sendVerificationCodeMailApi, } from '@/api' -import type { UserInfoResponseData } from '@/api' +import type { + UserInfoResponseData, + UserUpdateBioRequestData, + UserUpdateBioResponseData, +} from '@/api' -import { getUserByUidApi } from '@/api' +import { getUserByUidApi, updateUserBioApi } from '@/api' // kungalgame store 类型 import { KUNGalgamerStore } from '../types/kungalgamer' @@ -109,5 +113,17 @@ export const useKUNGalgameUserStore = defineStore({ async getUser(uid: number): Promise { return getUserByUidApi(uid) }, + + // 更新用户 bio + async updateBio( + uid: number, + bio: string + ): Promise { + const request: UserUpdateBioRequestData = { + uid, + bio, + } + return updateUserBioApi(request) + }, }, }) diff --git a/src/views/kungalgamer/content/Info.vue b/src/views/kungalgamer/content/Info.vue index f72366ce..df45662f 100644 --- a/src/views/kungalgamer/content/Info.vue +++ b/src/views/kungalgamer/content/Info.vue @@ -9,6 +9,33 @@ const props = defineProps<{ }>() const user = computed(() => props.user) + +// 角色名 +const rolesName = () => { + const roles = props.user.roles + if (roles === 1) { + return 'user' + } + if (roles === 2) { + return 'admin' + } + if (roles === 3) { + return 'SU' + } + return '' +} + +// 状态名 +const statusName = () => { + const status = props.user.status + if (status === 0) { + return 'normal' + } + if (status === 1) { + return 'banned' + } + return '' +}