fix: support titlebar double click maximize
This commit is contained in:
@@ -33,6 +33,11 @@ const isMacOS = ref(false)
|
||||
const isMaximized = ref(false)
|
||||
const sessionUsername = ref('未登录')
|
||||
const sessionProvider = ref('Auth Provider')
|
||||
const titlebarDoubleClickMaxDelayMs = 500
|
||||
const titlebarDoubleClickMaxDistancePx = 8
|
||||
let lastTitlebarClickAt = 0
|
||||
let lastTitlebarClickX = 0
|
||||
let lastTitlebarClickY = 0
|
||||
|
||||
const navItems: NavItem[] = [
|
||||
{ path: '/dashboard', label: '工作台', detail: '指标与近期任务', icon: DashboardOutlined },
|
||||
@@ -55,6 +60,35 @@ async function toggleMaximize() {
|
||||
isMaximized.value = await Window.IsMaximised()
|
||||
}
|
||||
|
||||
function isNoDragTarget(target: EventTarget | null) {
|
||||
return target instanceof Element && target.closest('.no-drag')
|
||||
}
|
||||
|
||||
async function handleTitlebarMouseDown(event: MouseEvent) {
|
||||
if (!isWindows.value || event.button !== 0 || isNoDragTarget(event.target)) {
|
||||
return
|
||||
}
|
||||
|
||||
const now = window.performance.now()
|
||||
const isDoubleClick =
|
||||
now - lastTitlebarClickAt <= titlebarDoubleClickMaxDelayMs &&
|
||||
Math.abs(event.clientX - lastTitlebarClickX) <= titlebarDoubleClickMaxDistancePx &&
|
||||
Math.abs(event.clientY - lastTitlebarClickY) <= titlebarDoubleClickMaxDistancePx
|
||||
|
||||
lastTitlebarClickAt = now
|
||||
lastTitlebarClickX = event.clientX
|
||||
lastTitlebarClickY = event.clientY
|
||||
|
||||
if (!isDoubleClick) {
|
||||
return
|
||||
}
|
||||
|
||||
lastTitlebarClickAt = 0
|
||||
|
||||
event.preventDefault()
|
||||
await toggleMaximize()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await OS_READY
|
||||
const osName = getOS()
|
||||
@@ -123,8 +157,9 @@ onMounted(async () => {
|
||||
|
||||
<section class="flex min-w-0 flex-1 flex-col">
|
||||
<header
|
||||
class="flex h-12 shrink-0 items-center justify-between border-b border-slate-200 bg-white px-4 dark:border-slate-800 dark:bg-slate-900"
|
||||
class="flex h-12 shrink-0 select-none items-center justify-between border-b border-slate-200 bg-white px-4 dark:border-slate-800 dark:bg-slate-900"
|
||||
:class="isWindows ? 'drag-region' : ''"
|
||||
@mousedown="handleTitlebarMouseDown"
|
||||
>
|
||||
<div class="drag-area min-w-0">
|
||||
<p class="mb-0 truncate text-sm font-medium text-slate-700 dark:text-slate-200">
|
||||
@@ -132,7 +167,7 @@ onMounted(async () => {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="no-drag flex items-center gap-1">
|
||||
<div class="no-drag flex items-center gap-1" @dblclick.stop>
|
||||
<button class="toolbar-button" title="打开第二窗口" @click="OpenSecondWindow">
|
||||
<ExceptionOutlined />
|
||||
</button>
|
||||
@@ -163,12 +198,12 @@ onMounted(async () => {
|
||||
|
||||
<style scoped>
|
||||
.drag-region {
|
||||
-webkit-app-region: drag;
|
||||
-webkit-app-region: no-drag;
|
||||
--wails-draggable: drag;
|
||||
}
|
||||
|
||||
.drag-area {
|
||||
-webkit-app-region: drag;
|
||||
-webkit-app-region: no-drag;
|
||||
--wails-draggable: drag;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user