-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
204 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<template> | ||
<div :class="$style.menuBar"> | ||
<n-dropdown v-for="item in menuItems" :key="item.key" :class="$style.dropdown" :options="item.children" | ||
placement="bottom-start" :show="showingItem == item.key" @select="handleSelect" | ||
@clickoutside="handleClickOutside"> | ||
<n-button quaternary :ref="(el) => bindMenuButton(item.key as string, el as ComponentPublicInstance | null)" | ||
@mouseenter="(e) => handleMouseEnter(e, item.key as string)" @click="(e) => handleClick(e, item.key as string)"> | ||
{{ item.label }} | ||
</n-button> | ||
</n-dropdown> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { h, ref, type ComponentPublicInstance } from 'vue'; | ||
import { | ||
type MenuOption, | ||
NButton, | ||
NDropdown, | ||
} from 'naive-ui'; | ||
import SizeSetter from './AppMenu/SizeSetter.vue'; | ||
import Fullscreen from './AppMenu/Fullscreen.vue'; | ||
const menuItems: MenuOption[] = [ | ||
{ | ||
label: '视图', | ||
key: 'view', | ||
children: [ | ||
{ | ||
key: 'icon-size', | ||
type: 'render', | ||
render: () => h(SizeSetter), | ||
}, | ||
{ type: 'divider' }, | ||
{ | ||
label: () => h(Fullscreen), | ||
key: 'fullscreen', | ||
}, | ||
], | ||
}, | ||
{ | ||
label: '帮助', | ||
key: 'help', | ||
children: [ | ||
{ | ||
label: () => h('a', { | ||
href: 'https://github.com/xingrz/rdt-editor', | ||
target: '_blank', | ||
}, '关于 RDT Editor'), | ||
key: 'about', | ||
}, | ||
], | ||
}, | ||
]; | ||
const showingItem = ref<string | null>(null); | ||
const menuButtons: Record<string, HTMLElement> = {}; | ||
function bindMenuButton(key: string, el: ComponentPublicInstance | null): void { | ||
if (el) { | ||
menuButtons[key] = el.$el; | ||
} else { | ||
delete menuButtons[key]; | ||
} | ||
} | ||
function handleClick(_e: MouseEvent, key: string): void { | ||
if (showingItem.value == null) { | ||
showingItem.value = key; | ||
} else { | ||
showingItem.value = null; | ||
} | ||
} | ||
function handleMouseEnter(_e: MouseEvent, key: string): void { | ||
if (showingItem.value != null) { | ||
menuButtons[showingItem.value]?.blur(); | ||
showingItem.value = key; | ||
menuButtons[showingItem.value]?.focus(); | ||
} | ||
} | ||
function handleSelect(): void { | ||
showingItem.value = null; | ||
} | ||
function handleClickOutside(e: MouseEvent): void { | ||
if (showingItem.value && menuButtons[showingItem.value]?.contains(e.target as Node)) { | ||
return; | ||
} | ||
showingItem.value = null; | ||
} | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.menuBar { | ||
display: flex; | ||
border-bottom: 1px solid #ddd; | ||
box-sizing: border-box; | ||
} | ||
.dropdown { | ||
min-width: 200px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<template> | ||
<div v-if="isFullscreen" @click="exitFullscreen">退出全屏</div> | ||
<div v-else @click="enterFullscreen">进入全屏</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import useDomEvented from '@/composables/useDomEvented'; | ||
const isFullscreen = useDomEvented(document, 'fullscreenchange', () => !!document.fullscreenElement); | ||
function enterFullscreen(): void { | ||
document.documentElement.requestFullscreen(); | ||
} | ||
function exitFullscreen(): void { | ||
document.exitFullscreen(); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<div :class="$style.setter"> | ||
<span>图标大小</span> | ||
<n-slider v-model:value="editorStore.size" :min="20" :max="60" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { | ||
NSlider, | ||
} from 'naive-ui'; | ||
import { useEditorStore } from '@/stores/editor'; | ||
const editorStore = useEditorStore(); | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.setter { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 4px; | ||
width: 200px; | ||
padding: 8px var(--n-option-prefix-width); | ||
font-size: var(--n-font-size); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { type UnwrapRef, onBeforeUnmount, onMounted, ref } from 'vue'; | ||
|
||
export default function useDomEvented<T>(target: EventTarget, type: string, getter: () => T) { | ||
const value = ref<T>(getter()); | ||
|
||
const listener = () => { | ||
value.value = getter() as UnwrapRef<T>; | ||
}; | ||
|
||
onMounted(() => { | ||
target.addEventListener(type, listener); | ||
}); | ||
|
||
onBeforeUnmount(() => { | ||
target.removeEventListener(type, listener); | ||
}); | ||
|
||
return value; | ||
} |