mirror of https://github.com/halo-dev/halo
fix: user detail page switching does not take effect (#4321)
#### What type of PR is this? /area console /kind bug /milestone 2.8.x #### What this PR does / why we need it: 修复用户详情页面切换用户之后,数据不更新的问题。操作路径: 1. 进入任意一个用户的资料页面。 2. 点击左下角当前登录用户的个人资料。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/4320 #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? ```release-note 修复用户详情页面切换用户之后,数据不更新的问题。 ```pull/4322/head
parent
eced9365a2
commit
e0d79cc2b2
|
@ -34,6 +34,7 @@ import { useQuery } from "@tanstack/vue-query";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useFileDialog } from "@vueuse/core";
|
import { useFileDialog } from "@vueuse/core";
|
||||||
import { rbacAnnotations } from "@/constants/annotations";
|
import { rbacAnnotations } from "@/constants/annotations";
|
||||||
|
import { onBeforeRouteUpdate } from "vue-router";
|
||||||
|
|
||||||
const UserAvatarCropper = defineAsyncComponent(
|
const UserAvatarCropper = defineAsyncComponent(
|
||||||
() => import("../components/UserAvatarCropper.vue")
|
() => import("../components/UserAvatarCropper.vue")
|
||||||
|
@ -69,6 +70,17 @@ const editingModal = ref(false);
|
||||||
const passwordChangeModal = ref(false);
|
const passwordChangeModal = ref(false);
|
||||||
|
|
||||||
const { params } = useRoute();
|
const { params } = useRoute();
|
||||||
|
const name = ref();
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
name.value = params.name;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update name when route change
|
||||||
|
onBeforeRouteUpdate((to, _, next) => {
|
||||||
|
name.value = to.params.name;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: user,
|
data: user,
|
||||||
|
@ -76,14 +88,14 @@ const {
|
||||||
isLoading,
|
isLoading,
|
||||||
refetch,
|
refetch,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["user-detail", params.name],
|
queryKey: ["user-detail", name],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (params.name === "-") {
|
if (name.value === "-") {
|
||||||
const { data } = await apiClient.user.getCurrentUserDetail();
|
const { data } = await apiClient.user.getCurrentUserDetail();
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} else {
|
||||||
const { data } = await apiClient.user.getUserDetail({
|
const { data } = await apiClient.user.getUserDetail({
|
||||||
name: params.name as string,
|
name: name.value,
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -95,10 +107,11 @@ const {
|
||||||
? 1000
|
? 1000
|
||||||
: false;
|
: false;
|
||||||
},
|
},
|
||||||
|
enabled: computed(() => !!name.value),
|
||||||
});
|
});
|
||||||
|
|
||||||
const isCurrentUser = computed(() => {
|
const isCurrentUser = computed(() => {
|
||||||
if (params.name === "-") {
|
if (name.value === "-") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
@ -155,7 +168,7 @@ const handleUploadAvatar = () => {
|
||||||
uploadSaving.value = true;
|
uploadSaving.value = true;
|
||||||
apiClient.user
|
apiClient.user
|
||||||
.uploadUserAvatar({
|
.uploadUserAvatar({
|
||||||
name: params.name as string,
|
name: name.value,
|
||||||
file: file,
|
file: file,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -181,7 +194,7 @@ const handleRemoveCurrentAvatar = () => {
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
apiClient.user
|
apiClient.user
|
||||||
.deleteUserAvatar({
|
.deleteUserAvatar({
|
||||||
name: params.name as string,
|
name: name.value as string,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
refetch();
|
refetch();
|
||||||
|
|
Loading…
Reference in New Issue