File size: 4,200 Bytes
7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e 2d7fc97 7bff52e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
<script lang="ts" setup>
import router from "@/router.ts";
import {watch, ref, onMounted, onUnmounted} from "vue";
import MinimizeIcon from "@/assets/icons/yellow.png"
import MaximizeIcon from "@/assets/icons/green.png"
import CloseIcon from "@/assets/icons/red.png"
import MinFocusIcon from "@/assets/icons/min.png"
import MaxFocusIcon from "@/assets/icons/max.png"
import CloseFocusIcon from "@/assets/icons/close.png"
// 修改electron的导入方式
let electronAPI: any = null;
// 检查是否在Electron环境中
// @ts-ignore
if (typeof window !== 'undefined' && window.electronAPI) {
// @ts-ignore
electronAPI = window.electronAPI;
}
// 添加窗口控制函数 - 使用contextBridge API
const minimizeWindow = () => {
if (electronAPI) {
// 通过preload脚本发送事件
// @ts-ignore
window.electronAPI?.minimizeWindow?.();
} else {
console.warn('Electron API not available');
}
}
const maximizeWindow = () => {
if (electronAPI) {
// @ts-ignore
window.electronAPI?.maximizeWindow?.();
} else {
console.warn('Electron API not available');
}
}
const closeWindow = () => {
if (electronAPI) {
// @ts-ignore
window.electronAPI?.closeWindow?.();
} else {
console.warn('Electron API not available');
}
}
</script>
<template>
<div class="header-nav">
<div class="window-controls">
<a-button type="link" size="small" @click="closeWindow" style="width:24px; height: 24px; padding: 0;">
<template #icon>
<img class="close-icon default" :src="CloseIcon" alt="close" style="width: 12px; height: 12px;">
<img class="close-icon focus" :src="CloseFocusIcon" alt="close-focus"
style="width: 12px; height: 12px;">
</template>
</a-button>
<a-button type="link" size="small" @click="minimizeWindow"
style="width:24px; height: 24px; padding: 0;">
<template #icon>
<img class="close-icon default" :src="MinimizeIcon" alt="min" style="width: 12px; height: 12px;">
<img class="close-icon focus" :src="MinFocusIcon" alt="min-focus"
style="width: 12px; height: 12px;">
</template>
</a-button>
<a-button type="link" size="small" @click="maximizeWindow"
style="width:24px; height: 24px; padding: 0;">
<template #icon>
<img class="close-icon default" :src="MaximizeIcon" alt="max" style="width: 12px; height: 12px;">
<img class="close-icon focus" :src="MaxFocusIcon" alt="max-focus"
style="width: 12px; height: 12px;">
</template>
</a-button>
</div>
</div>
</template>
<style scoped lang="scss">
.header-nav {
display: flex;
align-items: flex-start;
justify-content: space-between;
width: 100vw;
height: 40px;
align-items: center;
position: absolute;
top: 0;
left: 0;
z-index: 99;
-webkit-app-region: drag;
/* 整个header区域可拖拽 */
cursor: move;
/* 确保所有交互元素不可拖拽 */
.window-controls,
button,
.ant-input-search,
img,
.anticon {
-webkit-app-region: no-drag;
cursor: pointer;
}
.window-controls {
top: 0;
right: 0;
display: flex;
z-index: 1000;
margin-left: 12px;
.window-control-btn {
width: 46px;
height: 32px;
border: none;
background: transparent;
color: #666;
font-size: 16px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.2s;
&:hover {
background-color: rgba(0, 0, 0, 0.1);
}
&.close:hover {
background-color: #e81123;
color: white;
}
}
.close-icon.focus {
display: none;
}
&:hover .close-icon.default,
&:focus-within .close-icon.default {
display: none;
}
&:hover .close-icon.focus,
&:focus-within .close-icon.focus {
display: inline;
}
}
}
</style>
|