feat: 优化页面样式边距

This commit is contained in:
alger
2026-02-08 01:39:20 +08:00
parent e53a035ebc
commit ae20f78ec0
34 changed files with 1201 additions and 2107 deletions
+45 -82
View File
@@ -1,7 +1,7 @@
<template>
<div class="eq-control">
<div class="eq-header">
<h3>
<div class="eq-control p-6 rounded-lg bg-gray-100 dark:bg-gray-900 w-full max-w-[700px]">
<div class="eq-header flex justify-between items-center mb-4">
<h3 class="text-xl font-semibold text-gray-800 dark:text-gray-200">
{{ t('player.eq.title') }}
<n-tag type="warning" size="small" round v-if="!isElectron">
桌面版可用网页端不支持
@@ -15,7 +15,7 @@
</div>
</div>
<div class="eq-presets">
<div class="eq-presets mb-2 relative h-10">
<n-scrollbar x-scrollable>
<n-space :size="6" :wrap="false">
<n-tag
@@ -34,9 +34,19 @@
</n-scrollbar>
</div>
<div class="eq-sliders">
<div v-for="freq in frequencies" :key="freq" class="eq-slider">
<div class="freq-label">{{ formatFreq(freq) }}</div>
<div
class="eq-sliders flex justify-between items-end bg-gray-50 dark:bg-gray-800 gap-1 rounded-lg p-2 h-[300px]"
>
<div
v-for="freq in frequencies"
:key="freq"
class="eq-slider flex flex-col items-center w-[45px] h-full"
>
<div
class="freq-label text-xs font-medium text-center text-gray-600 dark:text-gray-400 whitespace-nowrap m-2 h-5"
>
{{ formatFreq(freq) }}
</div>
<n-slider
v-model:value="eqValues[freq.toString()]"
:min="-12"
@@ -45,8 +55,13 @@
vertical
:disabled="!isEnabled"
@update:value="updateEQ(freq.toString(), $event)"
class="flex-1 my-3 min-h-[180px]"
/>
<div class="gain-value">{{ eqValues[freq.toString()] }}dB</div>
<div
class="gain-value text-xs font-medium text-center text-gray-600 dark:text-gray-400 whitespace-nowrap my-1 h-4"
>
{{ eqValues[freq.toString()] }}dB
</div>
</div>
</div>
</div>
@@ -267,91 +282,39 @@ const formatFreq = (freq: number) => {
</script>
<style lang="scss" scoped>
.eq-control {
@apply p-6 rounded-lg;
@apply bg-light dark:bg-dark;
width: 100%;
max-width: 700px;
:deep(.n-scrollbar) {
margin-left: -0.5rem;
margin-right: -0.5rem;
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.eq-header {
@apply flex justify-between items-center mb-4;
:deep(.n-tag) {
cursor: pointer;
transition: all 0.2s;
text-align: center;
h3 {
@apply text-xl font-semibold;
@apply text-gray-800 dark:text-gray-200;
}
&:hover {
transform: translateY(-2px);
}
}
.eq-presets {
@apply mb-2 relative;
height: 40px;
:deep(.n-scrollbar) {
@apply -mx-2 px-2;
}
:deep(.n-tag) {
@apply cursor-pointer transition-all duration-200;
text-align: center;
&:hover {
transform: translateY(-2px);
}
}
:deep(.n-space) {
flex-wrap: nowrap;
padding: 4px 0;
}
}
.eq-sliders {
@apply flex justify-between items-end;
@apply bg-gray-50 dark:bg-gray-800 gap-1;
@apply rounded-lg p-2;
height: 300px;
.eq-slider {
@apply flex flex-col items-center;
width: 45px;
height: 100%;
.n-slider {
flex: 1;
margin: 12px 0;
min-height: 180px;
}
.freq-label {
@apply text-xs font-medium text-center;
@apply text-gray-600 dark:text-gray-400;
white-space: nowrap;
margin: 8px 0;
height: 20px;
}
.gain-value {
@apply text-xs font-medium text-center;
@apply text-gray-600 dark:text-gray-400;
white-space: nowrap;
margin: 4px 0;
height: 16px;
}
}
}
:deep(.n-space) {
flex-wrap: nowrap;
padding: 4px 0;
}
:deep(.n-slider) {
--n-rail-height: 4px;
--n-rail-color: theme('colors.gray.200');
--n-rail-color-hover: theme('colors.gray.300');
--n-fill-color: theme('colors.green.500');
--n-fill-color-hover: theme('colors.green.600');
--n-handle-color: theme('colors.green.500');
--n-rail-color: #e5e7eb;
--n-rail-color-hover: #d1d5db;
--n-fill-color: #22c55e;
--n-fill-color-hover: #16a34a;
--n-handle-color: #22c55e;
--n-handle-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
.n-slider-handle {
@apply transition-all duration-200;
transition: all 0.2s;
&:hover {
transform: scale(1.2);
}
-729
View File
@@ -1,729 +0,0 @@
<template>
<n-drawer
:show="show"
:height="isMobile ? '100%' : '80%'"
placement="bottom"
block-scroll
mask-closable
:style="{ backgroundColor: 'transparent' }"
:to="`#layout-main`"
:z-index="zIndex"
@mask-click="close"
>
<div class="music-page">
<div class="music-header h-12 flex items-center justify-between">
<n-ellipsis :line-clamp="1" class="flex-shrink-0 mr-3">
<div class="music-title">
{{ name }}
</div>
</n-ellipsis>
<!-- 搜索框 -->
<div class="flex-grow flex-1 flex items-center justify-end">
<div class="search-container">
<n-input
v-model:value="searchKeyword"
:placeholder="t('comp.musicList.searchSongs')"
clearable
round
size="small"
>
<template #prefix>
<i class="icon iconfont ri-search-line text-sm"></i>
</template>
</n-input>
</div>
</div>
<div class="music-close flex-shrink-0 ml-3">
<i class="icon iconfont ri-close-line" @click="close"></i>
</div>
</div>
<div class="music-content">
<!-- 左侧歌单信息 -->
<div class="music-info">
<div class="music-cover">
<n-image
:src="getCoverImgUrl"
class="cover-img"
preview-disabled
:class="setAnimationClass('animate__fadeIn')"
object-fit="cover"
/>
</div>
<div v-if="listInfo?.creator" class="creator-info">
<n-avatar round :size="24" :src="getImgUrl(listInfo.creator.avatarUrl, '50y50')" />
<span class="creator-name">{{ listInfo.creator.nickname }}</span>
</div>
<div v-if="total" class="music-total">{{ t('player.songNum', { num: total }) }}</div>
<n-scrollbar style="max-height: 200px">
<div v-if="listInfo?.description" class="music-desc">
{{ listInfo.description }}
</div>
</n-scrollbar>
</div>
<!-- 右侧歌曲列表 -->
<div class="music-list-container">
<div class="music-list">
<n-spin :show="loadingList || loading">
<div class="music-list-content">
<div v-if="filteredSongs.length === 0 && searchKeyword" class="no-result">
{{ t('comp.musicList.noSearchResults') }}
</div>
<!-- 虚拟列表设置正确的固定高度 -->
<n-virtual-list
ref="songListRef"
class="song-virtual-list"
style="height: calc(70vh - 60px)"
:items="filteredSongs"
:item-size="70"
item-resizable
key-field="id"
@scroll="handleVirtualScroll"
>
<template #default="{ item }">
<div class="double-item">
<song-item
:item="formatSong(item)"
:can-remove="canRemove"
@play="handlePlay"
@remove-song="(id) => emit('remove-song', id)"
/>
</div>
</template>
</n-virtual-list>
</div>
</n-spin>
</div>
<play-bottom />
</div>
</div>
</div>
</n-drawer>
</template>
<script setup lang="ts">
import PinyinMatch from 'pinyin-match';
import { computed, onUnmounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { getMusicDetail } from '@/api/music';
import SongItem from '@/components/common/SongItem.vue';
import { usePlayerStore } from '@/store/modules/player';
import { SongResult } from '@/types/music';
import { getImgUrl, isMobile, setAnimationClass } from '@/utils';
import PlayBottom from './common/PlayBottom.vue';
const { t } = useI18n();
const playerStore = usePlayerStore();
const props = withDefaults(
defineProps<{
show: boolean;
name: string;
zIndex?: number;
songList: any[];
loading?: boolean;
listInfo?: {
trackIds: { id: number }[];
[key: string]: any;
};
cover?: boolean;
canRemove?: boolean;
}>(),
{
loading: false,
cover: true,
zIndex: 9996,
canRemove: false
}
);
const emit = defineEmits(['update:show', 'update:loading', 'remove-song']);
const page = ref(0);
const pageSize = 40;
const isLoadingMore = ref(false);
const displayedSongs = ref<SongResult[]>([]);
const loadingList = ref(false);
const loadedIds = ref(new Set<number>()); // 用于追踪已加载的歌曲ID
const isPlaylistLoading = ref(false); // 标记是否正在加载播放列表
const completePlaylist = ref<SongResult[]>([]); // 存储完整的播放列表
const hasMore = ref(true); // 标记是否还有更多数据可加载
const searchKeyword = ref(''); // 搜索关键词
const isFullPlaylistLoaded = ref(false); // 标记完整播放列表是否已加载完成
// 计算总数
const total = computed(() => {
if (props.listInfo?.trackIds) {
return props.listInfo.trackIds.length;
}
return props.songList.length;
});
const getCoverImgUrl = computed(() => {
if (props.listInfo?.coverImgUrl) {
return props.listInfo.coverImgUrl;
}
const song = props.songList[0];
if (song?.picUrl) {
return song.picUrl;
}
if (song?.al?.picUrl) {
return song.al.picUrl;
}
if (song?.album?.picUrl) {
return song.album.picUrl;
}
return '';
});
// 过滤歌曲列表
const filteredSongs = computed(() => {
if (!searchKeyword.value) {
return displayedSongs.value;
}
const keyword = searchKeyword.value.toLowerCase().trim();
return displayedSongs.value.filter((song) => {
const songName = song.name?.toLowerCase() || '';
const albumName = song.al?.name?.toLowerCase() || '';
const artists = song.ar || song.artists || [];
// 原始文本匹配
const nameMatch = songName.includes(keyword);
const albumMatch = albumName.includes(keyword);
const artistsMatch = artists.some((artist: any) => {
return artist.name?.toLowerCase().includes(keyword);
});
// 拼音匹配
const namePinyinMatch = song.name && PinyinMatch.match(song.name, keyword);
const albumPinyinMatch = song.al?.name && PinyinMatch.match(song.al.name, keyword);
const artistsPinyinMatch = artists.some((artist: any) => {
return artist.name && PinyinMatch.match(artist.name, keyword);
});
return (
nameMatch ||
albumMatch ||
artistsMatch ||
namePinyinMatch ||
albumPinyinMatch ||
artistsPinyinMatch
);
});
});
// 格式化歌曲数据
const formatSong = (item: any) => {
if (!item) {
return null;
}
return {
...item,
picUrl: item.al?.picUrl || item.picUrl,
song: {
artists: item.ar || item.artists,
name: item.al?.name || item.name,
id: item.al?.id || item.id
}
};
};
/**
* 加载歌曲数据的核心函数
* @param ids 要加载的歌曲ID数组
* @param appendToList 是否将加载的歌曲追加到现有列表
* @param updateComplete 是否更新完整播放列表
*/
const loadSongs = async (ids: number[], appendToList = true, updateComplete = false) => {
if (ids.length === 0) return [];
try {
console.log(`请求歌曲详情,ID数量: ${ids.length}`);
const { data } = await getMusicDetail(ids);
if (data?.songs) {
console.log(`API返回歌曲数量: ${data.songs.length}`);
// 直接使用API返回的所有歌曲,不再过滤已加载的歌曲
// 因为当需要完整加载列表时,我们希望获取所有歌曲,即使ID可能重复
const { songs } = data;
// 只在非更新完整列表时执行过滤
let newSongs = songs;
if (!updateComplete) {
// 在普通加载模式下继续过滤已加载的歌曲,避免重复
newSongs = songs.filter((song: any) => !loadedIds.value.has(song.id));
console.log(`过滤已加载ID后剩余歌曲数量: ${newSongs.length}`);
}
// 更新已加载ID集合
songs.forEach((song: any) => {
loadedIds.value.add(song.id);
});
// 追加到显示列表 - 仅当appendToList=true时添加到displayedSongs
if (appendToList) {
displayedSongs.value.push(...newSongs);
}
// 更新完整播放列表 - 仅当updateComplete=true时添加到completePlaylist
if (updateComplete) {
completePlaylist.value.push(...songs);
console.log(`已添加到完整播放列表,当前完整列表长度: ${completePlaylist.value.length}`);
}
return updateComplete ? songs : newSongs;
}
console.log('API返回无歌曲数据');
return [];
} catch (error) {
console.error('加载歌曲失败:', error);
}
return [];
};
// 加载完整播放列表
const loadFullPlaylist = async () => {
if (isPlaylistLoading.value || isFullPlaylistLoaded.value) return;
isPlaylistLoading.value = true;
// 记录开始时间
const startTime = Date.now();
console.log(`开始加载完整播放列表,当前显示列表长度: ${displayedSongs.value.length}`);
try {
// 如果没有trackIds,直接使用当前歌曲列表并标记为已完成
if (!props.listInfo?.trackIds) {
isFullPlaylistLoaded.value = true;
console.log('无trackIds信息,使用当前列表作为完整列表');
return;
}
// 获取所有trackIds
const allIds = props.listInfo.trackIds.map((item) => item.id);
console.log(`歌单共有歌曲ID: ${allIds.length}首`);
// 重置completePlaylist和当前显示歌曲ID集合,保证不会重复添加歌曲
completePlaylist.value = [];
// 使用Set记录所有已加载的歌曲ID
const loadedSongIds = new Set<number>();
// 将当前显示列表中的歌曲和ID添加到集合中
displayedSongs.value.forEach((song) => {
loadedSongIds.add(song.id as number);
// 将已有歌曲添加到completePlaylist
completePlaylist.value.push(song);
});
console.log(
`已有显示歌曲: ${displayedSongs.value.length}首,已有ID数量: ${loadedSongIds.size}`
);
// 过滤出尚未加载的歌曲ID
const unloadedIds = allIds.filter((id) => !loadedSongIds.has(id));
console.log(`还需要加载的歌曲ID数量: ${unloadedIds.length}`);
if (unloadedIds.length === 0) {
console.log('所有歌曲已加载,无需再次加载');
isFullPlaylistLoaded.value = true;
hasMore.value = false;
return;
}
// 分批加载所有未加载的歌曲
const batchSize = 500; // 每批加载的歌曲数量
for (let i = 0; i < unloadedIds.length; i += batchSize) {
const batchIds = unloadedIds.slice(i, i + batchSize);
if (batchIds.length === 0) continue;
console.log(`请求第${Math.floor(i / batchSize) + 1}批歌曲,数量: ${batchIds.length}`);
// 关键修改: 设置appendToList为false,避免loadSongs直接添加到displayedSongs
const loadedBatch = await loadSongs(batchIds, false, false);
// 添加新加载的歌曲到displayedSongs
if (loadedBatch.length > 0) {
// 过滤掉已有的歌曲,确保不会重复添加
const newSongs = loadedBatch.filter((song) => !loadedSongIds.has(song.id as number));
// 更新已加载ID集合
newSongs.forEach((song) => {
loadedSongIds.add(song.id as number);
});
console.log(`新增${newSongs.length}首歌曲到显示列表`);
// 更新显示列表和完整播放列表
if (newSongs.length > 0) {
// 添加到显示列表
displayedSongs.value = [...displayedSongs.value, ...newSongs];
// 添加到完整播放列表
completePlaylist.value.push(...newSongs);
// 如果当前正在播放的列表与这个列表匹配,实时更新播放列表
const currentPlaylist = playerStore.playList;
if (currentPlaylist.length > 0 && currentPlaylist[0].id === displayedSongs.value[0]?.id) {
console.log('实时更新当前播放列表');
playerStore.setPlayList(displayedSongs.value.map(formatSong));
}
}
}
// 添加小延迟避免请求过于密集
if (i + batchSize < unloadedIds.length) {
await new Promise<void>((resolve) => {
setTimeout(() => resolve(), 100);
});
}
}
// 加载完成,更新状态
isFullPlaylistLoaded.value = true;
hasMore.value = false;
// 计算加载耗时
const endTime = Date.now();
const timeUsed = Math.round(((endTime - startTime) / 1000) * 100) / 100;
console.log(
`完整播放列表加载完成,共加载${displayedSongs.value.length}首歌曲,耗时${timeUsed}秒`
);
console.log(`歌单应有${allIds.length}首歌,实际加载${displayedSongs.value.length}首`);
// 检查加载的歌曲数量是否与预期相符
if (displayedSongs.value.length !== allIds.length) {
console.warn(
`警告: 加载的歌曲数量(${displayedSongs.value.length})与歌单应有数量(${allIds.length})不符`
);
// 如果数量不符,可能是API未返回所有歌曲,打印缺失的歌曲ID
if (displayedSongs.value.length < allIds.length) {
const loadedIds = new Set(displayedSongs.value.map((song) => song.id));
const missingIds = allIds.filter((id) => !loadedIds.has(id));
console.warn(`缺失的歌曲ID: ${missingIds.join(', ')}`);
}
}
} catch (error) {
console.error('加载完整播放列表失败:', error);
} finally {
isPlaylistLoading.value = false;
}
};
// 处理播放
const handlePlay = async () => {
// 当搜索状态下播放时,只播放过滤后的歌曲
if (searchKeyword.value) {
playerStore.setPlayList(filteredSongs.value.map(formatSong));
return;
}
// 如果完整播放列表已加载完成
if (isFullPlaylistLoaded.value && completePlaylist.value.length > 0) {
playerStore.setPlayList(completePlaylist.value.map(formatSong));
return;
}
// 如果完整播放列表未加载完成,先使用当前已加载的歌曲开始播放
playerStore.setPlayList(displayedSongs.value.map(formatSong));
// 如果完整播放列表正在加载中,不需要重新触发加载
if (isPlaylistLoading.value) {
return;
}
// 在后台继续加载完整播放列表(如果未加载完成)
if (!isFullPlaylistLoaded.value) {
console.log('播放时继续在后台加载完整列表');
loadFullPlaylist();
}
};
const close = () => {
emit('update:show', false);
};
// 加载更多歌曲
const loadMoreSongs = async () => {
if (isFullPlaylistLoaded.value) {
hasMore.value = false;
return;
}
if (searchKeyword.value) {
return;
}
if (isLoadingMore.value || displayedSongs.value.length >= total.value) {
hasMore.value = false;
return;
}
isLoadingMore.value = true;
try {
const start = displayedSongs.value.length;
const end = Math.min(start + pageSize, total.value);
if (props.listInfo?.trackIds) {
const trackIdsToLoad = props.listInfo.trackIds
.slice(start, end)
.map((item) => item.id)
.filter((id) => !loadedIds.value.has(id));
if (trackIdsToLoad.length > 0) {
await loadSongs(trackIdsToLoad, true, false);
}
} else if (start < props.songList.length) {
const newSongs = props.songList.slice(start, end);
newSongs.forEach((song) => {
if (!loadedIds.value.has(song.id)) {
loadedIds.value.add(song.id);
displayedSongs.value.push(song);
}
});
}
hasMore.value = displayedSongs.value.length < total.value;
} catch (error) {
console.error('加载更多歌曲失败:', error);
} finally {
isLoadingMore.value = false;
loadingList.value = false;
}
};
// 处理虚拟列表滚动事件
const handleVirtualScroll = (e: any) => {
if (!e || !e.target) return;
const { scrollTop, scrollHeight, clientHeight } = e.target;
const threshold = 200;
if (
scrollHeight - scrollTop - clientHeight < threshold &&
!isLoadingMore.value &&
hasMore.value &&
!searchKeyword.value // 搜索状态下不触发加载更多
) {
loadMoreSongs();
}
};
// 重置列表状态
const resetListState = () => {
page.value = 0;
loadedIds.value.clear();
displayedSongs.value = [];
completePlaylist.value = [];
hasMore.value = true;
loadingList.value = false;
searchKeyword.value = ''; // 重置搜索关键词
isFullPlaylistLoaded.value = false; // 重置完整播放列表状态
};
// 初始化歌曲列表
const initSongList = (songs: any[]) => {
if (songs.length > 0) {
displayedSongs.value = [...songs];
songs.forEach((song) => loadedIds.value.add(song.id));
page.value = Math.ceil(songs.length / pageSize);
}
// 检查是否还有更多数据可加载
hasMore.value = displayedSongs.value.length < total.value;
};
watch(
() => props.listInfo,
(newListInfo) => {
if (newListInfo?.trackIds) {
loadFullPlaylist();
}
},
{ deep: true }
);
// 修改 songList 监听器
watch(
() => props.songList,
(newSongs) => {
// 重置所有状态
resetListState();
// 初始化歌曲列表
initSongList(newSongs);
// 如果还有更多歌曲需要加载,且差距较小,立即加载
if (hasMore.value && props.listInfo?.trackIds) {
setTimeout(() => {
loadMoreSongs();
}, 300);
}
},
{ immediate: true }
);
// 监听搜索关键词变化
watch(searchKeyword, () => {
// 当搜索关键词为空时,考虑加载更多歌曲
if (!searchKeyword.value && hasMore.value && displayedSongs.value.length < total.value) {
loadMoreSongs();
}
});
// 组件卸载时清理状态
onUnmounted(() => {
isPlaylistLoading.value = false;
});
</script>
<style scoped lang="scss">
.music {
&-title {
@apply text-xl font-bold text-gray-900 dark:text-white;
}
&-total {
@apply text-sm font-normal text-gray-500 dark:text-gray-400;
}
&-page {
@apply px-8 w-full h-full bg-light dark:bg-black bg-opacity-75 dark:bg-opacity-75 rounded-t-2xl;
backdrop-filter: blur(20px);
}
&-close {
@apply cursor-pointer text-gray-500 dark:text-white hover:text-gray-900 dark:hover:text-gray-300 flex gap-2 items-center transition;
.icon {
@apply text-3xl;
}
}
&-content {
@apply flex h-[calc(100%-60px)];
}
&-info {
@apply w-[25%] flex-shrink-0 pr-8 flex flex-col;
.music-cover {
@apply w-full aspect-square rounded-2xl overflow-hidden mb-4 min-h-[250px];
.cover-img {
@apply w-full h-full object-cover;
}
}
.creator-info {
@apply flex items-center mb-4;
.creator-name {
@apply ml-2 text-gray-700 dark:text-gray-300;
}
}
.music-desc {
@apply text-sm text-gray-600 dark:text-gray-400 leading-relaxed pr-4;
}
}
&-list {
@apply flex-grow min-h-0;
&-container {
@apply flex-grow min-h-0 flex flex-col relative;
}
&-content {
@apply min-h-[calc(80vh-60px)];
}
}
}
.search-container {
@apply max-w-md;
:deep(.n-input) {
@apply bg-light-200 dark:bg-dark-200;
}
.icon {
@apply text-gray-500 dark:text-gray-400;
}
}
.no-result {
@apply text-center py-8 text-gray-500 dark:text-gray-400;
}
/* 虚拟列表样式 */
.song-virtual-list {
:deep(.n-virtual-list__scroll) {
scrollbar-width: thin;
&::-webkit-scrollbar {
width: 4px;
}
&::-webkit-scrollbar-thumb {
@apply bg-gray-400 dark:bg-gray-600 rounded;
}
}
}
.mobile {
.music-page {
@apply px-4;
}
.music-content {
@apply flex-col;
width: 100vw !important;
}
.music-info {
@apply w-full pr-0 mb-2 flex flex-row;
.music-cover {
@apply w-[100px] h-[100px] rounded-lg overflow-hidden mb-4;
}
.music-detail {
@apply flex-1 ml-4;
}
}
.music-title {
@apply text-base;
}
.search-container {
@apply max-w-[50%];
}
.song-virtual-list {
height: calc(80vh - 120px) !important;
}
}
.loading-more {
@apply text-center py-4 text-gray-500 dark:text-gray-400;
}
.double-item {
@apply mb-2 bg-light-100 bg-opacity-20 dark:bg-dark-100 dark:bg-opacity-20 rounded-3xl;
}
.mobile {
.music-info {
@apply hidden;
}
.music-list-content {
@apply pb-[100px];
}
}
</style>
@@ -3,10 +3,7 @@
class="category-selector border-b border-gray-100 dark:border-gray-800 bg-white dark:bg-black z-10"
>
<n-scrollbar ref="scrollbarRef" x-scrollable>
<div
class="categories-wrapper py-4 px-4 sm:px-6 lg:px-8 lg:pl-0"
@wheel.prevent="handleWheel"
>
<div class="categories-wrapper py-4 page-padding" @wheel.prevent="handleWheel">
<span
v-for="(category, index) in categories"
:key="getItemKey(category, index)"
+105 -204
View File
@@ -1,104 +1,140 @@
<template>
<n-drawer
:show="modelValue"
:width="400"
:width="420"
placement="right"
@update:show="$emit('update:modelValue', $event)"
:unstable-show-mask="false"
:show-mask="false"
>
<n-drawer-content :title="t('comp.playlistDrawer.title')" class="mac-style-drawer">
<n-drawer-content class="!p-0">
<template #header>
<div class="flex items-center gap-3">
<h2 class="text-lg font-bold tracking-tight text-neutral-900 dark:text-white">
{{ t('comp.playlistDrawer.title') }}
</h2>
<div class="h-1.5 w-1.5 rounded-full bg-primary" />
</div>
</template>
<n-scrollbar class="h-full">
<div class="playlist-drawer">
<!-- 创建新歌单按钮和表单 -->
<div class="create-playlist-section">
<div
class="create-playlist-button"
:class="{ 'is-expanded': isCreating }"
<div class="flex flex-col gap-5 px-5 py-4">
<!-- 创建新歌单 -->
<div class="flex flex-col">
<button
class="flex items-center gap-4 rounded-2xl p-3 transition-all duration-200"
:class="
isCreating
? 'bg-neutral-100 dark:bg-neutral-800'
: 'bg-neutral-50 hover:bg-neutral-100 dark:bg-neutral-800/50 dark:hover:bg-neutral-800'
"
@click="toggleCreateForm"
>
<div class="create-playlist-icon">
<i class="iconfont" :class="isCreating ? 'ri-close-line' : 'ri-add-line'"></i>
<div
class="flex h-11 w-11 items-center justify-center rounded-xl bg-primary text-white shadow-lg shadow-primary/25 transition-transform duration-300"
:class="{ 'rotate-45': isCreating }"
>
<i class="iconfont text-xl" :class="isCreating ? 'ri-close-line' : 'ri-add-line'" />
</div>
<div class="create-playlist-text">
<span class="text-sm font-semibold text-neutral-700 dark:text-neutral-200">
{{
isCreating
? t('comp.playlistDrawer.cancelCreate')
: t('comp.playlistDrawer.createPlaylist')
}}
</div>
</div>
</span>
</button>
<!-- 创建歌单表单 -->
<div class="create-playlist-form" :class="{ 'is-visible': isCreating }">
<n-input
v-model:value="formValue.name"
:placeholder="t('comp.playlistDrawer.playlistName')"
maxlength="40"
class="mac-style-input"
:status="inputError ? 'error' : undefined"
>
<template #prefix>
<i class="iconfont ri-music-2-line"></i>
</template>
</n-input>
<div class="privacy-switch">
<div class="privacy-label">
<i
class="iconfont"
:class="formValue.privacy ? 'ri-lock-line' : 'ri-earth-line'"
></i>
<span>{{
formValue.privacy
? t('comp.playlistDrawer.privatePlaylist')
: t('comp.playlistDrawer.publicPlaylist')
}}</span>
<div
class="overflow-hidden transition-all duration-300 ease-in-out"
:class="isCreating ? 'mt-4 max-h-[200px] opacity-100' : 'max-h-0 opacity-0'"
>
<div class="flex flex-col gap-4 px-1">
<n-input
v-model:value="formValue.name"
:placeholder="t('comp.playlistDrawer.playlistName')"
maxlength="40"
round
:status="inputError ? 'error' : undefined"
>
<template #prefix>
<i class="iconfont ri-music-2-line text-neutral-400" />
</template>
</n-input>
<div class="flex items-center justify-between px-1">
<div class="flex items-center gap-2.5">
<i
class="iconfont text-base"
:class="
formValue.privacy
? 'ri-lock-line text-primary'
: 'ri-earth-line text-neutral-400 dark:text-neutral-500'
"
/>
<span class="text-sm font-medium text-neutral-600 dark:text-neutral-300">
{{
formValue.privacy
? t('comp.playlistDrawer.privatePlaylist')
: t('comp.playlistDrawer.publicPlaylist')
}}
</span>
</div>
<n-switch v-model:value="formValue.privacy">
<template #checked>{{ t('comp.playlistDrawer.private') }}</template>
<template #unchecked>{{ t('comp.playlistDrawer.public') }}</template>
</n-switch>
</div>
<n-switch v-model:value="formValue.privacy" class="mac-style-switch">
<template #checked>{{ t('comp.playlistDrawer.private') }}</template>
<template #unchecked>{{ t('comp.playlistDrawer.public') }}</template>
</n-switch>
</div>
<div class="form-actions">
<n-button
type="primary"
quaternary
class="mac-style-button"
:loading="creating"
:disabled="!formValue.name"
<button
class="flex w-full items-center justify-center gap-2 rounded-full bg-primary px-6 py-2.5 text-sm font-semibold text-white shadow-lg shadow-primary/25 transition-all duration-200 hover:bg-primary/90 hover:scale-[1.02] active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed"
:disabled="!formValue.name || creating"
@click="handleCreatePlaylist"
>
{{ t('comp.playlistDrawer.create') }}
</n-button>
<n-spin v-if="creating" :size="14" />
<span>{{ t('comp.playlistDrawer.create') }}</span>
</button>
</div>
</div>
</div>
<!-- 歌单列表 -->
<div class="playlist-list">
<div class="flex flex-col gap-1.5 pb-32">
<div
v-for="playlist in playlists"
v-for="(playlist, index) in playlists"
:key="playlist.id"
class="playlist-item"
class="group flex cursor-pointer items-center gap-3.5 rounded-2xl p-2.5 transition-all duration-200 hover:bg-neutral-50 active:scale-[0.98] dark:hover:bg-neutral-800/60"
:style="{ animationDelay: `${index * 0.03}s` }"
@click="handleAddToPlaylist(playlist)"
>
<n-image
:src="getImgUrl(playlist.coverImgUrl || playlist.picUrl, '100y100')"
class="playlist-item-img"
preview-disabled
:img-props="{
crossorigin: 'anonymous'
}"
/>
<div class="playlist-item-info">
<div class="playlist-item-name">{{ playlist.name }}</div>
<div class="playlist-item-count">
{{ playlist.trackCount }}
{{ t('comp.playlistDrawer.count') }}
<!-- 封面 -->
<div
class="relative h-12 w-12 flex-shrink-0 overflow-hidden rounded-xl bg-neutral-100 shadow-sm dark:bg-neutral-800"
>
<n-image
:src="getImgUrl(playlist.coverImgUrl || playlist.picUrl, '100y100')"
class="h-full w-full object-cover"
preview-disabled
:img-props="{ crossorigin: 'anonymous' }"
/>
</div>
<!-- 信息 -->
<div class="min-w-0 flex-1">
<div class="truncate text-sm font-semibold text-neutral-800 dark:text-neutral-100">
{{ playlist.name }}
</div>
<div class="mt-0.5 text-xs font-medium text-neutral-400 dark:text-neutral-500">
{{ playlist.trackCount }} {{ t('comp.playlistDrawer.count') }}
</div>
</div>
<div class="playlist-item-action">
<i class="iconfont ri-add-line"></i>
<!-- 添加按钮 -->
<div
class="flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-neutral-300 transition-all duration-200 group-hover:bg-primary/10 group-hover:text-primary dark:text-neutral-600 dark:group-hover:text-primary"
>
<i class="iconfont ri-add-line text-xl" />
</div>
</div>
</div>
@@ -255,142 +291,7 @@ watch(
);
</script>
<style lang="scss" scoped>
.mac-style-drawer {
@apply h-full;
:deep(.n-drawer-header__main) {
@apply text-base font-medium;
}
:deep(.n-drawer-content) {
@apply h-full;
}
:deep(.n-drawer-content-wrapper) {
@apply h-full;
}
:deep(.n-scrollbar-rail) {
@apply right-0.5;
}
}
.playlist-drawer {
@apply flex flex-col gap-6 py-6;
}
.create-playlist-section {
@apply flex flex-col;
}
.create-playlist-button {
@apply flex items-center gap-4 p-3 rounded-xl cursor-pointer transition-all duration-200
bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700;
&.is-expanded {
@apply bg-gray-100 dark:bg-gray-700;
.create-playlist-icon {
transform: rotate(45deg);
}
}
&-icon {
@apply w-10 h-10 rounded-xl bg-green-500 flex items-center justify-center text-white
transition-all duration-300;
.iconfont {
@apply text-xl transition-transform duration-300;
}
}
&-text {
@apply text-sm font-medium transition-colors duration-300;
}
}
.create-playlist-form {
@apply max-h-0 overflow-hidden transition-all duration-300 ease-in-out opacity-0;
&.is-visible {
@apply max-h-[200px] mt-4 opacity-100;
}
.mac-style-input {
@apply rounded-lg;
:deep(.n-input-wrapper) {
@apply bg-gray-50 dark:bg-gray-800 border-0;
}
:deep(.n-input__input) {
@apply text-sm;
}
:deep(.n-input__prefix) {
@apply text-gray-400;
}
}
.form-actions {
@apply mt-4;
.mac-style-button {
@apply w-full rounded-lg text-sm py-2 bg-green-500 hover:bg-green-600 text-white;
}
}
}
.privacy-switch {
@apply flex items-center justify-between mt-4 px-2;
.privacy-label {
@apply flex items-center gap-2;
.iconfont {
@apply text-base text-gray-500 dark:text-gray-400;
}
span {
@apply text-sm;
}
}
:deep(.n-switch) {
@apply h-5 min-w-[40px];
}
}
.playlist-list {
@apply flex flex-col gap-2 pb-40;
}
.playlist-item {
@apply flex items-center gap-3 p-2 rounded-xl cursor-pointer transition-all duration-200
hover:bg-gray-50 dark:hover:bg-gray-800;
&-img {
@apply w-10 h-10 rounded-xl;
}
&-info {
@apply flex-1 min-w-0;
}
&-name {
@apply text-sm font-medium truncate;
}
&-count {
@apply text-xs text-gray-500 dark:text-gray-400;
}
&-action {
@apply w-8 h-8 rounded-lg flex items-center justify-center
text-gray-400 hover:text-green-500 transition-colors duration-200;
.iconfont {
@apply text-xl;
}
}
}
<style scoped>
:deep(.n-drawer-body-content-wrapper) {
padding-bottom: 0 !important;
padding-top: 0 !important;
+362 -435
View File
@@ -5,65 +5,102 @@
:show-icon="false"
:mask-closable="!downloading"
:closable="!downloading"
class="update-app-modal"
class="update-modal"
style="width: 800px; max-width: 90vw"
>
<div class="modal-content">
<div class="modal-header">
<div class="app-icon">
<img src="@/assets/logo.png" alt="App Icon" />
<div class="p-6 pb-4">
<!-- 头部图标 + 版本信息 -->
<div class="flex items-center mb-6">
<div
class="w-20 h-20 mr-5 flex-shrink-0 overflow-hidden rounded-2xl shadow-lg ring-2 ring-neutral-100 dark:ring-neutral-800"
>
<img src="@/assets/logo.png" alt="App Icon" class="w-full h-full object-cover" />
</div>
<div class="app-info">
<h2 class="app-name">{{ t('comp.update.title') }} {{ updateInfo.latestVersion }}</h2>
<p class="app-desc mb-2">
{{ t('comp.update.currentVersion') }} {{ updateInfo.currentVersion }}
</p>
<div class="flex-1 min-w-0">
<h2 class="text-2xl font-bold tracking-tight text-neutral-900 dark:text-white mb-1.5">
{{ t('comp.update.title') }} {{ updateInfo.latestVersion }}
</h2>
<div class="flex items-center gap-2">
<span
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold bg-neutral-100 text-neutral-500 dark:bg-neutral-800 dark:text-neutral-400"
>
{{ t('comp.update.currentVersion') }} {{ updateInfo.currentVersion }}
</span>
<span
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold bg-primary/10 text-primary dark:bg-primary/20"
>
NEW
</span>
</div>
</div>
</div>
<div class="update-info">
<!-- 更新日志 -->
<div class="mb-6 rounded-2xl bg-neutral-50 dark:bg-neutral-800/50 overflow-hidden">
<n-scrollbar style="max-height: 300px">
<div class="update-body" v-html="parsedReleaseNotes"></div>
<div
class="update-body p-5 text-sm leading-relaxed text-neutral-600 dark:text-neutral-300"
v-html="parsedReleaseNotes"
/>
</n-scrollbar>
</div>
<div v-if="downloading" class="download-status mt-6">
<div class="flex items-center justify-between mb-2">
<span class="text-sm text-gray-500">{{ downloadStatus }}</span>
<span class="text-sm font-medium">{{ downloadProgress }}%</span>
<!-- 下载进度 -->
<div v-if="downloading" class="mb-6 rounded-2xl bg-neutral-50 dark:bg-neutral-800/50 p-4">
<div class="flex items-center justify-between mb-2.5">
<span class="text-sm text-neutral-500 dark:text-neutral-400">{{ downloadStatus }}</span>
<span class="text-sm font-bold text-primary">{{ downloadProgress }}%</span>
</div>
<div class="progress-bar-wrapper">
<div class="progress-bar" :style="{ width: `${downloadProgress}%` }"></div>
<div
class="relative h-2 w-full overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700"
>
<div
class="absolute inset-y-0 left-0 rounded-full bg-primary transition-all duration-300 ease-out shadow-[0_0_10px_rgba(34,197,94,0.4)]"
:style="{ width: `${downloadProgress}%` }"
/>
</div>
</div>
<div class="modal-actions" :class="{ 'mt-6': !downloading }">
<n-button class="cancel-btn" :disabled="downloading" @click="closeModal">
<!-- 操作按钮 -->
<div class="flex gap-3" :class="{ 'mt-6': !downloading }">
<button
class="flex-1 rounded-xl py-2.5 text-sm font-semibold transition-all duration-200 bg-neutral-100 text-neutral-600 hover:bg-neutral-200 dark:bg-neutral-800 dark:text-neutral-300 dark:hover:bg-neutral-700 disabled:opacity-50 disabled:cursor-not-allowed"
:disabled="downloading"
@click="closeModal"
>
{{ t('comp.update.cancel') }}
</n-button>
<n-button
</button>
<button
v-if="!downloading"
type="primary"
class="update-btn"
class="flex-1 rounded-xl py-2.5 text-sm font-semibold transition-all duration-200 bg-primary text-white hover:bg-primary/90 shadow-lg shadow-primary/25 hover:scale-[1.02] active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed"
:disabled="downloading"
@click="handleUpdate"
>
{{ downloadBtnText }}
</n-button>
<!-- 后台下载 -->
<n-button v-else class="update-btn" type="primary" @click="closeModal">
</button>
<button
v-else
class="flex-1 rounded-xl py-2.5 text-sm font-semibold transition-all duration-200 bg-primary text-white hover:bg-primary/90 shadow-lg shadow-primary/25 hover:scale-[1.02] active:scale-95"
@click="closeModal"
>
{{ t('comp.update.backgroundDownload') }}
</n-button>
</div>
<div v-if="!downloading" class="modal-desc mt-4 text-center">
<p class="text-xs text-gray-400">
{{ t('comp.installApp.downloadProblem') }}
<a
class="text-green-500"
target="_blank"
href="https://github.com/algerkong/AlgerMusicPlayer/releases"
>GitHub</a
>
{{ t('comp.installApp.downloadProblemLinkText') }}
</p>
</button>
</div>
<!-- 底部提示 -->
<p
v-if="!downloading"
class="mt-4 text-center text-xs text-neutral-400 dark:text-neutral-500"
>
{{ t('comp.installApp.downloadProblem') }}
<a
class="text-primary hover:text-primary/80 transition-colors"
target="_blank"
href="https://github.com/algerkong/AlgerMusicPlayer/releases"
>GitHub</a
>
{{ t('comp.installApp.downloadProblemLinkText') }}
</p>
</div>
</n-modal>
</template>
@@ -82,13 +119,14 @@ const { t } = useI18n();
const dialog = useDialog();
const message = useMessage();
// 配置 marked
marked.setOptions({
breaks: true, // 支持 GitHub 风格的换行
gfm: true // 启用 GitHub 风格的 Markdown
});
// 配置 marked(只需执行一次)
marked.setOptions({ breaks: true, gfm: true });
const GITHUB_RELEASE_BASE = 'https://github.com/algerkong/AlgerMusicPlayer/releases/download';
const GITHUB_RELEASES_URL = 'https://github.com/algerkong/AlgerMusicPlayer/releases';
const settingsStore = useSettingsStore();
const ipc = window.electron.ipcRenderer;
const showModal = computed({
get: () => settingsStore.showUpdateModal,
@@ -102,22 +140,170 @@ const updateInfo = ref<UpdateResult>({
releaseInfo: null
});
// 解析 Markdown
const downloading = ref(false);
const downloadProgress = ref(0);
const downloadStatus = ref(t('comp.update.prepareDownload'));
const isDialogShown = ref(false);
const parsedReleaseNotes = computed(() => {
if (!updateInfo.value.releaseInfo?.body) return '';
const body = updateInfo.value.releaseInfo?.body;
if (!body) return '';
try {
return marked.parse(updateInfo.value.releaseInfo.body);
return marked.parse(body);
} catch (error) {
console.error('Error parsing markdown:', error);
return updateInfo.value.releaseInfo.body;
console.error('Markdown 解析失败:', error);
return body;
}
});
const downloadBtnText = computed(() =>
downloading.value ? t('comp.update.downloading') : t('comp.update.nowUpdate')
);
const closeModal = () => {
showModal.value = false;
};
const checkForUpdates = async () => {
// ---- 下载 URL 解析 ----
const buildReleaseUrl = (version: string, suffix: string): string =>
`${GITHUB_RELEASE_BASE}/v${version}/AlgerMusicPlayer-${version}${suffix}`;
const resolveDownloadUrl = (
assets: any[],
platform: string,
arch: string,
version: string
): string => {
// 从 release assets 中按平台/架构匹配
const findAsset = (keywords: string[]): string | undefined =>
assets.find((a) => keywords.every((k) => a.name.includes(k)))?.browser_download_url;
if (platform === 'darwin') {
const macArch = arch === 'arm64' ? 'arm64' : 'x64';
return findAsset(['mac', macArch]) || buildReleaseUrl(version, `-${macArch}.dmg`);
}
if (platform === 'win32') {
const winArch = arch === 'x64' ? 'x64' : 'ia32';
return (
findAsset(['win', winArch]) ||
buildReleaseUrl(version, `-win-${winArch}.exe`) ||
buildReleaseUrl(version, '-win.exe')
);
}
if (platform === 'linux') {
return (
findAsset(['x64', '.AppImage']) ||
findAsset(['x64', '.deb']) ||
buildReleaseUrl(version, '-linux-x64.AppImage')
);
}
return '';
};
// ---- IPC 事件处理 ----
const onDownloadProgress = (_event: any, progress: number, status: string) => {
downloadProgress.value = progress;
downloadStatus.value = status;
};
const showInstallDialog = (filePath: string) => {
const copyFilePath = () => {
navigator.clipboard
.writeText(filePath)
.then(() => message.success(t('comp.update.copySuccess')))
.catch(() => message.error(t('comp.update.copyFailed')));
};
const dialogRef = dialog.create({
title: t('comp.update.installConfirmTitle'),
content: () =>
h('div', { class: 'flex flex-col gap-3' }, [
h(
'p',
{ class: 'text-base font-medium text-neutral-800 dark:text-neutral-100' },
t('comp.update.installConfirmContent')
),
h('div', { class: 'h-px bg-neutral-200 dark:bg-neutral-700' }),
h(
'p',
{ class: 'text-sm text-neutral-500 dark:text-neutral-400' },
t('comp.update.manualInstallTip')
),
h('div', { class: 'flex items-center gap-3 mt-1' }, [
h('div', { class: 'flex-1 min-w-0' }, [
h(
'p',
{ class: 'text-xs text-neutral-400 dark:text-neutral-500 mb-1' },
t('comp.update.fileLocation')
),
h(
'div',
{
class:
'rounded-xl bg-neutral-100 dark:bg-neutral-800 px-3 py-2 text-xs font-mono text-neutral-700 dark:text-neutral-300 break-all'
},
filePath
)
]),
h(
'button',
{
class:
'flex items-center gap-1.5 rounded-xl bg-neutral-200 dark:bg-neutral-700 px-3 py-2 text-xs text-neutral-600 dark:text-neutral-300 cursor-pointer transition-colors hover:bg-neutral-300 dark:hover:bg-neutral-600 flex-shrink-0',
onClick: copyFilePath
},
[h('i', { class: 'ri-file-copy-line text-sm' }), h('span', t('comp.update.copy'))]
)
])
]),
positiveText: t('comp.update.yesInstall'),
negativeText: t('comp.update.noThanks'),
onPositiveClick: () => {
ipc.send('install-update', filePath);
},
onNegativeClick: () => {
dialogRef.destroy();
},
onClose: () => {
isDialogShown.value = false;
}
});
};
const onDownloadComplete = (_event: any, success: boolean, filePath: string) => {
downloading.value = false;
closeModal();
if (success && !isDialogShown.value) {
isDialogShown.value = true;
showInstallDialog(filePath);
} else if (!success) {
message.error(t('comp.update.downloadFailed'));
}
};
// ---- 生命周期 ----
const registerIpcListeners = () => {
// 先移除旧监听,防止重复注册
ipc.removeListener('download-progress', onDownloadProgress);
ipc.removeListener('download-complete', onDownloadComplete);
ipc.on('download-progress', onDownloadProgress);
ipc.on('download-complete', onDownloadComplete);
};
const removeIpcListeners = () => {
ipc.removeListener('download-progress', onDownloadProgress);
ipc.removeListener('download-complete', onDownloadComplete);
};
onMounted(async () => {
registerIpcListeners();
try {
const result = await checkUpdate(config.version);
if (result) {
@@ -127,407 +313,148 @@ const checkForUpdates = async () => {
} catch (error) {
console.error('检查更新失败:', error);
}
};
const downloading = ref(false);
const downloadProgress = ref(0);
const downloadStatus = ref(t('comp.update.prepareDownload'));
const downloadBtnText = computed(() => {
if (downloading.value) return t('comp.update.downloading');
return t('comp.update.nowUpdate');
});
// 下载完成后的文件路径
const downloadedFilePath = ref('');
// 防止对话框重复弹出
const isDialogShown = ref(false);
// 处理下载状态更新
const handleDownloadProgress = (_event: any, progress: number, status: string) => {
downloadProgress.value = progress;
downloadStatus.value = status;
};
// 处理下载完成
const handleDownloadComplete = (_event: any, success: boolean, filePath: string) => {
downloading.value = false;
closeModal();
if (success && !isDialogShown.value) {
downloadedFilePath.value = filePath;
isDialogShown.value = true;
// 复制文件路径到剪贴板
const copyFilePath = () => {
navigator.clipboard
.writeText(filePath)
.then(() => {
message.success(t('comp.update.copySuccess'));
})
.catch(() => {
message.error(t('comp.update.copyFailed'));
});
};
// 使用naive-ui的对话框询问用户是否安装
const dialogRef = dialog.create({
title: t('comp.update.installConfirmTitle'),
content: () =>
h('div', { class: 'update-dialog-content' }, [
h('p', { class: 'content-text' }, t('comp.update.installConfirmContent')),
h('div', { class: 'divider' }),
h('p', { class: 'manual-tip' }, t('comp.update.manualInstallTip')),
h('div', { class: 'file-path-container' }, [
h('div', { class: 'file-path-box' }, [
h('p', { class: 'file-path-label' }, t('comp.update.fileLocation')),
h('div', { class: 'file-path-value' }, filePath)
]),
h(
'div',
{
class: 'copy-btn',
onClick: copyFilePath
},
[h('i', { class: 'ri-file-copy-line' }), h('span', t('comp.update.copy'))]
)
])
]),
positiveText: t('comp.update.yesInstall'),
negativeText: t('comp.update.noThanks'),
onPositiveClick: () => {
window.electron.ipcRenderer.send('install-update', filePath);
},
onNegativeClick: () => {
closeModal();
// 关闭当前窗口
dialogRef.destroy();
},
onClose: () => {
isDialogShown.value = false;
}
});
} else if (!success) {
message.error(t('comp.update.downloadFailed'));
}
};
// 监听下载事件
onMounted(() => {
checkForUpdates();
// 确保事件监听器只注册一次
window.electron.ipcRenderer.removeListener('download-progress', handleDownloadProgress);
window.electron.ipcRenderer.removeListener('download-complete', handleDownloadComplete);
window.electron.ipcRenderer.on('download-progress', handleDownloadProgress);
window.electron.ipcRenderer.on('download-complete', handleDownloadComplete);
});
// 清理事件监听
onUnmounted(() => {
window.electron.ipcRenderer.removeListener('download-progress', handleDownloadProgress);
window.electron.ipcRenderer.removeListener('download-complete', handleDownloadComplete);
removeIpcListeners();
isDialogShown.value = false;
});
// ---- 触发更新下载 ----
const handleUpdate = async () => {
const assets = updateInfo.value.releaseInfo?.assets || [];
const { releaseInfo, latestVersion } = updateInfo.value;
const assets = releaseInfo?.assets ?? [];
const { platform } = window.electron.process;
const arch = window.electron.ipcRenderer.sendSync('get-arch');
const version = updateInfo.value.latestVersion;
const downUrls = {
win32: {
all: `https://github.com/algerkong/AlgerMusicPlayer/releases/download/v${version}/AlgerMusicPlayer-${version}-win.exe`,
x64: `https://github.com/algerkong/AlgerMusicPlayer/releases/download/v${version}/AlgerMusicPlayer-${version}-win-x64.exe`,
ia32: `https://github.com/algerkong/AlgerMusicPlayer/releases/download/v${version}/AlgerMusicPlayer-${version}-win-ia32.exe`
},
darwin: {
x64: `https://github.com/algerkong/AlgerMusicPlayer/releases/download/v${version}/AlgerMusicPlayer-${version}-x64.dmg`,
arm64: `https://github.com/algerkong/AlgerMusicPlayer/releases/download/v${version}/AlgerMusicPlayer-${version}-arm64.dmg`
},
linux: {
AppImage: `https://github.com/algerkong/AlgerMusicPlayer/releases/download/v${version}/AlgerMusicPlayer-${version}-linux-x64.AppImage`,
deb: `https://github.com/algerkong/AlgerMusicPlayer/releases/download/v${version}/AlgerMusicPlayer-${version}-linux-x64.deb`
}
};
const arch = ipc.sendSync('get-arch');
let downloadUrl = '';
const downloadUrl = resolveDownloadUrl(assets, platform, arch, latestVersion);
// 根据平台和架构选择对应的安装包
if (platform === 'darwin') {
// macOS - 根据芯片架构选择对应的 DMG
const macArch = arch === 'arm64' ? 'arm64' : 'x64';
const macAsset = assets.find(
(asset) => asset.name.includes('mac') && asset.name.includes(macArch)
);
downloadUrl = macAsset?.browser_download_url || downUrls.darwin[macArch] || '';
} else if (platform === 'win32') {
// Windows
const winAsset = assets.find(
(asset) =>
asset.name.includes('win') &&
(arch === 'x64' ? asset.name.includes('x64') : asset.name.includes('ia32'))
);
downloadUrl =
winAsset?.browser_download_url || downUrls.win32[arch] || downUrls.win32.all || '';
} else if (platform === 'linux') {
// Linux
const linuxAsset = assets.find(
(asset) =>
(asset.name.endsWith('.AppImage') || asset.name.endsWith('.deb')) &&
asset.name.includes('x64')
);
downloadUrl = linuxAsset?.browser_download_url || downUrls.linux[arch] || '';
if (!downloadUrl) {
message.error(t('comp.update.noDownloadUrl'));
window.open(`${GITHUB_RELEASES_URL}/latest`, '_blank');
return;
}
if (downloadUrl) {
try {
downloading.value = true;
downloadStatus.value = t('comp.update.prepareDownload');
isDialogShown.value = false;
try {
downloading.value = true;
downloadProgress.value = 0;
downloadStatus.value = t('comp.update.prepareDownload');
isDialogShown.value = false;
// 获取代理节点列表
const proxyHosts = await getProxyNodes();
const proxyDownloadUrl = `${proxyHosts[0]}/${downloadUrl}`;
// 发送所有可能的下载地址到主进程
window.electron.ipcRenderer.send('start-download', proxyDownloadUrl);
} catch (error) {
downloading.value = false;
message.error(t('comp.update.startFailed'));
console.error('下载失败:', error);
}
} else {
message.error(t('comp.update.noDownloadUrl'));
window.open('https://github.com/algerkong/AlgerMusicPlayer/releases/latest', '_blank');
const proxyHosts = await getProxyNodes();
ipc.send('start-download', `${proxyHosts[0]}/${downloadUrl}`);
} catch (error) {
downloading.value = false;
message.error(t('comp.update.startFailed'));
console.error('下载失败:', error);
}
};
</script>
<style lang="scss" scoped>
.update-app-modal {
:deep(.n-modal) {
@apply max-w-4xl;
}
.modal-content {
@apply p-6 pb-4;
.modal-header {
@apply flex items-center mb-6;
.app-icon {
@apply w-24 h-24 mr-6 rounded-2xl overflow-hidden;
img {
@apply w-full h-full object-cover;
}
}
.app-info {
@apply flex-1;
.app-name {
@apply text-2xl font-bold mb-2;
}
.app-desc {
@apply text-base text-gray-400;
}
}
}
.update-info {
@apply mb-6 rounded-lg bg-gray-50 dark:bg-gray-800;
.update-title {
@apply text-base font-medium p-4 pb-2;
}
.update-body {
@apply p-4 pt-2 text-gray-600 dark:text-gray-300 rounded-lg overflow-hidden;
<style scoped>
/* 弹窗圆角 */
.update-modal :deep(.n-dialog) {
border-radius: 1.25rem; /* 20px — rounded-2xl 级别 */
overflow: hidden;
}
:deep(h1) {
@apply text-xl font-bold mb-3;
}
:deep(h2) {
@apply text-lg font-bold mb-3;
}
:deep(h3) {
@apply text-base font-bold mb-2;
}
:deep(p) {
@apply mb-3 leading-relaxed;
}
:deep(ul) {
@apply list-disc list-inside mb-3;
}
:deep(ol) {
@apply list-decimal list-inside mb-3;
}
:deep(li) {
@apply mb-2 leading-relaxed;
}
:deep(code) {
@apply px-1.5 py-0.5 rounded bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200;
}
:deep(pre) {
@apply p-3 rounded bg-gray-100 dark:bg-gray-700 overflow-x-auto mb-3;
code {
@apply bg-transparent p-0;
}
}
:deep(blockquote) {
@apply pl-4 border-l-4 border-gray-200 dark:border-gray-600 mb-3;
}
:deep(a) {
@apply text-green-500 hover:text-green-600 dark:hover:text-green-400;
}
:deep(hr) {
@apply my-4 border-gray-200 dark:border-gray-600;
}
:deep(table) {
@apply w-full mb-3;
th,
td {
@apply px-3 py-2 border border-gray-200 dark:border-gray-600;
}
th {
@apply bg-gray-100 dark:bg-gray-700;
}
}
}
}
.download-status {
@apply p-2;
.progress-bar-wrapper {
@apply w-full h-2 bg-gray-100 dark:bg-gray-700 rounded-full overflow-hidden;
.progress-bar {
@apply h-full bg-green-500 rounded-full transition-all duration-300 ease-out;
box-shadow: 0 0 10px rgba(34, 197, 94, 0.5);
}
}
}
.modal-actions {
@apply flex gap-4;
.n-button {
@apply flex-1 text-base py-2;
}
.cancel-btn {
@apply bg-gray-800 text-gray-300 border-none;
&:hover {
@apply bg-gray-700;
}
&:disabled {
@apply opacity-50 cursor-not-allowed;
}
}
.update-btn {
@apply bg-green-600 border-none;
&:hover {
@apply bg-green-500;
}
&:disabled {
@apply opacity-50 cursor-not-allowed;
}
}
}
}
}
</style>
<style lang="scss" scoped>
/* 对话框内容样式 */
.update-dialog-content {
display: flex;
flex-direction: column;
gap: 12px;
.content-text {
font-size: 16px;
font-weight: 500;
}
.divider {
width: 100%;
height: 1px;
background-color: #e5e7eb;
margin: 4px 0;
}
.manual-tip {
font-size: 14px;
color: #6b7280;
}
.file-path-container {
display: flex;
align-items: center;
gap: 12px;
margin-top: 8px;
.file-path-box {
flex: 1;
.file-path-label {
font-size: 12px;
color: #6b7280;
margin-bottom: 4px;
}
.file-path-value {
padding: 8px;
border-radius: 4px;
background-color: #f3f4f6;
font-size: 12px;
font-family: monospace;
color: #1f2937;
word-break: break-all;
}
}
.copy-btn {
display: flex;
align-items: center;
gap: 4px;
padding: 8px 12px;
border-radius: 4px;
background-color: #e5e7eb;
color: #4b5563;
font-size: 12px;
cursor: pointer;
transition: background-color 0.2s;
&:hover {
background-color: #d1d5db;
}
i {
font-size: 14px;
}
}
}
}
/* 深色模式样式 */
.dark .update-dialog-content {
.divider {
background-color: #374151;
}
.manual-tip {
color: #9ca3af;
}
.file-path-container {
.file-path-box {
.file-path-label {
color: #9ca3af;
}
.file-path-value {
background-color: #1f2937;
color: #d1d5db;
}
}
.copy-btn {
background-color: #374151;
color: #d1d5db;
&:hover {
background-color: #4b5563;
}
}
}
/* 更新日志 Markdown 渲染样式 */
.update-body :deep(h1) {
font-size: 1.25rem;
font-weight: 700;
margin-bottom: 0.75rem;
}
.update-body :deep(h2) {
font-size: 1.125rem;
font-weight: 700;
margin-bottom: 0.75rem;
}
.update-body :deep(h3) {
font-size: 1rem;
font-weight: 700;
margin-bottom: 0.5rem;
}
.update-body :deep(p) {
margin-bottom: 0.75rem;
line-height: 1.625;
}
.update-body :deep(ul) {
list-style-type: disc;
list-style-position: inside;
margin-bottom: 0.75rem;
}
.update-body :deep(ol) {
list-style-type: decimal;
list-style-position: inside;
margin-bottom: 0.75rem;
}
.update-body :deep(li) {
margin-bottom: 0.5rem;
line-height: 1.625;
}
.update-body :deep(code) {
padding: 0.125rem 0.375rem;
border-radius: 0.375rem;
font-size: 0.8125rem;
background-color: rgb(245 245 245);
}
.dark .update-body :deep(code) {
background-color: rgb(64 64 64);
}
.update-body :deep(pre) {
padding: 0.75rem;
border-radius: 0.75rem;
overflow-x: auto;
margin-bottom: 0.75rem;
background-color: rgb(245 245 245);
}
.dark .update-body :deep(pre) {
background-color: rgb(64 64 64);
}
.update-body :deep(pre code) {
background-color: transparent;
padding: 0;
}
.update-body :deep(blockquote) {
padding-left: 1rem;
border-left: 4px solid rgb(229 229 229);
margin-bottom: 0.75rem;
}
.dark .update-body :deep(blockquote) {
border-left-color: rgb(82 82 82);
}
.update-body :deep(a) {
color: #22c55e;
transition: color 0.2s;
}
.update-body :deep(a:hover) {
color: rgb(34 197 94 / 0.8);
}
.update-body :deep(hr) {
margin: 1rem 0;
border-color: rgb(229 229 229);
}
.dark .update-body :deep(hr) {
border-color: rgb(82 82 82);
}
.update-body :deep(table) {
width: 100%;
margin-bottom: 0.75rem;
}
.update-body :deep(th),
.update-body :deep(td) {
padding: 0.5rem 0.75rem;
border: 1px solid rgb(229 229 229);
}
.dark .update-body :deep(th),
.dark .update-body :deep(td) {
border-color: rgb(82 82 82);
}
.update-body :deep(th) {
background-color: rgb(245 245 245);
}
.dark .update-body :deep(th) {
background-color: rgb(64 64 64);
}
</style>