feat: user info status
This commit is contained in:
parent
2183000947
commit
bd67e9cdbb
|
@ -1,6 +1,7 @@
|
||||||
import { fetchGet } from '@/utils/request'
|
import { fetchGet, fetchPut } from '@/utils/request'
|
||||||
import * as User from './types/user'
|
import * as User from './types/user'
|
||||||
|
|
||||||
|
// 获取单个用户信息
|
||||||
export async function getUserByUidApi(
|
export async function getUserByUidApi(
|
||||||
uid: number
|
uid: number
|
||||||
): Promise<User.UserInfoResponseData> {
|
): Promise<User.UserInfoResponseData> {
|
||||||
|
@ -12,3 +13,10 @@ export async function getUserByUidApi(
|
||||||
// 返回获取的用户数据
|
// 返回获取的用户数据
|
||||||
return response
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ export interface UserInfo {
|
||||||
uid: number
|
uid: number
|
||||||
name: string
|
name: string
|
||||||
avatar: string
|
avatar: string
|
||||||
roles: string
|
roles: number
|
||||||
status: number
|
status: number
|
||||||
time: number
|
time: number
|
||||||
moemoepoint: number
|
moemoepoint: number
|
||||||
|
@ -17,4 +17,11 @@ export interface UserInfo {
|
||||||
comment: number[]
|
comment: number[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UserUpdateBioRequestData {
|
||||||
|
uid: number
|
||||||
|
bio: string
|
||||||
|
}
|
||||||
|
|
||||||
export type UserInfoResponseData = KUNGalgameResponseData<UserInfo>
|
export type UserInfoResponseData = KUNGalgameResponseData<UserInfo>
|
||||||
|
|
||||||
|
export type UserUpdateBioResponseData = KUNGalgameResponseData<{}>
|
||||||
|
|
|
@ -16,9 +16,13 @@ import {
|
||||||
sendVerificationCodeMailApi,
|
sendVerificationCodeMailApi,
|
||||||
} from '@/api'
|
} 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 类型
|
// kungalgame store 类型
|
||||||
import { KUNGalgamerStore } from '../types/kungalgamer'
|
import { KUNGalgamerStore } from '../types/kungalgamer'
|
||||||
|
@ -109,5 +113,17 @@ export const useKUNGalgameUserStore = defineStore({
|
||||||
async getUser(uid: number): Promise<UserInfoResponseData> {
|
async getUser(uid: number): Promise<UserInfoResponseData> {
|
||||||
return getUserByUidApi(uid)
|
return getUserByUidApi(uid)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 更新用户 bio
|
||||||
|
async updateBio(
|
||||||
|
uid: number,
|
||||||
|
bio: string
|
||||||
|
): Promise<UserUpdateBioResponseData> {
|
||||||
|
const request: UserUpdateBioRequestData = {
|
||||||
|
uid,
|
||||||
|
bio,
|
||||||
|
}
|
||||||
|
return updateUserBioApi(request)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,6 +9,33 @@ const props = defineProps<{
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const user = computed(() => props.user)
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -24,16 +51,16 @@ const user = computed(() => props.user)
|
||||||
<span>萌萌点: {{ user.moemoepoint }}</span>
|
<span>萌萌点: {{ user.moemoepoint }}</span>
|
||||||
<!-- 注册序号 -->
|
<!-- 注册序号 -->
|
||||||
<span>注册序号: {{ user.uid }}</span>
|
<span>注册序号: {{ user.uid }}</span>
|
||||||
<span>角色: {{ user.roles }}</span>
|
<span>角色: {{ rolesName() }}</span>
|
||||||
<span>状态: {{ user.status }}</span>
|
<span>状态: {{ statusName() }}</span>
|
||||||
<span>被推数: {{ user.upvote }}</span>
|
<span>被推数: {{ user.upvote }}</span>
|
||||||
<span>被赞数: {{ user.like }}</span>
|
<span>被赞数: {{ user.like }}</span>
|
||||||
<span>被踩数: {{ user.dislike }}</span>
|
<span>被踩数: {{ user.dislike }}</span>
|
||||||
<span>今日发表: {{ user.daily_topic_count }}</span>
|
<span>今日发表: {{ user.daily_topic_count }}</span>
|
||||||
|
|
||||||
<span>发表话题数: {{ user.topic.length }}</span>
|
<span>话题数: {{ user.topic.length }}</span>
|
||||||
<span>发表回复数: {{ user.reply.length }}</span>
|
<span>回复数: {{ user.reply.length }}</span>
|
||||||
<span>发表评论数: {{ user.comment.length }}</span>
|
<span>评论数: {{ user.comment.length }}</span>
|
||||||
|
|
||||||
<!-- 注册时间 -->
|
<!-- 注册时间 -->
|
||||||
<span>注册时间: {{ dayjs(user.time).format('YYYY/MM/DD') }}</span>
|
<span>注册时间: {{ dayjs(user.time).format('YYYY/MM/DD') }}</span>
|
||||||
|
|
|
@ -1,12 +1,38 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import Avatar from '../components/Avatar.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 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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in a new issue