feat: 更新 @riwa/api-types 依赖至 0.0.49,优化用户数据处理逻辑

This commit is contained in:
2025-12-22 05:45:24 +07:00
parent 66e2222c48
commit 6d9b6b0a1b
9 changed files with 20 additions and 26 deletions

View File

@@ -25,9 +25,7 @@ export type WithdrawBody = Omit<Parameters<typeof client.api.withdraw.post>[0],
withdrawMethod: WithdrawMethodEnum;
};
export type UserProfileData = Treaty.Data<typeof client.api.user.profile.get>["userProfile"];
export type UserData = Treaty.Data<typeof client.api.user.profile.get>["user"];
export type UserProfileData = Treaty.Data<typeof client.api.user.profile.get>;
export type UpdateUserProfileBody = TreatyBody<typeof client.api.user.profile.put>;

View File

@@ -1,15 +1,13 @@
import type { UserData, UserProfileData } from "@/api/types";
import type { UserProfileData } from "@/api/types";
import { client, safeClient } from "@/api";
interface State {
user: UserData | null;
userProfile: UserProfileData | null;
}
export const useUserStore = defineStore("user", () => {
const token = useStorage<string | null>("user-token", null);
const state = reactive<State>({
user: null,
userProfile: null,
});
@@ -17,8 +15,7 @@ export const useUserStore = defineStore("user", () => {
async function updateProfile() {
const { data } = await safeClient(client.api.user.profile.get(), { silent: true });
state.userProfile = data.value?.userProfile || null;
state.user = data.value?.user || null;
state.userProfile = data.value || null;
}
function setToken(value: string) {
@@ -28,7 +25,6 @@ export const useUserStore = defineStore("user", () => {
function signOut() {
token.value = null;
state.userProfile = null;
state.user = null;
}
return {

View File

@@ -2,7 +2,7 @@
import { copyOutline, qrCodeOutline, shareOutline } from "ionicons/icons";
const userStore = useUserStore();
const { user } = storeToRefs(userStore);
const { userProfile } = storeToRefs(userStore);
</script>
<template>
@@ -23,7 +23,7 @@ const { user } = storeToRefs(userStore);
<ui-avatar class="size-18" />
</div>
<IonText class="user-email">
{{ user?.email }}
{{ userProfile?.user.email }}
</IonText>
</div>

View File

@@ -8,8 +8,8 @@ import { safeClient } from "@/api";
import { authClient, emailSchema } from "@/auth";
const userStore = useUserStore();
const { user } = storeToRefs(userStore);
const email = ref(user.value?.email || "");
const { userProfile } = storeToRefs(userStore);
const email = ref(userProfile.value?.user?.email || "");
const { updateProfile } = useUserStore();
const { t } = useI18n();
const countdown = ref(0);

View File

@@ -6,7 +6,7 @@ import { authClient } from "@/auth";
const router = useRouter();
const userStore = useUserStore();
const { user, userProfile } = storeToRefs(userStore);
const { userProfile } = storeToRefs(userStore);
async function handleSignOut() {
const alert = await alertController.create({
@@ -118,7 +118,7 @@ function handleCopyUid() {
</div>
</div>
<div class="end">
{{ user?.email }}
{{ userProfile?.user?.email }}
</div>
</div>
</ion-item>

View File

@@ -5,8 +5,8 @@ import { safeClient } from "@/api";
import { authClient } from "@/auth";
const userStore = useUserStore();
const { user } = storeToRefs(userStore);
const username = ref(user.value?.username || "");
const { userProfile } = storeToRefs(userStore);
const username = ref(userProfile.value?.user?.username || "");
const { updateProfile } = useUserStore();
async function handleSave() {

View File

@@ -2,7 +2,7 @@
import { chevronForwardOutline, copyOutline, qrCodeOutline } from "ionicons/icons";
const userStore = useUserStore();
const { user, userProfile } = storeToRefs(userStore);
const { userProfile } = storeToRefs(userStore);
</script>
<template>
@@ -11,7 +11,7 @@ const { user, userProfile } = storeToRefs(userStore);
<ui-avatar class="size-18" />
<div>
<div class="user-name">
{{ user?.email }}
{{ userProfile?.user?.email }}
</div>
<div class="user-uid mt-1 text-xs text-text-100">
UID: {{ userProfile?.uid }}