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/utils": "^1.0.0-beta.12",
|
||||||
"@formkit/validation": "1.0.0-beta.12",
|
"@formkit/validation": "1.0.0-beta.12",
|
||||||
"@formkit/vue": "^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/components": "workspace:*",
|
||||||
"@halo-dev/console-shared": "workspace:*",
|
"@halo-dev/console-shared": "workspace:*",
|
||||||
"@halo-dev/richtext-editor": "^0.0.0-alpha.17",
|
"@halo-dev/richtext-editor": "^0.0.0-alpha.17",
|
||||||
|
|
|
@ -13,7 +13,7 @@ importers:
|
||||||
'@formkit/utils': ^1.0.0-beta.12
|
'@formkit/utils': ^1.0.0-beta.12
|
||||||
'@formkit/validation': 1.0.0-beta.12
|
'@formkit/validation': 1.0.0-beta.12
|
||||||
'@formkit/vue': ^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/components': workspace:*
|
||||||
'@halo-dev/console-shared': workspace:*
|
'@halo-dev/console-shared': workspace:*
|
||||||
'@halo-dev/richtext-editor': ^0.0.0-alpha.17
|
'@halo-dev/richtext-editor': ^0.0.0-alpha.17
|
||||||
|
@ -108,7 +108,7 @@ importers:
|
||||||
'@formkit/utils': 1.0.0-beta.12-e579559
|
'@formkit/utils': 1.0.0-beta.12-e579559
|
||||||
'@formkit/validation': 1.0.0-beta.12
|
'@formkit/validation': 1.0.0-beta.12
|
||||||
'@formkit/vue': 1.0.0-beta.12-e579559_ior6jr3fpijijuwpr34w2i25va
|
'@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/components': link:packages/components
|
||||||
'@halo-dev/console-shared': link:packages/shared
|
'@halo-dev/console-shared': link:packages/shared
|
||||||
'@halo-dev/richtext-editor': 0.0.0-alpha.17_vue@3.2.45
|
'@halo-dev/richtext-editor': 0.0.0-alpha.17_vue@3.2.45
|
||||||
|
@ -1992,8 +1992,8 @@ packages:
|
||||||
- windicss
|
- windicss
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@halo-dev/api-client/0.0.64:
|
/@halo-dev/api-client/0.0.65:
|
||||||
resolution: {integrity: sha512-zzhTdRi4p7nRsWG7u85YCkoHZLHsbpuWeBCwLl5FSXxY8ruKuiOo0FypkS7Ll7505XASk4MJL6rsyeX+l7rLmQ==}
|
resolution: {integrity: sha512-00x5cDnXhjIHlTJ9CB9QDxyiWhJv48DWzKpKh/E1BvIB/umAqAG/S2TATB6z6GvOalOLXMfnQv6IfCb76wgl1Q==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@halo-dev/richtext-editor/0.0.0-alpha.17_vue@3.2.45:
|
/@halo-dev/richtext-editor/0.0.0-alpha.17_vue@3.2.45:
|
||||||
|
|
|
@ -241,7 +241,7 @@ onMounted(generateMenus);
|
||||||
type="secondary"
|
type="secondary"
|
||||||
:route="{
|
:route="{
|
||||||
name: 'UserDetail',
|
name: 'UserDetail',
|
||||||
params: { name: userStore.currentUser?.metadata.name },
|
params: { name: '-' },
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
个人资料
|
个人资料
|
||||||
|
|
|
@ -23,8 +23,6 @@ interface Action {
|
||||||
permissions?: string[];
|
permissions?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const userStore = useUserStore();
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const themePreviewVisible = ref(false);
|
const themePreviewVisible = ref(false);
|
||||||
|
@ -36,7 +34,7 @@ const actions: Action[] = [
|
||||||
action: () => {
|
action: () => {
|
||||||
router.push({
|
router.push({
|
||||||
name: "UserDetail",
|
name: "UserDetail",
|
||||||
params: { name: userStore.currentUser?.metadata.name },
|
params: { name: "-" },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,6 +15,9 @@ import { reset } from "@formkit/core";
|
||||||
// hooks
|
// hooks
|
||||||
import { setFocus } from "@/formkit/utils/focus";
|
import { setFocus } from "@/formkit/utils/focus";
|
||||||
import AnnotationsForm from "@/components/form/AnnotationsForm.vue";
|
import AnnotationsForm from "@/components/form/AnnotationsForm.vue";
|
||||||
|
import { useUserStore } from "@/stores/user";
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -115,10 +118,16 @@ const handleCreateUser = async () => {
|
||||||
try {
|
try {
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
if (isUpdateMode.value) {
|
if (isUpdateMode.value) {
|
||||||
await apiClient.extension.user.updatev1alpha1User({
|
if (props.user?.metadata.name === userStore.currentUser?.metadata.name) {
|
||||||
name: formState.value.metadata.name,
|
await apiClient.user.updateCurrentUser({
|
||||||
user: formState.value,
|
user: formState.value,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
await apiClient.extension.user.updatev1alpha1User({
|
||||||
|
name: formState.value.metadata.name,
|
||||||
|
user: formState.value,
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await apiClient.extension.user.createv1alpha1User({
|
await apiClient.extension.user.createv1alpha1User({
|
||||||
user: formState.value,
|
user: formState.value,
|
||||||
|
|
|
@ -8,11 +8,16 @@ import {
|
||||||
VTabbar,
|
VTabbar,
|
||||||
VAvatar,
|
VAvatar,
|
||||||
} from "@halo-dev/components";
|
} 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 { useRoute, useRouter } from "vue-router";
|
||||||
import type { User } from "@halo-dev/api-client";
|
import type { User } from "@halo-dev/api-client";
|
||||||
import UserEditingModal from "../components/UserEditingModal.vue";
|
import UserEditingModal from "../components/UserEditingModal.vue";
|
||||||
import UserPasswordChangeModal from "../components/UserPasswordChangeModal.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 = [
|
const tabs = [
|
||||||
{
|
{
|
||||||
|
@ -35,15 +40,27 @@ const { params } = useRoute();
|
||||||
|
|
||||||
const handleFetchUser = async () => {
|
const handleFetchUser = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await apiClient.extension.user.getv1alpha1User({
|
if (params.name === "-") {
|
||||||
name: params.name as string,
|
const { data } = await apiClient.user.getCurrentUserDetail();
|
||||||
});
|
user.value = data;
|
||||||
user.value = data;
|
} else {
|
||||||
|
const { data } = await apiClient.extension.user.getv1alpha1User({
|
||||||
|
name: params.name as string,
|
||||||
|
});
|
||||||
|
user.value = data;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isCurrentUser = computed(() => {
|
||||||
|
if (params.name === "-") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return user.value?.metadata.name === userStore.currentUser?.metadata.name;
|
||||||
|
});
|
||||||
|
|
||||||
provide("user", user);
|
provide("user", user);
|
||||||
|
|
||||||
const activeTab = ref();
|
const activeTab = ref();
|
||||||
|
@ -112,6 +129,10 @@ const handleTabChange = (id: string) => {
|
||||||
<h2 class="text-gray-600">@{{ user?.metadata.name }}</h2>
|
<h2 class="text-gray-600">@{{ user?.metadata.name }}</h2>
|
||||||
</div>
|
</div>
|
||||||
<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"
|
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>
|
<FloatingDropdown>
|
||||||
|
|
Loading…
Reference in New Issue