refactor: 更新 eslint 和 prettier 配置 格式化代码

This commit is contained in:
alger
2025-07-23 23:54:35 +08:00
parent d1f5c8af84
commit c08c2cbf19
134 changed files with 3887 additions and 3301 deletions
@@ -11,9 +11,9 @@
<template #trigger>
<n-tooltip trigger="hover" :z-index="9999999">
<template #trigger>
<i
<i
class="iconfont ri-refresh-line"
:class="{ 'text-green-500': isReparse, 'animate-spin': isReparsing }"
:class="{ 'text-green-500': isReparse, 'animate-spin': isReparsing }"
></i>
</template>
{{ t('player.playBar.reparse') }}
@@ -24,11 +24,11 @@
<div class="text-sm opacity-70 mb-3">{{ t('player.reparse.desc') }}</div>
<div class="mb-3">
<div class="flex flex-col space-y-2">
<div
v-for="source in musicSourceOptions"
<div
v-for="source in musicSourceOptions"
:key="source.value"
class="source-button flex items-center p-2 rounded-lg cursor-pointer transition-all duration-200 bg-light-200 dark:bg-dark-200 hover:bg-light-300 dark:hover:bg-dark-300"
:class="{
:class="{
'bg-green-50 dark:bg-green-900/20 text-green-500': isCurrentSource(source.value),
'opacity-50 cursor-not-allowed': isReparsing || playMusic.source === 'bilibili'
}"
@@ -40,10 +40,16 @@
<div class="flex-1 text-sm whitespace-nowrap overflow-hidden text-ellipsis">
{{ source.label }}
</div>
<div v-if="isReparsing && currentReparsingSource === source.value" class="w-5 h-5 flex items-center justify-center">
<div
v-if="isReparsing && currentReparsingSource === source.value"
class="w-5 h-5 flex items-center justify-center"
>
<i class="ri-loader-4-line animate-spin"></i>
</div>
<div v-else-if="isCurrentSource(source.value)" class="w-5 h-5 flex items-center justify-center">
<div
v-else-if="isCurrentSource(source.value)"
class="w-5 h-5 flex items-center justify-center"
>
<i class="ri-check-line"></i>
</div>
</div>
@@ -53,7 +59,10 @@
{{ t('player.reparse.bilibiliNotSupported') }}
</div>
<!-- 清除自定义音源 -->
<div class="text-red-500 text-sm flex items-center bg-light-200 dark:bg-dark-200 rounded-lg p-2 cursor-pointer" @click="clearCustomSource">
<div
class="text-red-500 text-sm flex items-center bg-light-200 dark:bg-dark-200 rounded-lg p-2 cursor-pointer"
@click="clearCustomSource"
>
<div class="flex items-center justify-center w-6 h-6 mr-3 text-lg">
<i class="ri-close-circle-line"></i>
</div>
@@ -66,13 +75,14 @@
</template>
<script lang="ts" setup>
import { useMessage } from 'naive-ui';
import { ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useMessage } from 'naive-ui';
import { playMusic } from '@/hooks/MusicHook';
import { audioService } from '@/services/audioService';
import { usePlayerStore } from '@/store/modules/player';
import type { Platform } from '@/types/music';
import { audioService } from '@/services/audioService';
const playerStore = usePlayerStore();
const { t } = useI18n();
@@ -104,13 +114,13 @@ const isCurrentSource = (source: Platform) => {
// 获取音源图标
const getSourceIcon = (source: Platform) => {
const iconMap: Record<Platform, string> = {
'migu': 'ri-music-2-fill',
'kugou': 'ri-music-fill',
'qq': 'ri-qq-fill',
'joox': 'ri-disc-fill',
'pyncmd': 'ri-netease-cloud-music-fill',
'bilibili': 'ri-bilibili-fill',
'gdmusic': 'ri-google-fill'
migu: 'ri-music-2-fill',
kugou: 'ri-music-fill',
qq: 'ri-qq-fill',
joox: 'ri-disc-fill',
pyncmd: 'ri-netease-cloud-music-fill',
bilibili: 'ri-bilibili-fill',
gdmusic: 'ri-google-fill'
};
return iconMap[source] || 'ri-music-2-fill';
@@ -120,11 +130,12 @@ const getSourceIcon = (source: Platform) => {
const initSelectedSources = () => {
const songId = String(playMusic.value.id);
const savedSource = localStorage.getItem(`song_source_${songId}`);
if (savedSource) {
try {
selectedSourcesValue.value = JSON.parse(savedSource);
} catch (e) {
console.error('解析保存的音源设置失败:', e);
selectedSourcesValue.value = [];
}
} else {
@@ -144,20 +155,20 @@ const directReparseMusic = async (source: Platform) => {
if (isReparsing.value || playMusic.value.source === 'bilibili') {
return;
}
try {
isReparsing.value = true;
currentReparsingSource.value = source;
// 更新选中的音源值为当前点击的音源
const songId = String(playMusic.value.id);
selectedSourcesValue.value = [source];
// 保存到localStorage
localStorage.setItem(`song_source_${songId}`, JSON.stringify(selectedSourcesValue.value));
const success = await playerStore.reparseCurrentSong(source);
if (success) {
message.success(t('player.reparse.success'));
} else {
@@ -173,48 +184,55 @@ const directReparseMusic = async (source: Platform) => {
};
// 监听歌曲ID变化,初始化音源设置
watch(() => playMusic.value.id, () => {
if (playMusic.value.id) {
initSelectedSources();
}
}, { immediate: true });
watch(
() => playMusic.value.id,
() => {
if (playMusic.value.id) {
initSelectedSources();
}
},
{ immediate: true }
);
// 监听歌曲变化,检查是否有自定义音源
watch(() => playMusic.value.id, async (newId) => {
if (newId) {
const songId = String(newId);
const savedSource = localStorage.getItem(`song_source_${songId}`);
// 如果有保存的音源设置但当前不是使用自定义解析的播放,尝试应用
if (savedSource && playMusic.value.source !== 'bilibili') {
try {
const sources = JSON.parse(savedSource) as Platform[];
console.log(`检测到歌曲ID ${songId} 有自定义音源设置:`, sources);
// 当URL加载失败或过期时,自动应用自定义音源重新加载
audioService.on('url_expired', async (trackInfo) => {
if (trackInfo && trackInfo.id === playMusic.value.id) {
console.log('URL已过期,自动应用自定义音源重新加载');
try {
isReparsing.value = true;
const success = await playerStore.reparseCurrentSong(sources[0]);
if (!success) {
watch(
() => playMusic.value.id,
async (newId) => {
if (newId) {
const songId = String(newId);
const savedSource = localStorage.getItem(`song_source_${songId}`);
// 如果有保存的音源设置但当前不是使用自定义解析的播放,尝试应用
if (savedSource && playMusic.value.source !== 'bilibili') {
try {
const sources = JSON.parse(savedSource) as Platform[];
console.log(`检测到歌曲ID ${songId} 有自定义音源设置:`, sources);
// 当URL加载失败或过期时,自动应用自定义音源重新加载
audioService.on('url_expired', async (trackInfo) => {
if (trackInfo && trackInfo.id === playMusic.value.id) {
console.log('URL已过期,自动应用自定义音源重新加载');
try {
isReparsing.value = true;
const success = await playerStore.reparseCurrentSong(sources[0]);
if (!success) {
message.error(t('player.reparse.failed'));
}
} catch (e) {
console.error('自动重新解析失败:', e);
message.error(t('player.reparse.failed'));
} finally {
isReparsing.value = false;
}
} catch (e) {
console.error('自动重新解析失败:', e);
message.error(t('player.reparse.failed'));
} finally {
isReparsing.value = false;
}
}
});
} catch (e) {
console.error('解析保存的音源设置失败:', e);
});
} catch (e) {
console.error('解析保存的音源设置失败:', e);
}
}
}
}
});
);
</script>
<style lang="scss" scoped>
@@ -223,8 +241,12 @@ watch(() => playMusic.value.id, async (newId) => {
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.animate-spin {
@@ -240,4 +262,4 @@ watch(() => playMusic.value.id, async (newId) => {
.iconfont {
@apply text-2xl mx-3;
}
</style>
</style>