mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-13 22:20:51 +08:00
Merge branch 'dev_electron' into dev_i18n
This commit is contained in:
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,19 +1,11 @@
|
||||
# 更新日志
|
||||
|
||||
## v3.9.0
|
||||
### ✨ 新功能
|
||||
- 添加歌曲右键菜单功能,支持添加到歌单、创建歌单、取消收藏等操作
|
||||
- 添加下一首播放功能(右键歌曲)
|
||||
- 添加自动播放和自动保存正在播放列表功能(设置->播放设置->自动播放)
|
||||
- 优化歌词滚动体验
|
||||
|
||||
### ⚡ 优化
|
||||
- 升级 Electron 版本和相关依赖包
|
||||
- 优化播放体验和代码结构
|
||||
## v3.9.2
|
||||
|
||||
### 🐞 修复
|
||||
- 修复我的收藏查看更多跳转空白页的问题
|
||||
|
||||
- 修复下载功能导致的登陆失败问题
|
||||
- 优化下载功能
|
||||
- 添加下载按钮显隐配置 默认隐藏(设置页面配置)
|
||||
|
||||
## 咖啡☕️
|
||||
| 微信 | | 支付宝 |
|
||||
|
||||
@@ -47,8 +47,6 @@ QQ群:789288579
|
||||
|
||||
## 咖啡☕️
|
||||
|
||||
[<img src="https://api.gitsponsors.com/api/badge/img?id=710867462" height="90">](https://api.gitsponsors.com/api/badge/link?p=GTUHmTNQ9W5XzPhaLd8cPBm26uhtP/QOon9hexaWh9gnfaDT3ivj1ID0uKScVHL61jTFrK1fRWyigScIYvcLh/no+3zgtdW3TK0+vN0TVs84Mt3RibhEqAgBHSd8KhNLxaMd4vMIY37P5gOA2/QYcw==)
|
||||
|
||||
| 微信 | 支付宝 |
|
||||
| :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: |
|
||||
| <img src="https://github.com/algerkong/algerkong/blob/main/wechat.jpg?raw=true" alt="WeChat QRcode" width=200> | <img src="https://github.com/algerkong/algerkong/blob/main/alipay.jpg?raw=true" alt="Wechat QRcode" width=200> |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "AlgerMusicPlayer",
|
||||
"version": "3.9.0",
|
||||
"version": "3.9.2",
|
||||
"description": "Alger Music Player",
|
||||
"author": "Alger <algerkc@qq.com>",
|
||||
"main": "./out/main/index.js",
|
||||
|
||||
@@ -60,13 +60,22 @@ export function initializeFileManager() {
|
||||
// 通用的打开目录处理
|
||||
ipcMain.on('open-directory', (_, filePath) => {
|
||||
try {
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
shell.openPath(filePath);
|
||||
// 验证文件路径
|
||||
if (!filePath) {
|
||||
console.error('无效的文件路径: 路径为空');
|
||||
return;
|
||||
}
|
||||
|
||||
// 统一处理路径分隔符
|
||||
const normalizedPath = path.normalize(filePath);
|
||||
|
||||
if (fs.statSync(normalizedPath).isDirectory()) {
|
||||
shell.openPath(normalizedPath);
|
||||
} else {
|
||||
shell.showItemInFolder(filePath);
|
||||
shell.showItemInFolder(normalizedPath);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error opening path:', error);
|
||||
console.error('打开路径失败:', error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
"fontScope": "global",
|
||||
"autoPlay": false,
|
||||
"downloadPath": "",
|
||||
"language": "zh-CN"
|
||||
"language": "zh-CN",
|
||||
"alwaysShowDownloadButton": false
|
||||
}
|
||||
|
||||
20
src/renderer/api/donation.ts
Normal file
20
src/renderer/api/donation.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export interface Donor {
|
||||
id: number;
|
||||
name: string;
|
||||
amount: number;
|
||||
date: string;
|
||||
message?: string;
|
||||
avatar?: string;
|
||||
badge: string;
|
||||
badgeColor: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取捐赠列表
|
||||
*/
|
||||
export const getDonationList = async (): Promise<Donor[]> => {
|
||||
const { data } = await axios.get('http://110.42.251.190:8766/api/donations');
|
||||
return data;
|
||||
};
|
||||
@@ -13,16 +13,25 @@ export const getMusicQualityDetail = (id: number) => {
|
||||
};
|
||||
|
||||
// 根据音乐Id获取音乐播放URl
|
||||
export const getMusicUrl = async (id: number) => {
|
||||
const res = await request.get('/song/download/url/v1', {
|
||||
params: {
|
||||
id,
|
||||
level: store.state.setData.musicQuality || 'higher'
|
||||
}
|
||||
});
|
||||
export const getMusicUrl = async (id: number, isDownloaded: boolean = false) => {
|
||||
// 判断是否登录
|
||||
try {
|
||||
if (store.state.user && isDownloaded && store.state.user.vipType !== 0) {
|
||||
const url = '/song/download/url/v1';
|
||||
const res = await request.get(url, {
|
||||
params: {
|
||||
id,
|
||||
level: store.state.setData.musicQuality || 'higher',
|
||||
cookie: `${localStorage.getItem('token')} os=pc;`
|
||||
}
|
||||
});
|
||||
|
||||
if (res.data.data.url) {
|
||||
return { data: { data: [{ ...res.data.data }] } };
|
||||
if (res.data.data.url) {
|
||||
return { data: { data: [{ ...res.data.data }] } };
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('error', error);
|
||||
}
|
||||
|
||||
return await request.get('/song/url/v1', {
|
||||
@@ -80,8 +89,10 @@ export const likeSong = (id: number, like: boolean = true) => {
|
||||
};
|
||||
|
||||
// 获取用户喜欢的音乐列表
|
||||
export const getLikedList = () => {
|
||||
return request.get('/likelist');
|
||||
export const getLikedList = (uid: number) => {
|
||||
return request.get('/likelist', {
|
||||
params: { uid }
|
||||
});
|
||||
};
|
||||
|
||||
// 创建歌单
|
||||
|
||||
4
src/renderer/components.d.ts
vendored
4
src/renderer/components.d.ts
vendored
@@ -27,14 +27,11 @@ declare module 'vue' {
|
||||
NInput: typeof import('naive-ui')['NInput']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NList: typeof import('naive-ui')['NList']
|
||||
NListItem: typeof import('naive-ui')['NListItem']
|
||||
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
|
||||
NModal: typeof import('naive-ui')['NModal']
|
||||
NPopover: typeof import('naive-ui')['NPopover']
|
||||
NProgress: typeof import('naive-ui')['NProgress']
|
||||
NRadio: typeof import('naive-ui')['NRadio']
|
||||
NRadioButton: typeof import('naive-ui')['NRadioButton']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSelect: typeof import('naive-ui')['NSelect']
|
||||
@@ -46,7 +43,6 @@ declare module 'vue' {
|
||||
NTabs: typeof import('naive-ui')['NTabs']
|
||||
NTag: typeof import('naive-ui')['NTag']
|
||||
NTooltip: typeof import('naive-ui')['NTooltip']
|
||||
NTransfer: typeof import('naive-ui')['NTransfer']
|
||||
NVirtualList: typeof import('naive-ui')['NVirtualList']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
|
||||
@@ -106,38 +106,24 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import axios from 'axios';
|
||||
import { computed, onActivated, onMounted, ref } from 'vue';
|
||||
|
||||
import type { Donor } from '@/api/donation';
|
||||
import { getDonationList } from '@/api/donation';
|
||||
import alipay from '@/assets/alipay.png';
|
||||
import wechat from '@/assets/wechat.png';
|
||||
|
||||
// 默认头像
|
||||
const defaultAvatar = 'https://avatars.githubusercontent.com/u/0?v=4';
|
||||
|
||||
// 捐赠者数据
|
||||
interface Donor {
|
||||
id: number;
|
||||
name: string;
|
||||
amount: number;
|
||||
date: string;
|
||||
message?: string;
|
||||
avatar?: string;
|
||||
badge: string;
|
||||
badgeColor: string;
|
||||
}
|
||||
|
||||
const donors = ref<Donor[]>([]);
|
||||
|
||||
const isLoading = ref(false);
|
||||
|
||||
const fetchDonors = async () => {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
const response = await axios.get(
|
||||
'https://www.ghproxy.cn/https://raw.githubusercontent.com/algerkong/data/main/donors.json'
|
||||
);
|
||||
donors.value = response.data.map((donor: Donor, index: number) => ({
|
||||
const data = await getDonationList();
|
||||
donors.value = data.map((donor, index) => ({
|
||||
...donor,
|
||||
avatar: `https://api.dicebear.com/7.x/micah/svg?seed=${index}`
|
||||
}));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="download-drawer-trigger">
|
||||
<n-badge :value="downloadingCount" :max="99" :show="downloadingCount > 0">
|
||||
<n-button circle @click="showDrawer = true">
|
||||
<n-button circle @click="store.commit('setShowDownloadDrawer', true)">
|
||||
<template #icon>
|
||||
<i class="iconfont ri-download-cloud-2-line"></i>
|
||||
</template>
|
||||
@@ -9,7 +9,12 @@
|
||||
</n-badge>
|
||||
</div>
|
||||
|
||||
<n-drawer v-model:show="showDrawer" :height="'80%'" placement="bottom">
|
||||
<n-drawer
|
||||
v-model:show="showDrawer"
|
||||
:height="'80%'"
|
||||
placement="bottom"
|
||||
@after-leave="handleDrawerClose"
|
||||
>
|
||||
<n-drawer-content title="下载管理" closable :native-scrollbar="false">
|
||||
<div class="drawer-container">
|
||||
<n-tabs type="line" animated class="h-full">
|
||||
@@ -85,7 +90,7 @@
|
||||
</div>
|
||||
<div v-else class="downloaded-content">
|
||||
<div class="downloaded-items">
|
||||
<div v-for="item in downloadedList" :key="item.path" class="downloaded-item">
|
||||
<div v-for="item in downList" :key="item.path" class="downloaded-item">
|
||||
<div class="downloaded-item-content">
|
||||
<div class="downloaded-item-cover">
|
||||
<n-image
|
||||
@@ -105,11 +110,11 @@
|
||||
<div class="downloaded-item-size">{{ formatSize(item.size) }}</div>
|
||||
</div>
|
||||
<div class="downloaded-item-actions">
|
||||
<n-button text type="primary" size="large" @click="handlePlayMusic(item)">
|
||||
<!-- <n-button text type="primary" size="large" @click="handlePlayMusic(item)">
|
||||
<template #icon>
|
||||
<i class="iconfont ri-play-circle-line text-xl"></i>
|
||||
</template>
|
||||
</n-button>
|
||||
</n-button> -->
|
||||
<n-button
|
||||
text
|
||||
type="primary"
|
||||
@@ -162,7 +167,7 @@ import { computed, onMounted, ref } from 'vue';
|
||||
import { useStore } from 'vuex';
|
||||
|
||||
import { getMusicDetail } from '@/api/music';
|
||||
import { audioService } from '@/services/audioService';
|
||||
// import { audioService } from '@/services/audioService';
|
||||
import { getImgUrl } from '@/utils';
|
||||
|
||||
interface DownloadItem {
|
||||
@@ -185,15 +190,26 @@ interface DownloadedItem {
|
||||
ar: { name: string }[];
|
||||
}
|
||||
|
||||
const store = useStore();
|
||||
const message = useMessage();
|
||||
const showDrawer = ref(false);
|
||||
const store = useStore();
|
||||
|
||||
const showDrawer = computed({
|
||||
get: () => store.state.showDownloadDrawer,
|
||||
set: (val) => store.commit('setShowDownloadDrawer', val)
|
||||
});
|
||||
|
||||
const downloadList = ref<DownloadItem[]>([]);
|
||||
const downloadedList = ref<DownloadedItem[]>([]);
|
||||
const downloadedList = ref<DownloadedItem[]>(
|
||||
JSON.parse(localStorage.getItem('downloadedList') || '[]')
|
||||
);
|
||||
|
||||
const downList = computed(() => {
|
||||
return (downloadedList.value as DownloadedItem[]).reverse();
|
||||
});
|
||||
|
||||
// 获取播放状态
|
||||
const play = computed(() => store.state.play as boolean);
|
||||
const currentMusic = computed(() => store.state.playMusic);
|
||||
// const play = computed(() => store.state.play as boolean);
|
||||
// const currentMusic = computed(() => store.state.playMusic);
|
||||
|
||||
// 计算下载中的任务数量
|
||||
const downloadingCount = computed(() => {
|
||||
@@ -264,8 +280,7 @@ const formatSize = (bytes: number) => {
|
||||
|
||||
// 打开目录
|
||||
const openDirectory = (path: string) => {
|
||||
const directory = path.substring(0, path.lastIndexOf('/'));
|
||||
window.electron.ipcRenderer.send('open-directory', directory);
|
||||
window.electron.ipcRenderer.send('open-directory', path);
|
||||
};
|
||||
|
||||
// 删除相关
|
||||
@@ -288,6 +303,14 @@ const confirmDelete = async () => {
|
||||
itemToDelete.value.path
|
||||
);
|
||||
if (success) {
|
||||
localStorage.setItem(
|
||||
'downloadedList',
|
||||
JSON.stringify(
|
||||
downloadedList.value.filter(
|
||||
(item) => item.id !== (itemToDelete.value as DownloadedItem).id
|
||||
)
|
||||
)
|
||||
);
|
||||
await refreshDownloadedList();
|
||||
message.success('删除成功');
|
||||
} else {
|
||||
@@ -303,58 +326,59 @@ const confirmDelete = async () => {
|
||||
};
|
||||
|
||||
// 播放音乐
|
||||
const handlePlayMusic = async (item: DownloadedItem) => {
|
||||
// 确保路径正确编码
|
||||
const encodedPath = encodeURIComponent(item.path);
|
||||
const localUrl = `local://${encodedPath}`;
|
||||
// const handlePlayMusic = async (item: DownloadedItem) => {
|
||||
// // 确保路径正确编码
|
||||
// const encodedPath = encodeURIComponent(item.path);
|
||||
// const localUrl = `local://${encodedPath}`;
|
||||
|
||||
const musicInfo = {
|
||||
name: item.filename,
|
||||
id: item.id,
|
||||
url: localUrl,
|
||||
playMusicUrl: localUrl,
|
||||
picUrl: item.picUrl,
|
||||
ar: item.ar || [{ name: '本地音乐' }],
|
||||
song: {
|
||||
artists: item.ar || [{ name: '本地音乐' }]
|
||||
},
|
||||
al: {
|
||||
picUrl: item.picUrl || '/images/default_cover.png'
|
||||
}
|
||||
};
|
||||
// const musicInfo = {
|
||||
// name: item.filename,
|
||||
// id: item.id,
|
||||
// url: localUrl,
|
||||
// playMusicUrl: localUrl,
|
||||
// picUrl: item.picUrl,
|
||||
// ar: item.ar || [{ name: '本地音乐' }],
|
||||
// song: {
|
||||
// artists: item.ar || [{ name: '本地音乐' }]
|
||||
// },
|
||||
// al: {
|
||||
// picUrl: item.picUrl || '/images/default_cover.png'
|
||||
// }
|
||||
// };
|
||||
|
||||
// 如果是当前播放的音乐,则切换播放状态
|
||||
if (currentMusic.value?.id === item.id) {
|
||||
if (play.value) {
|
||||
audioService.getCurrentSound()?.pause();
|
||||
store.commit('setPlayMusic', false);
|
||||
} else {
|
||||
audioService.getCurrentSound()?.play();
|
||||
store.commit('setPlayMusic', true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// // 如果是当前播放的音乐,则切换播放状态
|
||||
// if (currentMusic.value?.id === item.id) {
|
||||
// if (play.value) {
|
||||
// audioService.getCurrentSound()?.pause();
|
||||
// store.commit('setPlayMusic', false);
|
||||
// } else {
|
||||
// audioService.getCurrentSound()?.play();
|
||||
// store.commit('setPlayMusic', true);
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 播放新的音乐
|
||||
store.commit('setPlay', musicInfo);
|
||||
store.commit('setPlayMusic', true);
|
||||
store.commit('setIsPlay', true);
|
||||
// // 播放新的音乐
|
||||
// store.commit('setPlay', musicInfo);
|
||||
// store.commit('setPlayMusic', true);
|
||||
// store.commit('setIsPlay', true);
|
||||
|
||||
store.commit(
|
||||
'setPlayList',
|
||||
downloadedList.value.map((item) => ({
|
||||
...item,
|
||||
playMusicUrl: `local://${encodeURIComponent(item.path)}`
|
||||
}))
|
||||
);
|
||||
};
|
||||
// store.commit(
|
||||
// 'setPlayList',
|
||||
// downloadedList.value.map((item) => ({
|
||||
// ...item,
|
||||
// playMusicUrl: `local://${encodeURIComponent(item.path)}`
|
||||
// }))
|
||||
// );
|
||||
// };
|
||||
|
||||
// 获取已下载音乐列表
|
||||
const refreshDownloadedList = async () => {
|
||||
try {
|
||||
let saveList: any = [];
|
||||
const list = await window.electron.ipcRenderer.invoke('get-downloaded-music');
|
||||
if (!Array.isArray(list) || list.length === 0) {
|
||||
downloadedList.value = [];
|
||||
saveList = [];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -369,7 +393,7 @@ const refreshDownloadedList = async () => {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
downloadedList.value = list.map((item) => {
|
||||
saveList = list.map((item) => {
|
||||
const songDetail = songDetails[item.id];
|
||||
return {
|
||||
...item,
|
||||
@@ -379,17 +403,29 @@ const refreshDownloadedList = async () => {
|
||||
});
|
||||
} catch (detailError) {
|
||||
console.error('Failed to get music details:', detailError);
|
||||
downloadedList.value = list;
|
||||
saveList = list;
|
||||
}
|
||||
} else {
|
||||
downloadedList.value = list;
|
||||
saveList = list;
|
||||
}
|
||||
setLocalDownloadedList(saveList);
|
||||
} catch (error) {
|
||||
console.error('Failed to get downloaded music list:', error);
|
||||
downloadedList.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const setLocalDownloadedList = (list: DownloadedItem[]) => {
|
||||
const localList = localStorage.getItem('downloadedList');
|
||||
// 合并 去重
|
||||
const saveList = [...(localList ? JSON.parse(localList) : []), ...list];
|
||||
const uniqueList = saveList.filter(
|
||||
(item, index, self) => index === self.findIndex((t) => t.id === item.id)
|
||||
);
|
||||
localStorage.setItem('downloadedList', JSON.stringify(uniqueList));
|
||||
downloadedList.value = uniqueList;
|
||||
};
|
||||
|
||||
// 监听抽屉显示状态
|
||||
watch(
|
||||
() => showDrawer.value,
|
||||
@@ -465,6 +501,10 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const handleDrawerClose = () => {
|
||||
store.commit('setShowDownloadDrawer', false);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -207,6 +207,11 @@ const dropdownOptions = computed<MenuOption[]>(() => {
|
||||
type: 'divider',
|
||||
key: 'd1'
|
||||
},
|
||||
{
|
||||
label: '下载歌曲',
|
||||
key: 'download',
|
||||
icon: () => h('i', { class: 'iconfont ri-download-line' })
|
||||
},
|
||||
{
|
||||
label: '添加到歌单',
|
||||
key: 'addToPlaylist',
|
||||
|
||||
@@ -72,7 +72,7 @@ import { marked } from 'marked';
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useStore } from 'vuex';
|
||||
|
||||
import { checkUpdate, UpdateResult } from '@/utils/update';
|
||||
import { checkUpdate, getProxyNodes, UpdateResult } from '@/utils/update';
|
||||
|
||||
import config from '../../../../package.json';
|
||||
|
||||
@@ -226,7 +226,13 @@ const handleUpdate = async () => {
|
||||
try {
|
||||
downloading.value = true;
|
||||
downloadStatus.value = '准备下载...';
|
||||
window.electron.ipcRenderer.send('start-download', downloadUrl);
|
||||
|
||||
// 获取代理节点列表
|
||||
const proxyHosts = await getProxyNodes();
|
||||
const proxyDownloadUrl = `${proxyHosts[0]}/${downloadUrl}`;
|
||||
|
||||
// 发送所有可能的下载地址到主进程
|
||||
window.electron.ipcRenderer.send('start-download', proxyDownloadUrl);
|
||||
} catch (error) {
|
||||
downloading.value = false;
|
||||
window.$message.error('启动下载失败,请重试或手动下载');
|
||||
|
||||
@@ -13,7 +13,7 @@ const musicHistory = useMusicHistory();
|
||||
|
||||
// 获取歌曲url
|
||||
export const getSongUrl = async (id: number, songData: any, isDownloaded: boolean = false) => {
|
||||
const { data } = await getMusicUrl(id);
|
||||
const { data } = await getMusicUrl(id, isDownloaded);
|
||||
let url = '';
|
||||
let songDetail = null;
|
||||
try {
|
||||
|
||||
@@ -27,7 +27,14 @@
|
||||
<!-- 底部音乐播放 -->
|
||||
<play-bar v-show="isPlay" :style="isMobile && store.state.musicFull ? 'bottom: 0;' : ''" />
|
||||
<!-- 下载管理抽屉 -->
|
||||
<download-drawer v-if="isElectron" />
|
||||
<download-drawer
|
||||
v-if="
|
||||
isElectron &&
|
||||
(store.state.setData?.alwaysShowDownloadButton ||
|
||||
store.state.showDownloadDrawer ||
|
||||
store.state.hasDownloadingTasks)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<install-app-modal v-if="!isElectron"></install-app-modal>
|
||||
<update-modal v-if="isElectron" />
|
||||
|
||||
@@ -105,7 +105,7 @@ import { useRouter } from 'vue-router';
|
||||
import { useStore } from 'vuex';
|
||||
|
||||
import { getSearchKeyword } from '@/api/home';
|
||||
import { getUserDetail, logout } from '@/api/login';
|
||||
import { getUserDetail } from '@/api/login';
|
||||
import alipay from '@/assets/alipay.png';
|
||||
import wechat from '@/assets/wechat.png';
|
||||
import Coffee from '@/components/Coffee.vue';
|
||||
@@ -132,8 +132,10 @@ const loadPage = async () => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) return;
|
||||
const { data } = await getUserDetail();
|
||||
store.state.user = data.profile;
|
||||
localStorage.setItem('user', JSON.stringify(data.profile));
|
||||
console.log('data', data);
|
||||
store.state.user =
|
||||
data.profile || store.state.user || JSON.parse(localStorage.getItem('user') || '{}');
|
||||
localStorage.setItem('user', JSON.stringify(store.state.user));
|
||||
};
|
||||
|
||||
loadPage();
|
||||
@@ -202,10 +204,7 @@ const selectItem = async (key: string) => {
|
||||
// switch 判断
|
||||
switch (key) {
|
||||
case 'logout':
|
||||
logout().then(() => {
|
||||
store.commit('logout');
|
||||
router.push('/login');
|
||||
});
|
||||
store.commit('logout');
|
||||
break;
|
||||
case 'login':
|
||||
router.push('/login');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
import setData from '@/../main/set.json';
|
||||
import { logout } from '@/api/login';
|
||||
import { getLikedList, likeSong } from '@/api/music';
|
||||
import { useMusicListHook } from '@/hooks/MusicListHook';
|
||||
import homeRouter from '@/router/home';
|
||||
@@ -79,7 +80,7 @@ export interface State {
|
||||
user: any;
|
||||
playList: SongResult[];
|
||||
playListIndex: number;
|
||||
setData: any;
|
||||
setData: typeof defaultSettings;
|
||||
lyric: any;
|
||||
isMobile: boolean;
|
||||
searchValue: string;
|
||||
@@ -92,6 +93,7 @@ export interface State {
|
||||
showArtistDrawer: boolean;
|
||||
currentArtistId: number | null;
|
||||
systemFonts: { label: string; value: string }[];
|
||||
showDownloadDrawer: boolean;
|
||||
}
|
||||
|
||||
const state: State = {
|
||||
@@ -115,7 +117,8 @@ const state: State = {
|
||||
showUpdateModal: false,
|
||||
showArtistDrawer: false,
|
||||
currentArtistId: null,
|
||||
systemFonts: [{ label: '系统默认', value: 'system-ui' }]
|
||||
systemFonts: [{ label: '系统默认', value: 'system-ui' }],
|
||||
showDownloadDrawer: false
|
||||
};
|
||||
|
||||
const { handlePlayMusic, nextPlay, prevPlay } = useMusicListHook();
|
||||
@@ -231,9 +234,11 @@ const mutations = {
|
||||
state.showUpdateModal = value;
|
||||
},
|
||||
logout(state: State) {
|
||||
state.user = null;
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('token');
|
||||
logout().then(() => {
|
||||
state.user = null;
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('token');
|
||||
});
|
||||
},
|
||||
setShowArtistDrawer(state, show: boolean) {
|
||||
state.showArtistDrawer = show;
|
||||
@@ -252,6 +257,9 @@ const mutations = {
|
||||
value: font
|
||||
}))
|
||||
];
|
||||
},
|
||||
setShowDownloadDrawer(state: State, show: boolean) {
|
||||
state.showDownloadDrawer = show;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -284,9 +292,9 @@ const actions = {
|
||||
const localList: number[] = localFavoriteList ? JSON.parse(localFavoriteList) : [];
|
||||
|
||||
// 如果用户已登录,尝试获取服务器收藏列表并合并
|
||||
if (state.user && localStorage.getItem('token')) {
|
||||
if (state.user && state.user.userId) {
|
||||
try {
|
||||
const res = await getLikedList();
|
||||
const res = await getLikedList(state.user.userId);
|
||||
if (res.data?.ids) {
|
||||
// 合并本地和服务器的收藏列表,去重
|
||||
const serverList = res.data.ids.reverse();
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import axios, { InternalAxiosRequestConfig } from 'axios';
|
||||
import { createDiscreteApi } from 'naive-ui';
|
||||
|
||||
import store from '@/store';
|
||||
|
||||
import { isElectron } from '.';
|
||||
|
||||
const { notification } = createDiscreteApi(['notification']);
|
||||
|
||||
let setData: any = null;
|
||||
const getSetData = () => {
|
||||
if (window.electron) {
|
||||
@@ -50,7 +47,7 @@ request.interceptors.request.use(
|
||||
};
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.params.cookie = `${token} os=pc;`;
|
||||
config.params.cookie = config.params.cookie !== undefined ? config.params.cookie : token;
|
||||
}
|
||||
if (isElectron) {
|
||||
const proxyConfig = setData?.proxyConfig;
|
||||
@@ -70,6 +67,8 @@ request.interceptors.request.use(
|
||||
}
|
||||
);
|
||||
|
||||
const NO_RETRY_URLS = ['暂时没有'];
|
||||
|
||||
// 响应拦截器
|
||||
request.interceptors.response.use(
|
||||
(response) => {
|
||||
@@ -88,28 +87,16 @@ request.interceptors.response.use(
|
||||
if (error.response?.status === 301) {
|
||||
// 使用 store mutation 清除用户信息
|
||||
store.commit('logout');
|
||||
|
||||
// 如果还可以重试,则重新发起请求
|
||||
if (config.retryCount === undefined || config.retryCount < MAX_RETRIES) {
|
||||
config.retryCount = (config.retryCount || 1) + 1;
|
||||
console.log(`301 状态码,清除登录信息后重试第 ${config.retryCount} 次`);
|
||||
notification.error({
|
||||
content: '登录状态失效,请重新登录',
|
||||
meta: '请重新登录',
|
||||
duration: 2500,
|
||||
keepAliveOnHover: true
|
||||
});
|
||||
|
||||
// 延迟重试
|
||||
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
||||
|
||||
// 重新发起请求
|
||||
return request(config);
|
||||
}
|
||||
console.log(`301 状态码,清除登录信息后重试第 ${config.retryCount} 次`);
|
||||
config.retryCount = 3;
|
||||
}
|
||||
|
||||
// 检查是否还可以重试
|
||||
if (config.retryCount !== undefined && config.retryCount < MAX_RETRIES) {
|
||||
if (
|
||||
config.retryCount !== undefined &&
|
||||
config.retryCount < MAX_RETRIES &&
|
||||
!NO_RETRY_URLS.includes(config.url as string)
|
||||
) {
|
||||
config.retryCount++;
|
||||
console.log(`请求重试第 ${config.retryCount} 次`);
|
||||
|
||||
|
||||
@@ -15,6 +15,23 @@ interface GithubReleaseInfo {
|
||||
}>;
|
||||
}
|
||||
|
||||
interface ProxyNode {
|
||||
url: string;
|
||||
server: string;
|
||||
ip: string;
|
||||
location: string;
|
||||
latency: number;
|
||||
speed: number;
|
||||
}
|
||||
|
||||
interface ProxyResponse {
|
||||
code: number;
|
||||
msg: string;
|
||||
data: ProxyNode[];
|
||||
total: number;
|
||||
update_time: string;
|
||||
}
|
||||
|
||||
export interface UpdateResult {
|
||||
hasUpdate: boolean;
|
||||
latestVersion: string;
|
||||
@@ -30,6 +47,81 @@ export interface UpdateResult {
|
||||
} | null;
|
||||
}
|
||||
|
||||
// 缓存相关配置
|
||||
const CACHE_KEY = 'github_proxy_nodes';
|
||||
const CACHE_EXPIRE_TIME = 1000 * 60 * 10; // 10分钟过期
|
||||
|
||||
// 请求配置
|
||||
const REQUEST_TIMEOUT = 2000; // 2秒超时
|
||||
|
||||
/**
|
||||
* 从缓存获取代理节点
|
||||
*/
|
||||
const getCachedProxyNodes = (): { nodes: string[]; timestamp: number } | null => {
|
||||
const cached = localStorage.getItem(CACHE_KEY);
|
||||
if (cached) {
|
||||
const { nodes, timestamp } = JSON.parse(cached);
|
||||
if (Date.now() - timestamp < CACHE_EXPIRE_TIME) {
|
||||
return { nodes, timestamp };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 缓存代理节点
|
||||
*/
|
||||
const cacheProxyNodes = (nodes: string[]) => {
|
||||
localStorage.setItem(
|
||||
CACHE_KEY,
|
||||
JSON.stringify({
|
||||
nodes,
|
||||
timestamp: Date.now()
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取代理节点列表
|
||||
*/
|
||||
export const getProxyNodes = async (): Promise<string[]> => {
|
||||
// 尝试从缓存获取
|
||||
const cached = getCachedProxyNodes();
|
||||
if (cached) {
|
||||
return cached.nodes;
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取最新代理节点
|
||||
const { data } = await axios.get<ProxyResponse>('https://api.akams.cn/github', {
|
||||
timeout: REQUEST_TIMEOUT
|
||||
});
|
||||
if (data.code === 200) {
|
||||
// 按速度排序并获取前10个节点
|
||||
const nodes = data.data
|
||||
.sort((a, b) => b.speed - a.speed)
|
||||
.slice(0, 10)
|
||||
.map((node) => node.url);
|
||||
|
||||
// 缓存节点
|
||||
cacheProxyNodes(nodes);
|
||||
return nodes;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取代理节点失败:', error);
|
||||
}
|
||||
|
||||
// 使用备用节点
|
||||
return [
|
||||
'https://gh.lk.cc',
|
||||
'https://ghproxy.cn',
|
||||
'https://ghproxy.net',
|
||||
'https://gitproxy.click',
|
||||
'https://github.tbedu.top',
|
||||
'https://github.moeyy.xyz'
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取 GitHub 最新发布版本信息
|
||||
*/
|
||||
@@ -38,33 +130,42 @@ export const getLatestReleaseInfo = async (): Promise<GithubReleaseInfo | null>
|
||||
const token = import.meta.env.VITE_GITHUB_TOKEN;
|
||||
const headers = {};
|
||||
|
||||
// 获取代理节点列表
|
||||
const proxyHosts = await getProxyNodes();
|
||||
|
||||
// 构建 API URL 列表
|
||||
const apiUrls = [
|
||||
// 原始地址
|
||||
'https://api.github.com/repos/algerkong/AlgerMusicPlayer/releases/latest',
|
||||
|
||||
// 使用 ghproxy.com 代理
|
||||
'https://www.ghproxy.cn/https://raw.githubusercontent.com/algerkong/AlgerMusicPlayer/dev_electron/package.json'
|
||||
|
||||
// 使用 gitee 镜像(如果有的话)
|
||||
// 'https://gitee.com/api/v5/repos/[用户名]/AlgerMusicPlayer/releases/latest'
|
||||
// 使用代理节点
|
||||
...proxyHosts.map(
|
||||
(host) =>
|
||||
`${host}/https://raw.githubusercontent.com/algerkong/AlgerMusicPlayer/dev_electron/package.json`
|
||||
)
|
||||
];
|
||||
|
||||
if (token) {
|
||||
headers['Authorization'] = `token ${token}`;
|
||||
}
|
||||
|
||||
for (const url of apiUrls) {
|
||||
try {
|
||||
const response = await axios.get(url, { headers });
|
||||
const response = await axios.get(url, {
|
||||
headers,
|
||||
timeout: REQUEST_TIMEOUT
|
||||
});
|
||||
|
||||
if (url.includes('package.json')) {
|
||||
// 如果是 package.json,直接读取版本号
|
||||
// 如果是 package.json,获取对应的 CHANGELOG
|
||||
const changelogUrl = url.replace('package.json', 'CHANGELOG.md');
|
||||
const changelogResponse = await axios.get(changelogUrl, {
|
||||
timeout: REQUEST_TIMEOUT
|
||||
});
|
||||
|
||||
return {
|
||||
tag_name: response.data.version,
|
||||
body: (
|
||||
await axios.get(
|
||||
'https://www.ghproxy.cn/https://raw.githubusercontent.com/algerkong/AlgerMusicPlayer/dev_electron/CHANGELOG.md'
|
||||
)
|
||||
).data,
|
||||
body: changelogResponse.data,
|
||||
html_url: 'https://github.com/algerkong/AlgerMusicPlayer/releases/latest',
|
||||
assets: []
|
||||
} as unknown as GithubReleaseInfo;
|
||||
|
||||
@@ -272,9 +272,9 @@ const handleScroll = (e: any) => {
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
store.dispatch('initializeFavoriteList');
|
||||
getFavoriteSongs();
|
||||
onMounted(async () => {
|
||||
await store.dispatch('initializeFavoriteList');
|
||||
await getFavoriteSongs();
|
||||
});
|
||||
|
||||
// 监听收藏列表变化
|
||||
|
||||
@@ -58,7 +58,7 @@ const timerIsQr = (key: string) => {
|
||||
localStorage.setItem('token', data.cookie);
|
||||
const user = await getUserDetail();
|
||||
store.state.user = user.data.profile;
|
||||
localStorage.setItem('user', JSON.stringify(store.state.user));
|
||||
localStorage.setItem('user', JSON.stringify(user.data.profile));
|
||||
message.success('登录成功');
|
||||
|
||||
clearInterval(timer);
|
||||
|
||||
@@ -180,6 +180,24 @@
|
||||
<n-button size="small" @click="showShortcutModal = true">配置</n-button>
|
||||
</div>
|
||||
|
||||
<div v-if="isElectron" class="set-item">
|
||||
<div>
|
||||
<div class="set-item-title">下载管理</div>
|
||||
<div class="set-item-content">
|
||||
<n-switch v-model:value="setData.alwaysShowDownloadButton" class="mr-2">
|
||||
<template #checked>显示</template>
|
||||
<template #unchecked>隐藏</template>
|
||||
</n-switch>
|
||||
是否始终显示下载列表按钮
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<n-button size="small" @click="store.commit('setShowDownloadDrawer', true)">
|
||||
打开下载管理
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="set-item">
|
||||
<div>
|
||||
<div class="set-item-title">下载目录</div>
|
||||
@@ -728,8 +746,6 @@ const clearCache = async () => {
|
||||
localStorage.removeItem('favoriteList');
|
||||
break;
|
||||
case 'user':
|
||||
localStorage.removeItem('user');
|
||||
localStorage.removeItem('token');
|
||||
store.commit('logout');
|
||||
break;
|
||||
case 'settings':
|
||||
|
||||
@@ -152,6 +152,10 @@ const loadPage = async () => {
|
||||
// 检查登录状态
|
||||
if (!checkLoginStatus()) return;
|
||||
|
||||
await loadData();
|
||||
};
|
||||
|
||||
const loadData = async () => {
|
||||
try {
|
||||
infoLoading.value = true;
|
||||
|
||||
@@ -188,10 +192,10 @@ const loadPage = async () => {
|
||||
watch(
|
||||
() => router.currentRoute.value.path,
|
||||
(newPath) => {
|
||||
console.log('newPath', newPath);
|
||||
if (newPath === '/user') {
|
||||
checkLoginStatus();
|
||||
} else {
|
||||
loadPage();
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user