feat: 登录状态校验功能修改

This commit is contained in:
alger
2025-09-14 00:34:35 +08:00
parent 8f9c989815
commit 8f0728d9db
5 changed files with 61 additions and 11 deletions
@@ -117,6 +117,7 @@ import { createPlaylist, updatePlaylistTracks } from '@/api/music';
import { getUserPlaylist } from '@/api/user';
import { useUserStore } from '@/store';
import { getImgUrl } from '@/utils';
import { hasPermission, getLoginErrorMessage } from '@/utils/auth';
const store = useUserStore();
const { t } = useI18n();
@@ -160,6 +161,13 @@ const fetchUserPlaylists = async () => {
return;
}
// 检查是否有真实登录权限
if (!hasPermission(true)) {
message.error(getLoginErrorMessage(true));
emit('update:modelValue', false);
return;
}
const res = await getUserPlaylist(user.userId, 999);
if (res.data?.playlist) {
playlists.value = res.data.playlist.filter((item: any) => item.userId === user.userId);
@@ -173,6 +181,13 @@ const fetchUserPlaylists = async () => {
// 添加到歌单
const handleAddToPlaylist = async (playlist: any) => {
if (!props.songId) return;
// 检查是否有真实登录权限
if (!hasPermission(true)) {
message.error(getLoginErrorMessage(true));
return;
}
try {
const res = await updatePlaylistTracks({
op: 'add',
@@ -200,6 +215,12 @@ const handleCreatePlaylist = async () => {
return;
}
// 检查是否有真实登录权限
if (!hasPermission(true)) {
message.error(getLoginErrorMessage(true));
return;
}
try {
creating.value = true;
@@ -21,6 +21,7 @@ import { useI18n } from 'vue-i18n';
import type { SongResult } from '@/types/music';
import { getImgUrl, isElectron } from '@/utils';
import { hasPermission } from '@/utils/auth';
const { t } = useI18n();
@@ -121,6 +122,8 @@ const renderSongPreview = () => {
// 下拉菜单选项
const dropdownOptions = computed<MenuOption[]>(() => {
const hasRealAuth = hasPermission(true);
const options: MenuOption[] = [
{
key: 'header',
@@ -153,7 +156,8 @@ const dropdownOptions = computed<MenuOption[]>(() => {
{
label: t('songItem.menu.addToPlaylist'),
key: 'addToPlaylist',
icon: () => h('i', { class: 'iconfont ri-folder-add-line' })
icon: () => h('i', { class: 'iconfont ri-folder-add-line' }),
disabled: !hasRealAuth
},
{
label: props.isFavorite ? t('songItem.menu.unfavorite') : t('songItem.menu.favorite'),
@@ -162,6 +166,7 @@ const dropdownOptions = computed<MenuOption[]>(() => {
h('i', {
class: `iconfont ${props.isFavorite ? 'ri-heart-fill text-red-500' : 'ri-heart-line'}`
})
// 收藏功能不禁用,UID登录时可以本地收藏/取消收藏
},
{
label: props.isDislike ? t('songItem.menu.undislike') : t('songItem.menu.dislike'),