Skip to content

Commit 8f0728d

Browse files
committed
feat: 登录状态校验功能修改
1 parent 8f9c989 commit 8f0728d

File tree

5 files changed

+61
-11
lines changed

5 files changed

+61
-11
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
]
3232
},
3333
"dependencies": {
34-
"@electron-toolkit/preload": "^3.0.1",
34+
"@electron-toolkit/preload": "^3.0.2",
3535
"@electron-toolkit/utils": "^4.0.0",
3636
"@unblockneteasemusic/server": "^0.27.8-patch.1",
3737
"cors": "^2.8.5",
@@ -56,7 +56,7 @@
5656
"@electron-toolkit/tsconfig": "^1.0.1",
5757
"@eslint/js": "^9.31.0",
5858
"@rushstack/eslint-patch": "^1.10.3",
59-
"@tailwindcss/postcss7-compat": "^2.2.4",
59+
6060
"@types/howler": "^2.2.12",
6161
"@types/node": "^20.14.8",
6262
"@types/tinycolor2": "^1.4.6",
@@ -68,15 +68,15 @@
6868
"@vue/eslint-config-typescript": "^14.5.0",
6969
"@vue/runtime-core": "^3.5.0",
7070
"@vueuse/core": "^11.3.0",
71-
"@vueuse/electron": "^11.3.0",
71+
"@vueuse/electron": "^13.8.0",
7272
"animate.css": "^4.1.1",
7373
"autoprefixer": "^10.4.20",
7474
"axios": "^1.7.7",
7575
"cross-env": "^7.0.3",
76-
"electron": "^35.2.0",
77-
"electron-builder": "^25.1.8",
78-
"electron-vite": "^3.1.0",
79-
"eslint": "^9.0.0",
76+
"electron": "^37.4.0",
77+
"electron-builder": "^26.0.12",
78+
"electron-vite": "^4.0.0",
79+
"eslint": "^9.34.0",
8080
"eslint-config-prettier": "^10.1.8",
8181
"eslint-plugin-import": "^2.32.0",
8282
"eslint-plugin-prettier": "^5.5.3",
@@ -91,7 +91,7 @@
9191
"naive-ui": "^2.41.0",
9292
"pinia": "^3.0.1",
9393
"pinyin-match": "^1.2.6",
94-
"postcss": "^8.5.3",
94+
"postcss": "^8.4.47",
9595
"prettier": "^3.6.2",
9696
"remixicon": "^4.6.0",
9797
"sass": "^1.86.0",

src/renderer/components/common/PlaylistDrawer.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import { createPlaylist, updatePlaylistTracks } from '@/api/music';
117117
import { getUserPlaylist } from '@/api/user';
118118
import { useUserStore } from '@/store';
119119
import { getImgUrl } from '@/utils';
120+
import { hasPermission, getLoginErrorMessage } from '@/utils/auth';
120121
121122
const store = useUserStore();
122123
const { t } = useI18n();
@@ -160,6 +161,13 @@ const fetchUserPlaylists = async () => {
160161
return;
161162
}
162163
164+
// 检查是否有真实登录权限
165+
if (!hasPermission(true)) {
166+
message.error(getLoginErrorMessage(true));
167+
emit('update:modelValue', false);
168+
return;
169+
}
170+
163171
const res = await getUserPlaylist(user.userId, 999);
164172
if (res.data?.playlist) {
165173
playlists.value = res.data.playlist.filter((item: any) => item.userId === user.userId);
@@ -173,6 +181,13 @@ const fetchUserPlaylists = async () => {
173181
// 添加到歌单
174182
const handleAddToPlaylist = async (playlist: any) => {
175183
if (!props.songId) return;
184+
185+
// 检查是否有真实登录权限
186+
if (!hasPermission(true)) {
187+
message.error(getLoginErrorMessage(true));
188+
return;
189+
}
190+
176191
try {
177192
const res = await updatePlaylistTracks({
178193
op: 'add',
@@ -200,6 +215,12 @@ const handleCreatePlaylist = async () => {
200215
return;
201216
}
202217
218+
// 检查是否有真实登录权限
219+
if (!hasPermission(true)) {
220+
message.error(getLoginErrorMessage(true));
221+
return;
222+
}
223+
203224
try {
204225
creating.value = true;
205226

src/renderer/components/common/songItemCom/SongItemDropdown.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useI18n } from 'vue-i18n';
2121
2222
import type { SongResult } from '@/types/music';
2323
import { getImgUrl, isElectron } from '@/utils';
24+
import { hasPermission } from '@/utils/auth';
2425
2526
const { t } = useI18n();
2627
@@ -121,6 +122,8 @@ const renderSongPreview = () => {
121122
122123
// 下拉菜单选项
123124
const dropdownOptions = computed<MenuOption[]>(() => {
125+
const hasRealAuth = hasPermission(true);
126+
124127
const options: MenuOption[] = [
125128
{
126129
key: 'header',
@@ -153,7 +156,8 @@ const dropdownOptions = computed<MenuOption[]>(() => {
153156
{
154157
label: t('songItem.menu.addToPlaylist'),
155158
key: 'addToPlaylist',
156-
icon: () => h('i', { class: 'iconfont ri-folder-add-line' })
159+
icon: () => h('i', { class: 'iconfont ri-folder-add-line' }),
160+
disabled: !hasRealAuth
157161
},
158162
{
159163
label: props.isFavorite ? t('songItem.menu.unfavorite') : t('songItem.menu.favorite'),
@@ -162,6 +166,7 @@ const dropdownOptions = computed<MenuOption[]>(() => {
162166
h('i', {
163167
class: `iconfont ${props.isFavorite ? 'ri-heart-fill text-red-500' : 'ri-heart-line'}`
164168
})
169+
// 收藏功能不禁用,UID登录时可以本地收藏/取消收藏
165170
},
166171
{
167172
label: props.isDislike ? t('songItem.menu.undislike') : t('songItem.menu.dislike'),

src/renderer/store/modules/player.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { audioService } from '@/services/audioService';
1212
import type { ILyric, ILyricText, SongResult } from '@/types/music';
1313
import { type Platform } from '@/types/music';
1414
import { getImgUrl } from '@/utils';
15+
import { hasPermission } from '@/utils/auth';
1516
import { getImageLinearBackground } from '@/utils/linearColor';
1617

1718
import { useSettingsStore } from './settings';
@@ -1282,9 +1283,17 @@ export const usePlayerStore = defineStore('player', () => {
12821283
);
12831284

12841285
if (!isAlreadyInList) {
1286+
// 先添加到本地收藏列表
12851287
favoriteList.value.push(id);
12861288
localStorage.setItem('favoriteList', JSON.stringify(favoriteList.value));
1287-
typeof id === 'number' && useUserStore().user && likeSong(id, true);
1289+
// 只有在有真实登录权限时才调用API
1290+
if (typeof id === 'number' && useUserStore().user && hasPermission(true)) {
1291+
try {
1292+
await likeSong(id, true);
1293+
} catch (error) {
1294+
console.error('收藏歌曲API调用失败:', error);
1295+
}
1296+
}
12881297
}
12891298
};
12901299

@@ -1295,8 +1304,16 @@ export const usePlayerStore = defineStore('player', () => {
12951304
(existingId) => !isBilibiliIdMatch(existingId, id)
12961305
);
12971306
} else {
1307+
// 先从本地收藏列表中移除
12981308
favoriteList.value = favoriteList.value.filter((existingId) => existingId !== id);
1299-
useUserStore().user && likeSong(Number(id), false);
1309+
// 只有在有真实登录权限时才调用API
1310+
if (typeof id === 'number' && useUserStore().user && hasPermission(true)) {
1311+
try {
1312+
await likeSong(id, false);
1313+
} catch (error) {
1314+
console.error('取消收藏歌曲API调用失败:', error);
1315+
}
1316+
}
13001317
}
13011318
localStorage.setItem('favoriteList', JSON.stringify(favoriteList.value));
13021319
};

src/renderer/views/music/MusicListPage.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ import { useDownload } from '@/hooks/useDownload';
234234
import { useMusicStore, usePlayerStore, useRecommendStore } from '@/store';
235235
import { SongResult } from '@/types/music';
236236
import { getImgUrl, isElectron, isMobile, setAnimationClass } from '@/utils';
237+
import { getLoginErrorMessage, hasPermission } from '@/utils/auth';
237238
238239
const { t } = useI18n();
239240
const route = useRoute();
@@ -816,6 +817,12 @@ const checkCollectionStatus = () => {
816817
const toggleCollect = async () => {
817818
if (!listInfo.value?.id) return;
818819
820+
// 检查是否有真实登录权限
821+
if (!hasPermission(true)) {
822+
message.error(getLoginErrorMessage(true));
823+
return;
824+
}
825+
819826
try {
820827
loadingList.value = true;
821828
const tVal = isCollected.value ? 2 : 1; // 1:收藏, 2:取消收藏

0 commit comments

Comments
 (0)