|
|
@ -9,17 +9,20 @@ import { |
|
|
DropdownMenuItem, |
|
|
DropdownMenuItem, |
|
|
DropdownMenuLabel, |
|
|
DropdownMenuLabel, |
|
|
DropdownMenuSeparator, |
|
|
DropdownMenuSeparator, |
|
|
|
|
|
DropdownMenuShortcut, |
|
|
DropdownMenuTrigger, |
|
|
DropdownMenuTrigger, |
|
|
VbenAlertDialog, |
|
|
VbenAlertDialog, |
|
|
VbenAvatar, |
|
|
VbenAvatar, |
|
|
VbenIcon, |
|
|
VbenIcon, |
|
|
} from '@vben-core/shadcn-ui'; |
|
|
} from '@vben-core/shadcn-ui'; |
|
|
|
|
|
import { isWindowsOs } from '@vben-core/toolkit'; |
|
|
|
|
|
|
|
|
import type { Component } from 'vue'; |
|
|
import type { Component } from 'vue'; |
|
|
|
|
|
|
|
|
import { $t } from '@vben/locales'; |
|
|
import { $t } from '@vben/locales'; |
|
|
import { preference } from '@vben/preference'; |
|
|
import { preference } from '@vben/preference'; |
|
|
import { ref } from 'vue'; |
|
|
import { useMagicKeys, whenever } from '@vueuse/core'; |
|
|
|
|
|
import { computed, ref } from 'vue'; |
|
|
|
|
|
|
|
|
import { useOpenPreference } from '../preference/use-open-preference'; |
|
|
import { useOpenPreference } from '../preference/use-open-preference'; |
|
|
|
|
|
|
|
|
@ -32,15 +35,19 @@ interface Props { |
|
|
* @zh_CN 描述 |
|
|
* @zh_CN 描述 |
|
|
*/ |
|
|
*/ |
|
|
description?: string; |
|
|
description?: string; |
|
|
|
|
|
/** |
|
|
|
|
|
* 是否启用快捷键 |
|
|
|
|
|
*/ |
|
|
|
|
|
enableShortcutKey?: boolean; |
|
|
/** |
|
|
/** |
|
|
* 菜单数组 |
|
|
* 菜单数组 |
|
|
*/ |
|
|
*/ |
|
|
menus?: Array<{ handler: AnyFunction; icon?: Component; text: string }>; |
|
|
menus?: Array<{ handler: AnyFunction; icon?: Component; text: string }>; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 标签文本 |
|
|
* 标签文本 |
|
|
*/ |
|
|
*/ |
|
|
tagText?: string; |
|
|
tagText?: string; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 文本 |
|
|
* 文本 |
|
|
*/ |
|
|
*/ |
|
|
@ -51,10 +58,12 @@ defineOptions({ |
|
|
name: 'UserDropdown', |
|
|
name: 'UserDropdown', |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
withDefaults(defineProps<Props>(), { |
|
|
const props = withDefaults(defineProps<Props>(), { |
|
|
avatar: '', |
|
|
avatar: '', |
|
|
description: '', |
|
|
description: '', |
|
|
|
|
|
enableShortcutKey: true, |
|
|
menus: () => [], |
|
|
menus: () => [], |
|
|
|
|
|
showShortcutKey: true, |
|
|
tagText: '', |
|
|
tagText: '', |
|
|
text: '', |
|
|
text: '', |
|
|
}); |
|
|
}); |
|
|
@ -65,6 +74,12 @@ const openDialog = ref(false); |
|
|
|
|
|
|
|
|
const { handleOpenPreference } = useOpenPreference(); |
|
|
const { handleOpenPreference } = useOpenPreference(); |
|
|
|
|
|
|
|
|
|
|
|
const altView = computed(() => (isWindowsOs() ? 'Alt' : '⌥')); |
|
|
|
|
|
|
|
|
|
|
|
const shortcutKeys = computed(() => { |
|
|
|
|
|
return props.enableShortcutKey && preference.shortcutKeys; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
function handleLogout() { |
|
|
function handleLogout() { |
|
|
// emit |
|
|
// emit |
|
|
openDialog.value = true; |
|
|
openDialog.value = true; |
|
|
@ -75,6 +90,21 @@ function handleSubmitLogout() { |
|
|
emit('logout'); |
|
|
emit('logout'); |
|
|
openDialog.value = false; |
|
|
openDialog.value = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (shortcutKeys.value) { |
|
|
|
|
|
const keys = useMagicKeys(); |
|
|
|
|
|
whenever(keys['Alt+KeyQ'], () => { |
|
|
|
|
|
if (shortcutKeys.value) { |
|
|
|
|
|
handleLogout(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
whenever(keys['Alt+Comma'], () => { |
|
|
|
|
|
if (shortcutKeys.value) { |
|
|
|
|
|
handleOpenPreference(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<template> |
|
|
<template> |
|
|
@ -137,6 +167,9 @@ function handleSubmitLogout() { |
|
|
> |
|
|
> |
|
|
<IcRoundSettingsSuggest class="mr-2 size-5" /> |
|
|
<IcRoundSettingsSuggest class="mr-2 size-5" /> |
|
|
{{ $t('preference.preferences') }} |
|
|
{{ $t('preference.preferences') }} |
|
|
|
|
|
<DropdownMenuShortcut v-if="shortcutKeys"> |
|
|
|
|
|
{{ altView }} , |
|
|
|
|
|
</DropdownMenuShortcut> |
|
|
</DropdownMenuItem> |
|
|
</DropdownMenuItem> |
|
|
<DropdownMenuSeparator /> |
|
|
<DropdownMenuSeparator /> |
|
|
<DropdownMenuItem |
|
|
<DropdownMenuItem |
|
|
@ -145,6 +178,9 @@ function handleSubmitLogout() { |
|
|
> |
|
|
> |
|
|
<IcRoundLogout class="mr-2 size-5" /> |
|
|
<IcRoundLogout class="mr-2 size-5" /> |
|
|
{{ $t('common.logout') }} |
|
|
{{ $t('common.logout') }} |
|
|
|
|
|
<DropdownMenuShortcut v-if="shortcutKeys"> |
|
|
|
|
|
{{ altView }} Q |
|
|
|
|
|
</DropdownMenuShortcut> |
|
|
</DropdownMenuItem> |
|
|
</DropdownMenuItem> |
|
|
</DropdownMenuContent> |
|
|
</DropdownMenuContent> |
|
|
</DropdownMenu> |
|
|
</DropdownMenu> |
|
|
|