feat: 将锁定屏幕和退出登录图标从用户下拉菜单移至头部栏

将锁定屏幕(LockKeyhole)和退出登录(LogOut)图标按钮从 UserDropdown 下拉菜单
移至 LayoutHeader 头部栏,位于通知图标的右侧。

变更内容:
- header.vue: 新增 lock-screen-btn 和 logout-btn 插槽,位于 notification 之后;
  添加 LockScreenModal/LogoutModal 及快捷键(Alt+L/Alt+Q)支持;
  新增 avatar/text props 用于锁屏弹窗显示
- layout.vue: 透传 avatar/text props 和 logout 事件
- user-dropdown.vue: 移除锁定屏幕和退出登录的菜单项、弹窗及快捷键逻辑
- 所有 5 个应用 basic.vue: 向 BasicLayout 传递 avatar/text,绑定 @logout 事件

头部右侧图标顺序: ... → 全屏 → 通知🔔 → 锁定🔒 → 退出🚪 → 用户头像
This commit is contained in:
ddfabc
2026-06-06 23:24:54 +08:00
parent 748b182e44
commit 4459389d4a
8 changed files with 185 additions and 144 deletions

View File

@@ -2,25 +2,38 @@
import { computed, useSlots } from 'vue';
import { useRefresh } from '@vben/hooks';
import { RotateCw } from '@vben/icons';
import { LockKeyhole, LogOut, RotateCw } from '@vben/icons';
import { $t } from '@vben/locales';
import { preferences, usePreferences } from '@vben/preferences';
import { useAccessStore } from '@vben/stores';
import { useVbenModal } from '@vben-core/popup-ui';
import { VbenFullScreen, VbenIconButton } from '@vben-core/shadcn-ui';
import { useMagicKeys, whenever } from '@vueuse/core';
import {
GlobalSearch,
LanguageToggle,
LockScreenModal,
PreferencesButton,
ThemeToggle,
TimezoneButton,
} from '../../widgets';
interface Props {
/**
* 头像
*/
avatar?: string;
/**
* Logo 主题
*/
theme?: string;
/**
* 用户文本
*/
text?: string;
}
defineOptions({
@@ -28,18 +41,79 @@ defineOptions({
});
withDefaults(defineProps<Props>(), {
avatar: '',
theme: 'light',
text: '',
});
const emit = defineEmits<{ clearPreferencesAndLogout: [] }>();
const emit = defineEmits<{
clearPreferencesAndLogout: [];
logout: [];
openLockScreen: [];
}>();
const REFERENCE_VALUE = 100;
const accessStore = useAccessStore();
const { globalSearchShortcutKey, preferencesButtonPosition } = usePreferences();
const {
globalLockScreenShortcutKey,
globalLogoutShortcutKey,
globalSearchShortcutKey,
preferencesButtonPosition,
} = usePreferences();
const slots = useSlots();
const { refresh } = useRefresh();
const [LockModal, lockModalApi] = useVbenModal({
connectedComponent: LockScreenModal,
});
const [LogoutModal, logoutModalApi] = useVbenModal({
onConfirm() {
handleSubmitLogout();
},
});
function handleOpenLock() {
lockModalApi.open();
}
function handleSubmitLock(lockScreenPassword: string) {
lockModalApi.close();
accessStore.lockScreen(lockScreenPassword);
}
function handleLogout() {
logoutModalApi.open();
}
function handleSubmitLogout() {
emit('logout');
logoutModalApi.close();
}
// 快捷键
if (preferences.shortcutKeys.enable) {
const keys = useMagicKeys();
const lockKey = keys['Alt+KeyL'];
const logoutKey = keys['Alt+KeyQ'];
if (lockKey) {
whenever(lockKey, () => {
if (globalLockScreenShortcutKey?.value) {
handleOpenLock();
}
});
}
if (logoutKey) {
whenever(logoutKey, () => {
if (globalLogoutShortcutKey?.value) {
handleLogout();
}
});
}
}
/**
* 插槽列表类型
*/
@@ -94,6 +168,18 @@ const rightSlots = computed(() => {
name: 'notification',
});
}
// 锁定屏幕
if (preferences.widget.lockScreen) {
list.push({
index: REFERENCE_VALUE + 70,
name: 'lock-screen-btn',
});
}
// 退出登录
list.push({
index: REFERENCE_VALUE + 80,
name: 'logout-btn',
});
Object.keys(slots).forEach((key) => {
// 适配插槽名称例如第一个插槽名header-right-1
@@ -150,6 +236,26 @@ function clearPreferencesAndLogout() {
</script>
<template>
<LockModal
v-if="preferences.widget.lockScreen"
:avatar="avatar"
:text="text"
@submit="handleSubmitLock"
/>
<LogoutModal
:cancel-text="$t('common.cancel')"
:confirm-text="$t('common.confirm')"
:fullscreen-button="false"
:title="$t('common.prompt')"
centered
content-class="px-8 min-h-10"
footer-class="border-none mb-3 mr-3"
header-class="border-none"
>
{{ $t('ui.widgets.logoutTip') }}
</LogoutModal>
<template
v-for="slot in leftSlots.filter((item) => item.index < REFERENCE_VALUE)"
:key="slot.name"
@@ -206,6 +312,24 @@ function clearPreferencesAndLogout() {
<template v-else-if="slot.name === 'timezone'">
<TimezoneButton class="mt-0.5 mr-1" />
</template>
<template v-else-if="slot.name === 'lock-screen-btn'">
<VbenIconButton
class="mr-1"
:tooltip="$t('ui.widgets.lockScreen.title')"
@click="handleOpenLock"
>
<LockKeyhole class="size-4" />
</VbenIconButton>
</template>
<template v-else-if="slot.name === 'logout-btn'">
<VbenIconButton
class="mr-1"
:tooltip="$t('common.logout')"
@click="handleLogout"
>
<LogOut class="size-4" />
</VbenIconButton>
</template>
</slot>
</template>
</div>