Files
AlgerMusicPlayer/src/renderer/layout/components/TitleBar.vue
T

146 lines
3.2 KiB
Vue
Raw Normal View History

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">
2025-03-09 19:34:05 +08:00
<n-button
v-if="!isElectron"
type="primary"
size="small"
text
title="下载应用"
@click="openDownloadPage"
>
<i class="ri-download-line"></i>
下载桌面版
</n-button>
<template v-if="isElectron">
<div class="button" @click="minimize">
<i class="iconfont icon-minisize"></i>
</div>
<div class="button" @click="close">
<i class="iconfont icon-close"></i>
</div>
</template>
2023-12-18 19:39:36 +08:00
</div>
</div>
<n-modal
v-model:show="showCloseModal"
preset="dialog"
title="关闭应用"
:style="{ width: '400px' }"
:mask-closable="true"
>
<div class="close-dialog-content">
2025-02-19 01:01:43 +08:00
<p>{{ t('comp.titleBar.closeTitle') }}</p>
<div class="remember-choice">
2025-02-19 01:01:43 +08:00
<n-checkbox v-model:checked="rememberChoice">
{{ t('comp.titleBar.rememberChoice') }}
</n-checkbox>
</div>
</div>
<template #action>
<div class="dialog-footer">
2025-02-19 01:01:43 +08:00
<n-button type="primary" @click="handleAction('minimize')">
{{ t('comp.titleBar.minimizeToTray') }}
</n-button>
<n-button @click="handleAction('close')">
{{ t('comp.titleBar.exitApp') }}
</n-button>
</div>
</template>
</n-modal>
2023-12-18 19:39:36 +08:00
</template>
<script setup lang="ts">
import { ref } from 'vue';
2025-02-19 01:31:19 +08:00
import { useI18n } from 'vue-i18n';
2025-01-10 22:49:55 +08:00
2025-03-19 22:48:28 +08:00
import { useSettingsStore } from '@/store/modules/settings';
import { isElectron } from '@/utils';
2025-02-19 01:31:19 +08:00
const { t } = useI18n();
2025-03-19 22:48:28 +08:00
const settingsStore = useSettingsStore();
const showCloseModal = ref(false);
const rememberChoice = ref(false);
2023-12-28 10:45:11 +08:00
2025-03-09 19:34:05 +08:00
const openDownloadPage = () => {
if (!isElectron) {
window.open('http://donate.alger.fun/download', '_blank');
}
};
2023-12-18 19:39:36 +08:00
const minimize = () => {
if (!isElectron) {
return;
}
window.api.minimize();
};
2023-12-18 19:39:36 +08:00
const handleAction = (action: 'minimize' | 'close') => {
if (rememberChoice.value) {
2025-03-19 22:48:28 +08:00
settingsStore.setSettings({
...settingsStore.setData,
closeAction: action
});
}
2025-01-10 22:49:55 +08:00
if (action === 'minimize') {
2025-03-19 22:48:28 +08:00
window.api.minimize();
} else {
window.api.close();
}
showCloseModal.value = false;
};
2025-03-19 22:48:28 +08:00
const handleClose = () => {
const { closeAction } = settingsStore.setData;
2025-01-10 22:49:55 +08:00
if (closeAction === 'minimize') {
2025-03-19 22:48:28 +08:00
window.api.minimize();
} else if (closeAction === 'close') {
window.api.close();
2025-03-19 22:48:28 +08:00
} else {
showCloseModal.value = true;
}
};
2023-12-18 19:39:36 +08:00
2023-12-28 10:45:11 +08:00
const drag = (event: MouseEvent) => {
if (!isElectron) {
return;
}
window.api.dragStart(event as unknown as string);
};
2025-03-19 22:48:28 +08:00
const handleThemeChange = () => {
settingsStore.toggleTheme();
};
2023-12-18 19:39:36 +08:00
</script>
<style scoped lang="scss">
#title-bar {
-webkit-app-region: drag;
@apply flex justify-between px-6 py-2 select-none relative;
@apply text-dark dark:text-white;
2025-01-13 22:55:46 +08:00
z-index: 3000;
2023-12-18 19:39:36 +08:00
}
#buttons {
@apply flex gap-4;
-webkit-app-region: no-drag;
}
.button {
@apply text-gray-600 dark:text-gray-400 hover:text-green-500;
2023-12-18 19:39:36 +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>