feat: user info status

This commit is contained in:
KUN1007 2023-10-12 00:13:30 +08:00
parent 2183000947
commit bd67e9cdbb
5 changed files with 95 additions and 11 deletions

View file

@ -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<User.UserInfoResponseData> {
@ -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<User.UserUpdateBioResponseData>(url, request)
return response
}

View file

@ -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<UserInfo>
export type UserUpdateBioResponseData = KUNGalgameResponseData<{}>

View file

@ -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<UserInfoResponseData> {
return getUserByUidApi(uid)
},
// 更新用户 bio
async updateBio(
uid: number,
bio: string
): Promise<UserUpdateBioResponseData> {
const request: UserUpdateBioRequestData = {
uid,
bio,
}
return updateUserBioApi(request)
},
},
})

View file

@ -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 ''
}
</script>
<template>
@ -24,16 +51,16 @@ const user = computed(() => props.user)
<span>萌萌点: {{ user.moemoepoint }}</span>
<!-- 注册序号 -->
<span>注册序号: {{ user.uid }}</span>
<span>角色: {{ user.roles }}</span>
<span>状态: {{ user.status }}</span>
<span>角色: {{ rolesName() }}</span>
<span>状态: {{ statusName() }}</span>
<span>被推数: {{ user.upvote }}</span>
<span>被赞数: {{ user.like }}</span>
<span>被踩数: {{ user.dislike }}</span>
<span>今日发表: {{ user.daily_topic_count }}</span>
<span>发表话题数: {{ user.topic.length }}</span>
<span>发表回复数: {{ user.reply.length }}</span>
<span>发表评论数: {{ user.comment.length }}</span>
<span>话题数: {{ user.topic.length }}</span>
<span>回复数: {{ user.reply.length }}</span>
<span>评论数: {{ user.comment.length }}</span>
<!-- 注册时间 -->
<span>注册时间: {{ dayjs(user.time).format('YYYY/MM/DD') }}</span>

View file

@ -1,12 +1,38 @@
<script setup lang="ts">
import { ref } from 'vue'
import { computed, ref } from 'vue'
import Avatar from '../components/Avatar.vue'
import message from '@/components/alert/Message'
// store
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
const currentUserUid = computed(() => useKUNGalgameUserStore().uid)
//
const bioValue = ref('')
//
const handleChangeBio = () => {}
const handleChangeBio = async () => {
//
if (bioValue.value.length > 107) {
message(
'Bio must not exceed a maximum length of 107 characters',
'签名的最大长度不可超过 107 个字符',
'warn'
)
return
}
const res = await useKUNGalgameUserStore().updateBio(
currentUserUid.value,
bioValue.value
)
if (res.code === 200) {
message('Rewrite bio successfully!', 'Rewrite 签名成功', 'success')
bioValue.value = ''
} else {
message('Rewrite bio failed!', 'Rewrite 签名失败', 'error')
}
}
</script>
<template>