2023-12-18 19:39:36 +08:00
|
|
|
<template>
|
2024-01-02 22:19:39 +08:00
|
|
|
<div id="title-bar" @mousedown="drag">
|
2023-12-18 19:39:36 +08:00
|
|
|
<div id="title">Alger Music</div>
|
|
|
|
|
<div id="buttons">
|
|
|
|
|
<button @click="minimize">
|
|
|
|
|
<i class="iconfont icon-minisize"></i>
|
|
|
|
|
</button>
|
|
|
|
|
<button @click="close">
|
|
|
|
|
<i class="iconfont icon-close"></i>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-01-03 22:24:13 +08:00
|
|
|
|
|
|
|
|
<n-modal
|
|
|
|
|
v-model:show="showCloseModal"
|
|
|
|
|
preset="dialog"
|
|
|
|
|
title="关闭应用"
|
|
|
|
|
:style="{ width: '400px' }"
|
|
|
|
|
:mask-closable="true"
|
|
|
|
|
>
|
|
|
|
|
<div class="close-dialog-content">
|
|
|
|
|
<p>请选择关闭方式</p>
|
|
|
|
|
<div class="remember-choice">
|
|
|
|
|
<n-checkbox v-model:checked="rememberChoice">记住我的选择</n-checkbox>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<template #action>
|
|
|
|
|
<div class="dialog-footer">
|
|
|
|
|
<n-button type="primary" @click="handleAction('minimize')">最小化到托盘</n-button>
|
|
|
|
|
<n-button @click="handleAction('close')">退出应用</n-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</n-modal>
|
2023-12-18 19:39:36 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2025-01-03 22:24:13 +08:00
|
|
|
import { ref } from 'vue';
|
|
|
|
|
import { useStore } from 'vuex';
|
2025-01-10 22:49:55 +08:00
|
|
|
|
2025-01-01 02:25:18 +08:00
|
|
|
import { isElectron } from '@/utils';
|
2024-12-14 13:49:32 +08:00
|
|
|
|
2025-01-03 22:24:13 +08:00
|
|
|
const store = useStore();
|
|
|
|
|
const showCloseModal = ref(false);
|
|
|
|
|
const rememberChoice = ref(false);
|
2023-12-28 10:45:11 +08:00
|
|
|
|
2023-12-18 19:39:36 +08:00
|
|
|
const minimize = () => {
|
2025-01-01 02:25:18 +08:00
|
|
|
if (!isElectron) {
|
2024-12-14 13:49:32 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2025-01-01 02:25:18 +08:00
|
|
|
window.api.minimize();
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2023-12-18 19:39:36 +08:00
|
|
|
|
2025-01-03 22:24:13 +08:00
|
|
|
const handleAction = (action: 'minimize' | 'close') => {
|
|
|
|
|
if (rememberChoice.value) {
|
|
|
|
|
store.commit('setSetData', {
|
|
|
|
|
...store.state.setData,
|
|
|
|
|
closeAction: action
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-01-10 22:49:55 +08:00
|
|
|
|
2025-01-03 22:24:13 +08:00
|
|
|
if (action === 'minimize') {
|
|
|
|
|
window.api.miniTray();
|
|
|
|
|
} else {
|
|
|
|
|
window.api.close();
|
|
|
|
|
}
|
|
|
|
|
showCloseModal.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-18 19:39:36 +08:00
|
|
|
const close = () => {
|
2025-01-01 02:25:18 +08:00
|
|
|
if (!isElectron) {
|
2024-12-14 13:49:32 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2025-01-03 22:24:13 +08:00
|
|
|
|
2025-01-10 22:49:55 +08:00
|
|
|
const { closeAction } = store.state.setData;
|
|
|
|
|
|
2025-01-03 22:24:13 +08:00
|
|
|
if (closeAction === 'minimize') {
|
|
|
|
|
window.api.miniTray();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-01-10 22:49:55 +08:00
|
|
|
|
2025-01-03 22:24:13 +08:00
|
|
|
if (closeAction === 'close') {
|
|
|
|
|
window.api.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showCloseModal.value = true;
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2023-12-18 19:39:36 +08:00
|
|
|
|
2023-12-28 10:45:11 +08:00
|
|
|
const drag = (event: MouseEvent) => {
|
2025-01-01 02:25:18 +08:00
|
|
|
if (!isElectron) {
|
2024-12-14 13:49:32 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2025-01-01 02:25:18 +08:00
|
|
|
window.api.dragStart(event as unknown as string);
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2023-12-18 19:39:36 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
#title-bar {
|
|
|
|
|
-webkit-app-region: drag;
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply flex justify-between px-6 py-2 select-none relative;
|
|
|
|
|
@apply text-dark dark:text-white;
|
2023-12-18 19:39:36 +08:00
|
|
|
z-index: 9999999;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#buttons {
|
|
|
|
|
@apply flex gap-4;
|
|
|
|
|
-webkit-app-region: no-drag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
button {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply text-gray-600 dark:text-gray-400 hover:text-green-500;
|
2023-12-18 19:39:36 +08:00
|
|
|
}
|
2025-01-03 22:24:13 +08:00
|
|
|
|
|
|
|
|
.close-dialog-content {
|
|
|
|
|
@apply flex flex-col gap-4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.dialog-footer {
|
|
|
|
|
@apply flex gap-4 justify-end;
|
|
|
|
|
}
|
2023-12-18 19:39:36 +08:00
|
|
|
</style>
|