mirror of https://github.com/halo-dev/halo-admin
fix: logged-in users cannot access the profile page (#796)
#### What type of PR is this? /kind bug #### What this PR does / why we need it: 修复已登录用户无法访问个人资料页面的问题。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3027 #### Special notes for your reviewer: /hold 等待 https://github.com/halo-dev/halo/issues/3035 解决。 #### Does this PR introduce a user-facing change? ```release-note 修复 Console 端已登录用户无法访问个人资料页面的问题。 ```pull/804/head^2
parent
f8fe630d4c
commit
4661c5ed66
|
@ -41,7 +41,7 @@
|
|||
"@formkit/utils": "^1.0.0-beta.12",
|
||||
"@formkit/validation": "1.0.0-beta.12",
|
||||
"@formkit/vue": "^1.0.0-beta.12",
|
||||
"@halo-dev/api-client": "0.0.64",
|
||||
"@halo-dev/api-client": "0.0.65",
|
||||
"@halo-dev/components": "workspace:*",
|
||||
"@halo-dev/console-shared": "workspace:*",
|
||||
"@halo-dev/richtext-editor": "^0.0.0-alpha.17",
|
||||
|
|
|
@ -13,7 +13,7 @@ importers:
|
|||
'@formkit/utils': ^1.0.0-beta.12
|
||||
'@formkit/validation': 1.0.0-beta.12
|
||||
'@formkit/vue': ^1.0.0-beta.12
|
||||
'@halo-dev/api-client': 0.0.64
|
||||
'@halo-dev/api-client': 0.0.65
|
||||
'@halo-dev/components': workspace:*
|
||||
'@halo-dev/console-shared': workspace:*
|
||||
'@halo-dev/richtext-editor': ^0.0.0-alpha.17
|
||||
|
@ -108,7 +108,7 @@ importers:
|
|||
'@formkit/utils': 1.0.0-beta.12-e579559
|
||||
'@formkit/validation': 1.0.0-beta.12
|
||||
'@formkit/vue': 1.0.0-beta.12-e579559_ior6jr3fpijijuwpr34w2i25va
|
||||
'@halo-dev/api-client': 0.0.64
|
||||
'@halo-dev/api-client': 0.0.65
|
||||
'@halo-dev/components': link:packages/components
|
||||
'@halo-dev/console-shared': link:packages/shared
|
||||
'@halo-dev/richtext-editor': 0.0.0-alpha.17_vue@3.2.45
|
||||
|
@ -1992,8 +1992,8 @@ packages:
|
|||
- windicss
|
||||
dev: false
|
||||
|
||||
/@halo-dev/api-client/0.0.64:
|
||||
resolution: {integrity: sha512-zzhTdRi4p7nRsWG7u85YCkoHZLHsbpuWeBCwLl5FSXxY8ruKuiOo0FypkS7Ll7505XASk4MJL6rsyeX+l7rLmQ==}
|
||||
/@halo-dev/api-client/0.0.65:
|
||||
resolution: {integrity: sha512-00x5cDnXhjIHlTJ9CB9QDxyiWhJv48DWzKpKh/E1BvIB/umAqAG/S2TATB6z6GvOalOLXMfnQv6IfCb76wgl1Q==}
|
||||
dev: false
|
||||
|
||||
/@halo-dev/richtext-editor/0.0.0-alpha.17_vue@3.2.45:
|
||||
|
|
|
@ -241,7 +241,7 @@ onMounted(generateMenus);
|
|||
type="secondary"
|
||||
:route="{
|
||||
name: 'UserDetail',
|
||||
params: { name: userStore.currentUser?.metadata.name },
|
||||
params: { name: '-' },
|
||||
}"
|
||||
>
|
||||
个人资料
|
||||
|
|
|
@ -23,8 +23,6 @@ interface Action {
|
|||
permissions?: string[];
|
||||
}
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const themePreviewVisible = ref(false);
|
||||
|
@ -36,7 +34,7 @@ const actions: Action[] = [
|
|||
action: () => {
|
||||
router.push({
|
||||
name: "UserDetail",
|
||||
params: { name: userStore.currentUser?.metadata.name },
|
||||
params: { name: "-" },
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
@ -15,6 +15,9 @@ import { reset } from "@formkit/core";
|
|||
// hooks
|
||||
import { setFocus } from "@/formkit/utils/focus";
|
||||
import AnnotationsForm from "@/components/form/AnnotationsForm.vue";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
|
@ -115,10 +118,16 @@ const handleCreateUser = async () => {
|
|||
try {
|
||||
saving.value = true;
|
||||
if (isUpdateMode.value) {
|
||||
if (props.user?.metadata.name === userStore.currentUser?.metadata.name) {
|
||||
await apiClient.user.updateCurrentUser({
|
||||
user: formState.value,
|
||||
});
|
||||
} else {
|
||||
await apiClient.extension.user.updatev1alpha1User({
|
||||
name: formState.value.metadata.name,
|
||||
user: formState.value,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await apiClient.extension.user.createv1alpha1User({
|
||||
user: formState.value,
|
||||
|
|
|
@ -8,11 +8,16 @@ import {
|
|||
VTabbar,
|
||||
VAvatar,
|
||||
} from "@halo-dev/components";
|
||||
import { onMounted, provide, ref, watch } from "vue";
|
||||
import { computed, onMounted, provide, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import type { User } from "@halo-dev/api-client";
|
||||
import UserEditingModal from "../components/UserEditingModal.vue";
|
||||
import UserPasswordChangeModal from "../components/UserPasswordChangeModal.vue";
|
||||
import { usePermission } from "@/utils/permission";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
|
||||
const { currentUserHasPermission } = usePermission();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
|
@ -35,15 +40,27 @@ const { params } = useRoute();
|
|||
|
||||
const handleFetchUser = async () => {
|
||||
try {
|
||||
if (params.name === "-") {
|
||||
const { data } = await apiClient.user.getCurrentUserDetail();
|
||||
user.value = data;
|
||||
} else {
|
||||
const { data } = await apiClient.extension.user.getv1alpha1User({
|
||||
name: params.name as string,
|
||||
});
|
||||
user.value = data;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
const isCurrentUser = computed(() => {
|
||||
if (params.name === "-") {
|
||||
return true;
|
||||
}
|
||||
return user.value?.metadata.name === userStore.currentUser?.metadata.name;
|
||||
});
|
||||
|
||||
provide("user", user);
|
||||
|
||||
const activeTab = ref();
|
||||
|
@ -112,6 +129,10 @@ const handleTabChange = (id: string) => {
|
|||
<h2 class="text-gray-600">@{{ user?.metadata.name }}</h2>
|
||||
</div>
|
||||
<div
|
||||
v-if="
|
||||
currentUserHasPermission(['system:users:manage']) ||
|
||||
isCurrentUser
|
||||
"
|
||||
class="justify-stretch mt-6 hidden flex-col space-y-3 sm:flex-row sm:space-y-0 sm:space-x-4 md:flex"
|
||||
>
|
||||
<FloatingDropdown>
|
||||
|
|
Loading…
Reference in New Issue